# 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