Initial commit
This commit is contained in:
49
spec/services/vendors/broad_sign/broad_sign_fetch_schedule_spec.rb
vendored
Normal file
49
spec/services/vendors/broad_sign/broad_sign_fetch_schedule_spec.rb
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'webmock/rspec'
|
||||
|
||||
RSpec.describe Vendors::BroadSign::BroadSignFetchSchedule do
|
||||
let(:player) { 'dpc-100ca2-154410202' }
|
||||
let(:tokens) { double(auth_token: SecureRandom.uuid) }
|
||||
let(:action) { described_class.new(tokens) }
|
||||
let(:auth_token) { SecureRandom.hex(10) }
|
||||
|
||||
context 'when successful' do
|
||||
let(:vendor_schedule) { JSON.parse(File.read('spec/services/vendors/broad_sign/broad_sign_player_schedule.json')).with_indifferent_access }
|
||||
|
||||
before do
|
||||
WebMock.stub_request(:post, URI.join("https://#{described_class::AIR_DOMAIN}", described_class::PATH))
|
||||
.to_return(
|
||||
status: 200,
|
||||
body: vendor_schedule.to_json
|
||||
)
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
it 'makes the http call' do
|
||||
schedule_data = action.call({ player: player })
|
||||
expect(schedule_data[:items]).not_to be_nil
|
||||
end
|
||||
|
||||
it 'requests an access token' do
|
||||
action.call({ player: player })
|
||||
expect(tokens).to have_received(:auth_token).once
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unsuccessful' do
|
||||
before do
|
||||
WebMock.stub_request(:post, URI.join("https://#{described_class::AIR_DOMAIN}", described_class::PATH))
|
||||
.to_return(
|
||||
status: 429,
|
||||
body: "Too Many Requests"
|
||||
)
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
expect { action.call({ player: player }) }.to raise_error(Vendors::Errors::ScheduleFetchError)
|
||||
end
|
||||
end
|
||||
end
|
||||
96
spec/services/vendors/broad_sign/broad_sign_player_schedule.json
vendored
Normal file
96
spec/services/vendors/broad_sign/broad_sign_player_schedule.json
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"startTime": "2019-06-14T14:17:26.456Z",
|
||||
"duration": "5s",
|
||||
"token": "CgphbGV4YW5kcmVjEgNVVEMaDAj22I7oBRCAhLjZASICCAUoAToDCNMBQgMIlRtKAwiSG2IDVVUwcgMI4BE=",
|
||||
"contentIndex": 0,
|
||||
"campaign_index": 0,
|
||||
"frame_index": 0,
|
||||
"geometry_index": 0
|
||||
},
|
||||
{
|
||||
"duration": "5s",
|
||||
"token": "CgphbGV4YW5kcmVjEgNVVEMaDAj72I7oBRCAhLjZASICCAUoAToDCNQBQgMInhtKAwiSG2IDVVUwcgMI4BE=",
|
||||
"contentIndex": 1,
|
||||
"campaign_index": 1,
|
||||
"frame_index": 0,
|
||||
"geometry_index": 0
|
||||
},
|
||||
{
|
||||
"duration": "5s",
|
||||
"token": "CgphbGV4YW5kcmVjEgNVVEMaDAio2Y7oBRCAhLjZASICCAUoAToDCNMBQgMIlRtKAwiSG2IDVVUwcgMI4BE=",
|
||||
"contentIndex": 2,
|
||||
"campaign_index": 2,
|
||||
"frame_index": 0,
|
||||
"geometry_index": 0
|
||||
}
|
||||
],
|
||||
"contents": [
|
||||
{
|
||||
"name": "Content-0",
|
||||
"mimeType": "jpg",
|
||||
"uri": "https://my-storage-url.com/11045825-19889464/8e649eb2-4e0a-4727-8d8c-9e6b1fb31f50.jpg",
|
||||
"size": "187435",
|
||||
"hash": {
|
||||
"type": "CRC32",
|
||||
"payload": "ODc1ZTlmYg=="
|
||||
},
|
||||
"adCopyId": "211"
|
||||
},
|
||||
{
|
||||
"name": "Content-1",
|
||||
"mimeType": "jpg",
|
||||
"uri": "https://my-storage-url.com/11045825-19889464/8e649eb2-4e0a-4727-8d8c-9e6b1fb31f50.jpg",
|
||||
"size": "97227",
|
||||
"hash": {
|
||||
"type": "CRC32",
|
||||
"payload": "ODI0MmZjMjg="
|
||||
},
|
||||
"adCopyId": "212"
|
||||
},
|
||||
{
|
||||
"name": "Content-2",
|
||||
"mimeType": "mp4",
|
||||
"uri": "https://my-storage-url.com/11045825-19889464/8e649eb2-4e0a-4727-8d8c-9e6b1fb31f50.mp4",
|
||||
"size": "97434227",
|
||||
"hash": {
|
||||
"type": "CRC32",
|
||||
"payload": "ODI0MmZjMjg="
|
||||
},
|
||||
"adCopyId": "2122"
|
||||
}
|
||||
],
|
||||
"identification": {
|
||||
"playerId": "2272",
|
||||
"displayUnitId": "3472",
|
||||
"displayUnitLatlong": {
|
||||
"latitude": 45.5164,
|
||||
"longitude": -73.5548
|
||||
},
|
||||
"displayUnitAddress": "1100 Robert-Bourassa Montreal"
|
||||
},
|
||||
"campaigns": [
|
||||
{
|
||||
"campaignId": "19889482"
|
||||
},
|
||||
{
|
||||
"campaignId": "14889444"
|
||||
},
|
||||
{
|
||||
"campaignId": "99932"
|
||||
}
|
||||
],
|
||||
"frames": [
|
||||
{
|
||||
"frameId": "19889456"
|
||||
}
|
||||
],
|
||||
"geometries": [
|
||||
{
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"fullscreen": true
|
||||
}
|
||||
]
|
||||
}
|
||||
31
spec/services/vendors/broad_sign/broad_sign_transform_schedule_spec.rb
vendored
Normal file
31
spec/services/vendors/broad_sign/broad_sign_transform_schedule_spec.rb
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vendors::BroadSign::BroadSignTransformSchedule do
|
||||
let(:action) { described_class.new }
|
||||
let(:vendor) { 'fake-vendor' }
|
||||
let(:player) { 'dpc-100ca2-154410202' }
|
||||
let(:vendor_schedule) { JSON.parse(File.read('spec/services/vendors/broad_sign/broad_sign_player_schedule.json')).with_indifferent_access }
|
||||
let(:content_map) { vendor_schedule[:contents].collect { |item| { id: SecureRandom.uuid, name: item[:name] } } }
|
||||
let(:content_keys) { content_map.collect { |item| item[:id] } }
|
||||
|
||||
context 'when successful' do
|
||||
describe '#call' do
|
||||
it 'converts each item in the vendor schedule' do
|
||||
schedule_data = action.call(vendor, player, vendor_schedule, content_map)
|
||||
expect(schedule_data.items.count).to eq(vendor_schedule[:items].count)
|
||||
end
|
||||
|
||||
it 'maps content indices' do
|
||||
schedule_data = action.call(vendor, player, vendor_schedule, content_map)
|
||||
expect(schedule_data.items.collect(&:content_key)).to eq(content_keys)
|
||||
end
|
||||
|
||||
it 'parses item duration' do
|
||||
schedule_data = action.call(vendor, player, vendor_schedule, content_map)
|
||||
expect(schedule_data.items.collect(&:duration)).to eq(vendor_schedule[:items].collect { |i| i[:duration] })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user