44 lines
1.2 KiB
Ruby
44 lines
1.2 KiB
Ruby
# 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
|