Initial commit

This commit is contained in:
Senad Uka
2022-03-23 05:44:42 +01:00
parent 1405281a5c
commit eea10dd03b
113 changed files with 3617 additions and 81 deletions

View 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