-
Notifications
You must be signed in to change notification settings - Fork 2
/
notify_goobi_spec.rb
42 lines (34 loc) · 1.28 KB
/
notify_goobi_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Notify Goobi' do
let(:object) { Dor::Item.new(pid: 'druid:1234') }
let(:fake_request) { "<stanfordCreationRequest><objectId>#{object.pid}</objectId></stanfordCreationRequest>" }
before do
allow(Dor).to receive(:find).and_return(object)
allow_any_instance_of(Dor::Goobi).to receive(:xml_request).and_return fake_request
end
context 'when it is successful' do
before do
stub_request(:post, Settings.goobi.url)
.to_return(body: fake_request,
headers: { 'Content-Type' => 'application/xml' },
status: 201)
end
it 'notifies goobi of a new registration by making a web service call' do
post '/v1/objects/druid:1234/notify_goobi', headers: { 'Authorization' => "Bearer #{jwt}" }
expect(response.status).to eq(201)
end
end
context 'when it is a conflict' do
before do
stub_request(:post, Settings.goobi.url)
.to_return(body: 'conflict',
status: 409)
end
it 'returns the conflict code' do
post '/v1/objects/druid:1234/notify_goobi', headers: { 'Authorization' => "Bearer #{jwt}" }
expect(response.status).to eq(409)
expect(response.body).to eq('conflict')
end
end
end