Initial commit
This commit is contained in:
71
spec/services/vle/vle_create_asset_spec.rb
Normal file
71
spec/services/vle/vle_create_asset_spec.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
# 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
|
||||
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
|
||||
58
spec/services/vle/vle_vendor_schedule_spec.rb
Normal file
58
spec/services/vle/vle_vendor_schedule_spec.rb
Normal file
@@ -0,0 +1,58 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user