Initial commit
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user