Initial commit
This commit is contained in:
51
spec/services/schedule_pipeline/fetch_schedule_spec.rb
Normal file
51
spec/services/schedule_pipeline/fetch_schedule_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SchedulePipeline::FetchSchedule, type: :service do
|
||||
let(:in_queue) { double(subscribe: nil) }
|
||||
let(:out_queue) { double(push: nil) }
|
||||
let(:errors) { double(push: nil) }
|
||||
let(:service) { described_class.new(in_queue, out_queue, errors) }
|
||||
|
||||
describe '#start' do
|
||||
it 'subscribes to the in_queue' do
|
||||
service.start
|
||||
expect(in_queue).to have_received(:subscribe)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#process_msg' do
|
||||
let(:player) { 'fake-player-identifier' }
|
||||
let(:vendor) { :broad_sign }
|
||||
let(:vendor_schedule) { JSON.parse(File.read('spec/services/vendors/broad_sign/broad_sign_player_schedule.json')).with_indifferent_access }
|
||||
let(:vendor_fetch) { double(call: vendor_schedule) }
|
||||
let(:params) { { player: player } }
|
||||
let(:msg) { { params: params, vendor: vendor } }
|
||||
|
||||
before { allow(service).to receive(:for_vendor).and_return(vendor_fetch) }
|
||||
|
||||
context 'when successful' do
|
||||
before { service.process_msg(msg) }
|
||||
|
||||
it 'fetches the player schedule from the vendor' do
|
||||
expect(vendor_fetch).to have_received(:call).with(params).once
|
||||
end
|
||||
|
||||
it 'pushes schedule to out_queue' do
|
||||
expect(out_queue).to have_received(:push).with({ vendor: vendor, player: player, vendor_schedule: vendor_schedule }).once
|
||||
end
|
||||
|
||||
it('raises no errors') { expect(errors).not_to have_received(:push) }
|
||||
end
|
||||
|
||||
context 'when the vendor is unknown' do
|
||||
before do
|
||||
allow(service).to receive(:for_vendor).and_return(nil)
|
||||
service.process_msg(msg)
|
||||
end
|
||||
|
||||
it('raises an error') { expect(errors).to have_received(:push).once }
|
||||
end
|
||||
end
|
||||
end
|
||||
65
spec/services/schedule_pipeline/process_schedule_spec.rb
Normal file
65
spec/services/schedule_pipeline/process_schedule_spec.rb
Normal file
@@ -0,0 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SchedulePipeline::ProcessSchedule, type: :service do
|
||||
let(:in_queue) { double(subscribe: nil) }
|
||||
let(:out_queue) { double(push: nil) }
|
||||
let(:errors) { double(push: nil) }
|
||||
let(:service) { described_class.new(in_queue, out_queue, errors) }
|
||||
let(:player) { 'fake-player-id' }
|
||||
let(:vendor) { 'fake-vendor' }
|
||||
let(:presigned_url) { SecureRandom.uuid }
|
||||
let(:transformed_schedule) { {} }
|
||||
let(:vendor_transform) { double(call: transformed_schedule) }
|
||||
|
||||
before do
|
||||
allow(service).to receive(:create_asset).and_return({ asset: { meta: { presigned_url: presigned_url } } })
|
||||
allow(service).to receive(:ingest_content) {}
|
||||
allow(service).to receive(:for_vendor).and_return(vendor_transform)
|
||||
end
|
||||
|
||||
describe '#start' do
|
||||
it 'subscribes to the in_queue' do
|
||||
service.start
|
||||
expect(in_queue).to have_received(:subscribe)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#process_msg' do
|
||||
let(:vendor_schedule) { JSON.parse(File.read('spec/services/vendors/broad_sign/broad_sign_player_schedule.json')).with_indifferent_access }
|
||||
let(:msg) { SchedulePipeline::Models::ScheduleProcessMsg.new(vendor, player, vendor_schedule) }
|
||||
let(:content_count) { vendor_schedule[:contents].count }
|
||||
|
||||
context 'when successful' do
|
||||
before { service.process_msg(msg) }
|
||||
|
||||
it 'processes the player schedule from the vendor' do
|
||||
expect(vendor_transform).to have_received(:call).with(vendor, player, vendor_schedule, anything).once
|
||||
end
|
||||
|
||||
it 'pushes schedule to out_queue' do
|
||||
expect(out_queue).to have_received(:push).with(transformed_schedule).once
|
||||
end
|
||||
|
||||
it 'creates each content asset' do
|
||||
expect(service).to have_received(:create_asset).exactly(content_count).times
|
||||
end
|
||||
|
||||
it 'ingests each content' do
|
||||
expect(service).to have_received(:ingest_content).exactly(content_count).times
|
||||
end
|
||||
|
||||
it('raises no errors') { expect(errors).not_to have_received(:push) }
|
||||
end
|
||||
|
||||
context 'when the vendor is unknown' do
|
||||
before do
|
||||
allow(service).to receive(:for_vendor).and_return(nil)
|
||||
service.process_msg(msg)
|
||||
end
|
||||
|
||||
it('raises an error') { expect(errors).to have_received(:push).once }
|
||||
end
|
||||
end
|
||||
end
|
||||
16
spec/services/schedule_pipeline/publish_schedule_spec.rb
Normal file
16
spec/services/schedule_pipeline/publish_schedule_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SchedulePipeline::PublishSchedule, type: :service do
|
||||
let(:queue) { double(subscribe: nil) }
|
||||
let(:errors) { double(push: nil) }
|
||||
let(:service) { described_class.new(queue, errors) }
|
||||
|
||||
describe '#start' do
|
||||
it 'subscribes to the queue' do
|
||||
service.start
|
||||
expect(queue).to have_received(:subscribe)
|
||||
end
|
||||
end
|
||||
end
|
||||
37
spec/services/schedule_pipeline/schedule_pipeline_spec.rb
Normal file
37
spec/services/schedule_pipeline/schedule_pipeline_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SchedulePipeline::SchedulePipeline, type: :service do
|
||||
let(:queue_factory) { double(for_name: nil) }
|
||||
|
||||
describe '#initialize' do
|
||||
it 'uses 3 queues' do
|
||||
described_class.new(queue_factory)
|
||||
expect(queue_factory).to have_received(:for_name).with(:fetch_vendor_schedules)
|
||||
expect(queue_factory).to have_received(:for_name).with(:unprocessed_schedules)
|
||||
expect(queue_factory).to have_received(:for_name).with(:processed_schedules)
|
||||
end
|
||||
end
|
||||
|
||||
context 'after construction' do
|
||||
let(:service) { described_class.new(queue_factory) }
|
||||
let(:stages) { (1..3).collect{ double(start: nil, stop: nil) } }
|
||||
|
||||
before { allow(service).to receive(:stages).and_return(stages) }
|
||||
|
||||
describe '#start' do
|
||||
it 'starts each stage' do
|
||||
service.start
|
||||
stages.each { |stg| expect(stg).to have_received(:start).once }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stop' do
|
||||
it 'stops each stage' do
|
||||
service.stop
|
||||
stages.each { |stg| expect(stg).to have_received(:stop).once }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
23
spec/services/vendors/vistar/vistar_ad_fetch_response.json
vendored
Normal file
23
spec/services/vendors/vistar/vistar_ad_fetch_response.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"advertisement": [
|
||||
{
|
||||
"id": "-227826498",
|
||||
"proof_of_play_url": "https://sandbox-api.vistarmedia.com/api/v2/proof_of_play/json?s=27jkXH6c5WIPAaVHTauJUJ0NFfbMQlequO8MUArXW8Hhdot43e0S6fo5kK2j7r3kCVybgRnrRsxu2-zibsVFueeUMfwytTVPMYhG4u--3YEvFH6rQe2LQKiWnkQmyopVC09URKCS3Vtz8H0G3svHQMeWi8tcvnkZyVHzEIzDLuBXugusV76kbUZ-OvIhOihT0cPBH3Oj5mAKQZpQiP2sCVMVS0XocBajc20CeCE7rYXwds-Rj1WnvRPvEzz_dBpfwo-cpD8tNLUJCOzr5loY_kxOgbYQttEPwD1SWEZgCmf7qo9AaaTYDjiEHKHgU94t5AaldJqIaz3f5ax5j5oXr9YxvOGSblN25XPNoNZDFWbb0bS5oClXhBN3kWIB_U_C_lLqFYx0nZAQuiso9oSzaTiEbqTCbNCkpZ8UPxCxvsUq6_Q5usQkKNwzG6TCv1_fK9xRTWoVHznMoiHZ0y-lDF33K6QCEmAqDExpCWi7BIsT66KFznH0DbgElJBYsTpX7Dp5Na7MNaE3_Rus4fJz8Kjx4gwL0vYTl_pHmOaZZPQGOQp8GKv4qq7uvSEUw49-tY2id5snQ1xBQ0iwVsX5EET_wKJh9-EJHzcjqhBr_ZcIk70qgxK1zTMjfqDe6_aQHfY3rXiAXRPCUOM9ayUy8db1cbyuOdkOA63HQJXLIGVNwTXOlaDU-jBLB3A-_ap0ap_tcz_085-rH7A-ORG_aoiYPjrOQEEHl-AQcnanuVjEx30n-UyKcjP6BHoXbNKMj-GyWyclUsSHo1t0Tw2ARN6b7FIaK272DToMQCLbxGxJJymD5Iwy2p03XeUH1vbZmq2EOewq1Q1W2YPmJ_M2YAUYL2I4MyF2icS4xdySZ1y3mdmbuA",
|
||||
"expiration_url": "https://sandbox-api.vistarmedia.com/api/v2/cancel/json?s=27jkXH6c5WIPAaVHTauJUJ0NFfbMQlequO8MUArXW8Hhdot43e0S6fo5kK2j7r3kCVybgRnrRsxu2-zibsVFueeUMfwytTVPMYhG4u--3YEvFH6rQe2LQKiWnkQmyopVC09URKCS3Vtz8H0G3svHQMeWi8tcvnkZyVHzEIzDLuBXugusV76kbUZ-OvIhOihT0cPBH3Oj5mAKQZpQiP2sCVMVS0XocBajc20CeCE7rYXwds-Rj1WnvRPvEzz_dBpfwo-cpD8tNLUJCOzr5loY_kxOgbYQttEPwD1SWEZgCmf7qo9AaaTYDjiEHKHgU94t5AaldJqIaz3f5ax5j5oXr9YxvOGSblN25XPNoNZDFWbb0bS5oClXhBN3kWIB_U_C_lLqFYx0nZAQuiso9oSzaTiEbqTCbNCkpZ8UPxCxvsUq6_Q5usQkKNwzG6TCv1_fK9xRTWoVHznMoiHZ0y-lDF33K6QCEmAqDExpCWi7BIsT66KFznH0DbgElJBYsTpX7Dp5Na7MNaE3_Rus4fJz8Kjx4gwL0vYTl_pHmOaZZPQGOQp8GKv4qq7uvSEUw49-tY2id5snQ1xBQ0iwVsX5EET_wKJh9-EJHzcjqhBr_ZcIk70qgxK1zTMjfqDe6_aQHfY3rXiAXRPCUOM9ayUy8db1cbyuOdkOA63HQJXLIGVNwTXOlaDU-jBLB3A-_ap0ap_tcz_085-rH7A-ORG_aoiYPjrOQEEHl-AQcnanuVjEx30n-UyKcjP6BHoXbNKMj-GyWyclUsSHo1t0Tw2ARN6b7FIaK272DToMQCLbxGxJJymD5Iwy2p03XeUH1vbZmq2EOewq1Q1W2YPmJ_M2YAUYL2I4MyF2icS4xdySZ1y3mdmbuA",
|
||||
"display_time": 1638576000,
|
||||
"lease_expiry": 1638662400,
|
||||
"display_area_id": "display-0",
|
||||
"creative_id": "582e43720b476f4e6d3e5e69495e370c585b27436352",
|
||||
"asset_id": "6e286b5d0b796835683b78154b4030162f643b1b7e74",
|
||||
"asset_url": "https://s3.amazonaws.com/dev.assets.vistarmedia.com/creative/SLNbnvhuQo2t71yKptSsvA/2f/f0a/c1137069-0966-4be2-b109-1d742d759191.jpeg",
|
||||
"width": 600,
|
||||
"height": 900,
|
||||
"mime_type": "image/jpeg",
|
||||
"length_in_seconds": 8,
|
||||
"length_in_milliseconds": 8000,
|
||||
"campaign_id": 1044648314,
|
||||
"creative_category": "10144",
|
||||
"advertiser": "01"
|
||||
}
|
||||
]
|
||||
}
|
||||
53
spec/services/vendors/vistar/vistar_fetch_ad_spec.rb
vendored
Normal file
53
spec/services/vendors/vistar/vistar_fetch_ad_spec.rb
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'webmock/rspec'
|
||||
|
||||
RSpec.describe Vendors::Vistar::VistarFetchAd do
|
||||
let(:player) { 'dpc-100ca2-154410202' }
|
||||
let(:tokens) { double(api_key: SecureRandom.uuid) }
|
||||
let(:action) { described_class.new(tokens) }
|
||||
let(:auth_token) { SecureRandom.hex(10) }
|
||||
let(:params) { { device_id: player } }
|
||||
|
||||
before do
|
||||
allow(Vendors::Vistar::VistarSettings.instance).to receive(:network_id).and_return('fake-network-id')
|
||||
end
|
||||
|
||||
context 'when successful' do
|
||||
let(:response_body) { JSON.parse(File.read('spec/services/vendors/vistar/vistar_ad_fetch_response.json')).with_indifferent_access }
|
||||
|
||||
before do
|
||||
WebMock.stub_request(:post, Vendors::Vistar::VistarSettings.instance.vistar_url(described_class::PATH))
|
||||
.to_return(
|
||||
status: 200,
|
||||
body: response_body.to_json
|
||||
)
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
it 'makes the http call' do
|
||||
response = action.call(params)
|
||||
expect(response).to eq(response_body)
|
||||
end
|
||||
|
||||
it 'requests an api key' do
|
||||
action.call(params)
|
||||
expect(tokens).to have_received(:api_key).once
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unsuccessful' do
|
||||
before do
|
||||
WebMock.stub_request(:post, Vendors::Vistar::VistarSettings.instance.vistar_url(described_class::PATH))
|
||||
.to_return(
|
||||
status: 500,
|
||||
)
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
expect { action.call(params) }.to raise_error(Vendors::Errors::ScheduleFetchError)
|
||||
end
|
||||
end
|
||||
end
|
||||
41
spec/services/vendors/vistar/vistar_fetch_schedule_spec.rb
vendored
Normal file
41
spec/services/vendors/vistar/vistar_fetch_schedule_spec.rb
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vendors::Vistar::VistarFetchSchedule do
|
||||
let(:tokens) { double(api_key: SecureRandom.uuid) }
|
||||
let(:action) { described_class.new(tokens) }
|
||||
let(:params) { {} }
|
||||
|
||||
|
||||
let(:fetch_ad_response) { JSON.parse(File.read('spec/services/vendors/vistar/vistar_ad_fetch_response.json')).with_indifferent_access }
|
||||
let(:ad) { fetch_ad_response[:advertisement][0] }
|
||||
let(:schedule) do
|
||||
{
|
||||
contents: [
|
||||
{
|
||||
name: "vistar_asset_#{ad[:asset_id]}",
|
||||
url: ad[:asset_url]
|
||||
}
|
||||
],
|
||||
startTime: Time.at(ad[:display_time]).to_datetime,
|
||||
items: [
|
||||
{
|
||||
contentIndex: 0,
|
||||
duration: "#{ad[:length_in_seconds]}s",
|
||||
pop_url: ad[:proof_of_play_url]
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
context 'when ad is fetched from vistar' do
|
||||
before { allow(action).to receive(:fetch_ad).and_return(fetch_ad_response) }
|
||||
|
||||
it 'returns the expected schedule with the first ad' do
|
||||
expect(action.call(params)).to eq(schedule)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
16
spec/services/vendors/vistar/vistar_schedule.json
vendored
Normal file
16
spec/services/vendors/vistar/vistar_schedule.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"contents": [
|
||||
{
|
||||
"name": "vistar_asset_-227826498",
|
||||
"url": "https://s3.amazonaws.com/dev.assets.vistarmedia.com/creative/SLNbnvhuQo2t71yKptSsvA/2f/f0a/c1137069-0966-4be2-b109-1d742d759191.jpeg"
|
||||
}
|
||||
],
|
||||
"startTime": 1638576000,
|
||||
"items": [
|
||||
{
|
||||
"contentIndex": 0,
|
||||
"duration": "8s",
|
||||
"pop_url": "https://sandbox-api.vistarmedia.com/api/v2/proof_of_play/json?s=27jkXH6c5WIPAaVHTauJUJ0NFfbMQlequO8MUArXW8Hhdot43e0S6fo5kK2j7r3kCVybgRnrRsxu2-zibsVFueeUMfwytTVPMYhG4u--3YEvFH6rQe2LQKiWnkQmyopVC09URKCS3Vtz8H0G3svHQMeWi8tcvnkZyVHzEIzDLuBXugusV76kbUZ-OvIhOihT0cPBH3Oj5mAKQZpQiP2sCVMVS0XocBajc20CeCE7rYXwds-Rj1WnvRPvEzz_dBpfwo-cpD8tNLUJCOzr5loY_kxOgbYQttEPwD1SWEZgCmf7qo9AaaTYDjiEHKHgU94t5AaldJqIaz3f5ax5j5oXr9YxvOGSblN25XPNoNZDFWbb0bS5oClXhBN3kWIB_U_C_lLqFYx0nZAQuiso9oSzaTiEbqTCbNCkpZ8UPxCxvsUq6_Q5usQkKNwzG6TCv1_fK9xRTWoVHznMoiHZ0y-lDF33K6QCEmAqDExpCWi7BIsT66KFznH0DbgElJBYsTpX7Dp5Na7MNaE3_Rus4fJz8Kjx4gwL0vYTl_pHmOaZZPQGOQp8GKv4qq7uvSEUw49-tY2id5snQ1xBQ0iwVsX5EET_wKJh9-EJHzcjqhBr_ZcIk70qgxK1zTMjfqDe6_aQHfY3rXiAXRPCUOM9ayUy8db1cbyuOdkOA63HQJXLIGVNwTXOlaDU-jBLB3A-_ap0ap_tcz_085-rH7A-ORG_aoiYPjrOQEEHl-AQcnanuVjEx30n-UyKcjP6BHoXbNKMj-GyWyclUsSHo1t0Tw2ARN6b7FIaK272DToMQCLbxGxJJymD5Iwy2p03XeUH1vbZmq2EOewq1Q1W2YPmJ_M2YAUYL2I4MyF2icS4xdySZ1y3mdmbuA"
|
||||
}
|
||||
]
|
||||
}
|
||||
31
spec/services/vendors/vistar/vistar_transform_schedule_spec.rb
vendored
Normal file
31
spec/services/vendors/vistar/vistar_transform_schedule_spec.rb
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Vendors::Vistar::VistarTransformSchedule 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/vistar/vistar_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
|
||||
71
spec/services/vle/vle_create_asset_spec.rb
Normal file
71
spec/services/vle/vle_create_asset_spec.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'webmock/rspec'
|
||||
|
||||
RSpec.describe Vle::VleCreateAsset do
|
||||
let(:token) { SecureRandom.hex(4) }
|
||||
let(:asset) do
|
||||
{
|
||||
asset: {
|
||||
id: 101,
|
||||
type: "asset",
|
||||
processed: 0,
|
||||
error: "",
|
||||
project_id: 155162,
|
||||
meta: {
|
||||
key: "sandbox-vle/library/original/101_original.jpeg",
|
||||
presigned_url: "https://fake-url.com",
|
||||
original_filename: "sunrise.jpeg"
|
||||
},
|
||||
name:"sunrise",
|
||||
orientation:"any",
|
||||
loop:false,
|
||||
contract_id:"",
|
||||
description_long:"",
|
||||
description_short:"",
|
||||
tag_match_expression:"",
|
||||
tags:[],
|
||||
created_at:"2021-10-22T18:09:13.689Z",
|
||||
updated_at:"2021-10-22T18:09:13.710Z",
|
||||
blobs:[]
|
||||
}
|
||||
}.with_indifferent_access
|
||||
end
|
||||
let(:content) { asset.slice(:name, :organization_id, :project_id, :contract_id).merge(file: 'fake-filename.ext') }
|
||||
let(:action) { described_class.new(content) }
|
||||
let(:url) { Vle::VleSettings.instance.central_url.join(described_class::PATH) }
|
||||
|
||||
context 'when successful' do
|
||||
before do
|
||||
WebMock.stub_request(:post, action.url)
|
||||
.to_return(
|
||||
status: 200,
|
||||
body: { asset: asset }.to_json
|
||||
)
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
it 'makes the http call' do
|
||||
response = action.call(token)
|
||||
expect(response[:asset]).to eq(asset)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unsuccessful with 401' do
|
||||
before { WebMock.stub_request(:post, action.url).to_return(status: 401, body: "") }
|
||||
|
||||
it 'raises an auth error' do
|
||||
expect { action.call(token) }.to raise_error(Auth::Client::Errors::Unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unsuccessful with 500' do
|
||||
before { WebMock.stub_request(:post, action.url).to_return(status: 500, body: "") }
|
||||
|
||||
it 'raises an error' do
|
||||
expect { action.call(token) }.to raise_error(Vendors::Errors::ContentIngestError)
|
||||
end
|
||||
end
|
||||
end
|
||||
43
spec/services/vle/vle_ingest_asset_spec.rb
Normal file
43
spec/services/vle/vle_ingest_asset_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'webmock/rspec'
|
||||
|
||||
RSpec.describe Vle::VleIngestAsset do
|
||||
let(:action) { described_class.new }
|
||||
let(:source) { 'https://fake-source.com' }
|
||||
let(:destination) { 'https://fake-destination.com' }
|
||||
let(:content) { { uri: source } }
|
||||
let(:asset_contents) { SecureRandom.hex(16) }
|
||||
|
||||
before do
|
||||
WebMock.stub_request(:get, source).to_return(status: 200, body: asset_contents)
|
||||
WebMock.stub_request(:put, destination).to_return(status: 200)
|
||||
end
|
||||
|
||||
context 'when the requests work' do
|
||||
describe '#call' do
|
||||
it('succeeds') { expect(action.call(content, destination)).to eq(true) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content fetch fails' do
|
||||
before do
|
||||
WebMock.stub_request(:get, source).to_return(status: 400)
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
expect { action.call(content, destination) }.to raise_error(Vendors::Errors::ContentIngestError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content post fails' do
|
||||
before do
|
||||
WebMock.stub_request(:put, destination).to_return(status: 400)
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
expect { action.call(content, destination) }.to raise_error(Vendors::Errors::ContentIngestError)
|
||||
end
|
||||
end
|
||||
end
|
||||
58
spec/services/vle/vle_vendor_schedule_spec.rb
Normal file
58
spec/services/vle/vle_vendor_schedule_spec.rb
Normal file
@@ -0,0 +1,58 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'webmock/rspec'
|
||||
|
||||
RSpec.describe Vle::VleVendorSchedule do
|
||||
let(:token) { SecureRandom.hex(10) }
|
||||
let(:vendor) { 'fake-vendor' }
|
||||
let(:player) { 'dpc-100ca2-154410202' }
|
||||
let(:schedule) do
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"startTime": "2019-06-14T14:17:26.456Z",
|
||||
"duration": "5s",
|
||||
"pop_data": "CgphbGV4YW5kcmVjEgNVVEMaDAj22I7oBRCAhLjZASICCAUoAToDCNMBQgMIlRtKAwiSG2IDVVUwcgMI4BE=",
|
||||
"content_key": 0,
|
||||
},
|
||||
{
|
||||
"startTime": "2019-06-14T14:17:26.456Z",
|
||||
"duration": "5s",
|
||||
"pop_data": "CgphbGV4YW5kcmVjEgNVVEMaDAj72I7oBRCAhLjZASICCAUoAToDCNQBQgMInhtKAwiSG2IDVVUwcgMI4BE=",
|
||||
"content_key": 1,
|
||||
}
|
||||
]
|
||||
}.with_indifferent_access
|
||||
end
|
||||
let(:action) { described_class.new(vendor, player, schedule) }
|
||||
|
||||
let(:url) { Vle::VleSettings.instance.scheduler_url.join(described_class::PATH) }
|
||||
|
||||
context 'when successful' do
|
||||
before { WebMock.stub_request(:post, action.url).to_return(status: 200, body: {}.to_json ) }
|
||||
|
||||
describe '#call' do
|
||||
it 'makes the http call' do
|
||||
response = action.call(token)
|
||||
expect(response).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unsuccessful with a 401' do
|
||||
before { WebMock.stub_request(:post, action.url).to_return(status: 401) }
|
||||
|
||||
it 'raises an error' do
|
||||
expect { action.call(token) }.to raise_error(Auth::Client::Errors::Unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unsuccessful with a 500' do
|
||||
before { WebMock.stub_request(:post, action.url).to_return(status: 500) }
|
||||
|
||||
it 'raises an error' do
|
||||
expect { action.call(token) }.to raise_error(Vendors::Errors::SchedulePublishError)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user