Files
old-vendor-scheduler-service/spec/services/vle/vle_create_asset_spec.rb
2022-03-23 05:44:42 +01:00

72 lines
1.9 KiB
Ruby

# 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