Initial commit
This commit is contained in:
75
spec/rails_helper.rb
Normal file
75
spec/rails_helper.rb
Normal file
@@ -0,0 +1,75 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'simplecov'
|
||||
require 'simplecov-cobertura'
|
||||
|
||||
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
|
||||
SimpleCov.start 'rails' do
|
||||
add_filter '/vendor/'
|
||||
add_filter '/.bundle/'
|
||||
end
|
||||
|
||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||
require 'spec_helper'
|
||||
ENV['RAILS_ENV'] ||= 'test'
|
||||
require File.expand_path('../config/environment', __dir__)
|
||||
# Prevent database truncation if the environment is production
|
||||
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
||||
require 'rspec/rails'
|
||||
# Add additional requires below this line. Rails is not loaded until this point!
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
||||
# run as spec files by default. This means that files in spec/support that end
|
||||
# in _spec.rb will both be required and run as specs, causing the specs to be
|
||||
# run twice. It is recommended that you do not name files matching this glob to
|
||||
# end with _spec.rb. You can configure this pattern with the --pattern
|
||||
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
||||
#
|
||||
# The following line is provided for convenience purposes. It has the downside
|
||||
# of increasing the boot-up time by auto-requiring all files in the support
|
||||
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
||||
# require only the support files necessary.
|
||||
#
|
||||
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
|
||||
|
||||
# Checks for pending migrations and applies them before tests are run.
|
||||
# If you are not using ActiveRecord, you can remove these lines.
|
||||
begin
|
||||
ActiveRecord::Migration.maintain_test_schema!
|
||||
rescue ActiveRecord::PendingMigrationError => e
|
||||
puts e.to_s.strip
|
||||
exit 1
|
||||
end
|
||||
RSpec.configure do |config|
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
|
||||
# You can uncomment this line to turn off ActiveRecord support entirely.
|
||||
# config.use_active_record = false
|
||||
|
||||
# RSpec Rails can automatically mix in different behaviours to your tests
|
||||
# based on their file location, for example enabling you to call `get` and
|
||||
# `post` in specs under `spec/controllers`.
|
||||
#
|
||||
# You can disable this behaviour by removing the line below, and instead
|
||||
# explicitly tag your specs with their type, e.g.:
|
||||
#
|
||||
# RSpec.describe UsersController, type: :controller do
|
||||
# # ...
|
||||
# end
|
||||
#
|
||||
# The different available types are documented in the features, such as in
|
||||
# https://relishapp.com/rspec/rspec-rails/docs
|
||||
config.infer_spec_type_from_file_location!
|
||||
|
||||
# Filter lines from Rails gems in backtraces.
|
||||
config.filter_rails_from_backtrace!
|
||||
# arbitrary gems may also be filtered via:
|
||||
# config.filter_gems_from_backtrace("gem name")
|
||||
end
|
||||
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
|
||||
96
spec/spec_helper.rb
Normal file
96
spec/spec_helper.rb
Normal file
@@ -0,0 +1,96 @@
|
||||
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
||||
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
||||
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
||||
# this file to always be loaded, without a need to explicitly require it in any
|
||||
# files.
|
||||
#
|
||||
# Given that it is always loaded, you are encouraged to keep this file as
|
||||
# light-weight as possible. Requiring heavyweight dependencies from this file
|
||||
# will add to the boot time of your test suite on EVERY test run, even for an
|
||||
# individual file that may not need all of that loaded. Instead, consider making
|
||||
# a separate helper file that requires the additional dependencies and performs
|
||||
# the additional setup, and require it from the spec files that actually need
|
||||
# it.
|
||||
#
|
||||
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
||||
RSpec.configure do |config|
|
||||
# rspec-expectations config goes here. You can use an alternate
|
||||
# assertion/expectation library such as wrong or the stdlib/minitest
|
||||
# assertions if you prefer.
|
||||
config.expect_with :rspec do |expectations|
|
||||
# This option will default to `true` in RSpec 4. It makes the `description`
|
||||
# and `failure_message` of custom matchers include text for helper methods
|
||||
# defined using `chain`, e.g.:
|
||||
# be_bigger_than(2).and_smaller_than(4).description
|
||||
# # => "be bigger than 2 and smaller than 4"
|
||||
# ...rather than:
|
||||
# # => "be bigger than 2"
|
||||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
||||
end
|
||||
|
||||
# rspec-mocks config goes here. You can use an alternate test double
|
||||
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
||||
config.mock_with :rspec do |mocks|
|
||||
# Prevents you from mocking or stubbing a method that does not exist on
|
||||
# a real object. This is generally recommended, and will default to
|
||||
# `true` in RSpec 4.
|
||||
mocks.verify_partial_doubles = true
|
||||
end
|
||||
|
||||
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
||||
# have no way to turn it off -- the option exists only for backwards
|
||||
# compatibility in RSpec 3). It causes shared context metadata to be
|
||||
# inherited by the metadata hash of host groups and examples, rather than
|
||||
# triggering implicit auto-inclusion in groups with matching metadata.
|
||||
config.shared_context_metadata_behavior = :apply_to_host_groups
|
||||
|
||||
# The settings below are suggested to provide a good initial experience
|
||||
# with RSpec, but feel free to customize to your heart's content.
|
||||
=begin
|
||||
# This allows you to limit a spec run to individual examples or groups
|
||||
# you care about by tagging them with `:focus` metadata. When nothing
|
||||
# is tagged with `:focus`, all examples get run. RSpec also provides
|
||||
# aliases for `it`, `describe`, and `context` that include `:focus`
|
||||
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
||||
config.filter_run_when_matching :focus
|
||||
|
||||
# Allows RSpec to persist some state between runs in order to support
|
||||
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
||||
# you configure your source control system to ignore this file.
|
||||
config.example_status_persistence_file_path = "spec/examples.txt"
|
||||
|
||||
# Limits the available syntax to the non-monkey patched syntax that is
|
||||
# recommended. For more details, see:
|
||||
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
||||
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
||||
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
||||
config.disable_monkey_patching!
|
||||
|
||||
# Many RSpec users commonly either run the entire suite or an individual
|
||||
# file, and it's useful to allow more verbose output when running an
|
||||
# individual spec file.
|
||||
if config.files_to_run.one?
|
||||
# Use the documentation formatter for detailed output,
|
||||
# unless a formatter has already been configured
|
||||
# (e.g. via a command-line flag).
|
||||
config.default_formatter = "doc"
|
||||
end
|
||||
|
||||
# Print the 10 slowest examples and example groups at the
|
||||
# end of the spec run, to help surface which specs are running
|
||||
# particularly slow.
|
||||
config.profile_examples = 10
|
||||
|
||||
# Run specs in random order to surface order dependencies. If you find an
|
||||
# order dependency and want to debug it, you can fix the order by providing
|
||||
# the seed, which is printed after each run.
|
||||
# --seed 1234
|
||||
config.order = :random
|
||||
|
||||
# Seed global randomization in this process using the `--seed` CLI option.
|
||||
# Setting this allows you to use `--seed` to deterministically reproduce
|
||||
# test failures related to randomization by passing the same `--seed` value
|
||||
# as the one that triggered the failure.
|
||||
Kernel.srand config.seed
|
||||
=end
|
||||
end
|
||||
Reference in New Issue
Block a user