rsbe-client 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +3 -0
- data/GETTING-STARTED.md +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +11 -0
- data/TODO.md +38 -0
- data/lib/rsbe/client.rb +50 -0
- data/lib/rsbe/client/base.rb +140 -0
- data/lib/rsbe/client/collection.rb +84 -0
- data/lib/rsbe/client/connection.rb +24 -0
- data/lib/rsbe/client/method_not_implemented_error.rb +6 -0
- data/lib/rsbe/client/not_found_error.rb +6 -0
- data/lib/rsbe/client/partner.rb +82 -0
- data/lib/rsbe/client/provider.rb +47 -0
- data/lib/rsbe/client/se.rb +97 -0
- data/lib/rsbe/client/search.rb +80 -0
- data/lib/rsbe/client/search_results.rb +41 -0
- data/lib/rsbe/client/unrecognized_resource_error.rb +6 -0
- data/lib/rsbe/client/version.rb +5 -0
- data/lib/rsbe/client/wrong_origin_error.rb +6 -0
- data/rsbe-client.gemspec +30 -0
- data/spec/fixtures/partners/partners_all.json +1 -0
- data/spec/fixtures/partners/partners_none.json +1 -0
- data/spec/rsbe/client/base_spec.rb +10 -0
- data/spec/rsbe/client/collection_spec.rb +186 -0
- data/spec/rsbe/client/connection_spec.rb +20 -0
- data/spec/rsbe/client/partner_spec.rb +185 -0
- data/spec/rsbe/client/provider_spec.rb +122 -0
- data/spec/rsbe/client/se_spec.rb +273 -0
- data/spec/rsbe/client/search_results_spec.rb +140 -0
- data/spec/rsbe/client/search_spec.rb +74 -0
- data/spec/rsbe/client_spec.rb +52 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/vcr_cassettes/client/find_collection.yml +53 -0
- data/spec/vcr_cassettes/client/find_partner.yml +52 -0
- data/spec/vcr_cassettes/client/find_provider.yml +52 -0
- data/spec/vcr_cassettes/client/find_se.yml +53 -0
- data/spec/vcr_cassettes/collection/find-existing.yml +53 -0
- data/spec/vcr_cassettes/collection/find-non_existent.yml +50 -0
- data/spec/vcr_cassettes/collection/lazy-eval-dne.yml +285 -0
- data/spec/vcr_cassettes/collection/lazy-eval-exists.yml +53 -0
- data/spec/vcr_cassettes/collection/save-create-known-id.yml +103 -0
- data/spec/vcr_cassettes/collection/save-create-unknown-id.yml +56 -0
- data/spec/vcr_cassettes/collection/save-invalid.yml +143 -0
- data/spec/vcr_cassettes/collection/save-update-valid.yml +99 -0
- data/spec/vcr_cassettes/partner/all.yml +300 -0
- data/spec/vcr_cassettes/partner/dne-with-id.yml +238 -0
- data/spec/vcr_cassettes/partner/find-existing.yml +52 -0
- data/spec/vcr_cassettes/partner/find-non_existent.yml +50 -0
- data/spec/vcr_cassettes/partner/lazy-eval-exists.yml +53 -0
- data/spec/vcr_cassettes/partner/save-create-known-id.yml +101 -0
- data/spec/vcr_cassettes/partner/save-create-unknown-id.yml +54 -0
- data/spec/vcr_cassettes/partner/save-invalid.yml +177 -0
- data/spec/vcr_cassettes/partner/save-unknown-id.yml +54 -0
- data/spec/vcr_cassettes/partner/save-update-valid.yml +98 -0
- data/spec/vcr_cassettes/partner/with-collections.yml +203 -0
- data/spec/vcr_cassettes/partner/without-collections.yml +101 -0
- data/spec/vcr_cassettes/provider/all.yml +248 -0
- data/spec/vcr_cassettes/provider/find-existing.yml +52 -0
- data/spec/vcr_cassettes/provider/find-non_existent.yml +50 -0
- data/spec/vcr_cassettes/provider/save-create-known-id.yml +101 -0
- data/spec/vcr_cassettes/provider/save-create-unknown-id.yml +54 -0
- data/spec/vcr_cassettes/provider/save-invalid.yml +178 -0
- data/spec/vcr_cassettes/provider/save-update-valid.yml +144 -0
- data/spec/vcr_cassettes/se/find-existing.yml +53 -0
- data/spec/vcr_cassettes/se/find-non_existent.yml +50 -0
- data/spec/vcr_cassettes/se/lazy-eval-exists.yml +52 -0
- data/spec/vcr_cassettes/se/save-create-known-id.yml +146 -0
- data/spec/vcr_cassettes/se/save-create-unknown-id.yml +56 -0
- data/spec/vcr_cassettes/se/save-invalid.yml +305 -0
- data/spec/vcr_cassettes/se/save-update-valid.yml +99 -0
- data/spec/vcr_cassettes/se/search-malformed-uuid.yml +54 -0
- data/spec/vcr_cassettes/se/search-with-existing-se.yml +52 -0
- data/spec/vcr_cassettes/se/search-with-missing-se.yml +52 -0
- data/spec/vcr_cassettes/search/search-with-existing-se.yml +52 -0
- data/spec/vcr_cassettes/search_results/no-results.yml +52 -0
- data/spec/vcr_cassettes/search_results/search-by-digi_id.yml +101 -0
- data/spec/vcr_cassettes/search_results/search-by-step.yml +201 -0
- metadata +307 -0
@@ -0,0 +1,273 @@
|
|
1
|
+
describe Rsbe::Client::Se do
|
2
|
+
def chk_header(valid_params,incoming_response)
|
3
|
+
exist = []
|
4
|
+
allowed_param = {:scope => "ses"}
|
5
|
+
incoming_response.each_key { |k|
|
6
|
+
s = k.to_sym
|
7
|
+
if valid_params.key?(s) and valid_params[s] == incoming_response[k]
|
8
|
+
exist << true
|
9
|
+
elsif allowed_param.key?(s) and allowed_param[s] == incoming_response[k]
|
10
|
+
exist << true
|
11
|
+
else
|
12
|
+
exist << false
|
13
|
+
end
|
14
|
+
}
|
15
|
+
exist
|
16
|
+
end
|
17
|
+
describe ".new" do
|
18
|
+
context "with valid attributes and symbol keys" do
|
19
|
+
subject { Rsbe::Client::Se.new(coll_id: 'ea85c776-a79b-4603-b307-d6760a400281', digi_id: 'boo', do_type: 'audio', phase: 'digitization', step: 'qc', status: 'pause', label:'why label anything?', notes: 'notes') }
|
20
|
+
it { should be_a(Rsbe::Client::Se) }
|
21
|
+
its(:coll_id) { should eq 'ea85c776-a79b-4603-b307-d6760a400281' }
|
22
|
+
its(:digi_id) { should eq 'boo' }
|
23
|
+
its(:do_type) { should eq 'audio' }
|
24
|
+
its(:phase) { should eq 'digitization' }
|
25
|
+
its(:step) { should eq 'qc' }
|
26
|
+
its(:status) { should eq 'pause' }
|
27
|
+
its(:label) { should eq 'why label anything?' }
|
28
|
+
its(:notes) { should eq 'notes' }
|
29
|
+
end
|
30
|
+
context "with incorrect argument type" do
|
31
|
+
subject { Rsbe::Client::Se.new(24) }
|
32
|
+
it 'should raise an ArgumentError' do
|
33
|
+
expect { subject }.to raise_error ArgumentError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".base_path" do
|
39
|
+
subject { Rsbe::Client::Se }
|
40
|
+
its(:base_path) { should eq '/api/v0/ses' }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".all" do
|
44
|
+
subject { Rsbe::Client::Se.all }
|
45
|
+
it 'should raise a MethodNotImplementedError' do
|
46
|
+
expect { subject }.to raise_error Rsbe::Client::MethodNotImplementedError
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".search" do
|
51
|
+
describe "with valid params" do
|
52
|
+
context "with an existing se", vcr: {cassette_name: 'se/search-with-existing-se'} do
|
53
|
+
let(:valid_params) { {coll_id: 'ea85c776-a79b-4603-b307-d6760a400281', digi_id: 'foo_quux_cuid370'} }
|
54
|
+
let(:response) { Rsbe::Client::Se.search(valid_params) }
|
55
|
+
let(:header) { JSON.parse(response.body)['responseHeader'] }
|
56
|
+
let(:results) { JSON.parse(response.body)['response'] }
|
57
|
+
it "should have a response status of 200" do
|
58
|
+
expect(response.status).to eq(200)
|
59
|
+
end
|
60
|
+
it "should have a numFound of 1" do
|
61
|
+
expect(results['numFound']).to eq(1)
|
62
|
+
end
|
63
|
+
it "docs array size should be 1" do
|
64
|
+
expect(results['docs'].size).to eq(1)
|
65
|
+
end
|
66
|
+
it "should have a url of a certain value" do
|
67
|
+
expect(results['docs'][0]['url']).to eq("http://localhost:3000/api/v0/ses/f903ee1f-83e3-4ba2-8234-0d0b85793705")
|
68
|
+
end
|
69
|
+
it "should respond with a valid params in the responseHeader" do
|
70
|
+
valid_header_params = chk_header(valid_params,header["params"])
|
71
|
+
expect(valid_header_params).not_to include(false)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
context "with valid params but malformed uuid", vcr: {cassette_name: 'se/search-malformed-uuid'} do
|
75
|
+
let(:bad_uuid) { {coll_id: 'ea85c0a400281', digi_id: 'foo_quux_cuid370'} }
|
76
|
+
let(:response) { Rsbe::Client::Se.search(bad_uuid) }
|
77
|
+
let(:message) { JSON.parse(response.body) }
|
78
|
+
it "should have a response status of 400" do
|
79
|
+
expect(response.status).to eq(400)
|
80
|
+
end
|
81
|
+
it "should have a hash with a key called errors" do
|
82
|
+
expect(message.key?("errors")).to be true
|
83
|
+
end
|
84
|
+
it "should have an error message" do
|
85
|
+
expect(message["errors"][0]).to match(/invalid input syntax for uuid:/)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
context "with a non-existent se", vcr: {cassette_name: 'se/search-with-missing-se'} do
|
89
|
+
let(:no_se) { {coll_id: 'ea85c776-a79b-4603-b307-d6760a400281', digi_id: 'iamnothere'} }
|
90
|
+
let(:response) { Rsbe::Client::Se.search(no_se) }
|
91
|
+
let(:results) { JSON.parse(response.body)['response'] }
|
92
|
+
it "should have a response status of 200" do
|
93
|
+
status = response.status
|
94
|
+
expect(status).to eq(200)
|
95
|
+
end
|
96
|
+
it "should have a numFound of 0" do
|
97
|
+
expect(results['numFound']).to eq(0)
|
98
|
+
end
|
99
|
+
it "docs array size should be 0" do
|
100
|
+
expect(results['docs'].size).to eq(0)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
context "with invalid params" do
|
106
|
+
it "raises an error if no params are sent" do
|
107
|
+
expect { Rsbe::Client::Se.search }.to raise_error(ArgumentError)
|
108
|
+
end
|
109
|
+
it "raises an error if a param key is a string" do
|
110
|
+
invalid_params = {'coll_id' => 'ea85c776-a79b-4603-b307-d6760a400281', 'digi_id' => 'foo_quux_cuid370'}
|
111
|
+
expect { Rsbe::Client::Se.search(invalid_params) }.to raise_error(ArgumentError)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
describe ".find" do
|
116
|
+
context "with id of existing Se", vcr: {cassette_name: 'se/find-existing'} do
|
117
|
+
subject { Rsbe::Client::Se.find('acf51ef2-8bf3-4f05-9042-0bfcb6860560') }
|
118
|
+
its(:class) { should eq Rsbe::Client::Se }
|
119
|
+
its(:id) { should eq 'acf51ef2-8bf3-4f05-9042-0bfcb6860560' }
|
120
|
+
its(:digi_id) { should eq 'foo_quux_cuid01234' }
|
121
|
+
end
|
122
|
+
|
123
|
+
context "with non-existent id", vcr: {cassette_name: 'se/find-non_existent'} do
|
124
|
+
subject { Rsbe::Client::Se.find('443d3d42-1084-4045-b618-f4358d6e8b12') }
|
125
|
+
it 'should raise an Rsbe::Client::RecordNotFound' do
|
126
|
+
expect { subject }.to raise_error Rsbe::Client::RecordNotFound
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#save" do
|
132
|
+
context "when creating a new Se" do
|
133
|
+
context "with valid attributes" do
|
134
|
+
# TODO: implment FactoryGirl
|
135
|
+
context "and no id", vcr: {cassette_name: 'se/save-create-unknown-id'} do
|
136
|
+
let(:coll_id) { "ea85c776-a79b-4603-b307-d6760a400281" }
|
137
|
+
let(:digi_id) { 'posso_dormire' }
|
138
|
+
let(:do_type) { 'map' }
|
139
|
+
let(:phase) { 'upload' }
|
140
|
+
let(:step) { 'packaging' }
|
141
|
+
let(:status) { 'done' }
|
142
|
+
let(:label) { 'labels' }
|
143
|
+
let(:notes) { 'lorem ipsum dolor' }
|
144
|
+
let(:se) { Rsbe::Client::Se.new(coll_id: coll_id,
|
145
|
+
digi_id: digi_id,
|
146
|
+
do_type: do_type,
|
147
|
+
phase: phase,
|
148
|
+
step: step,
|
149
|
+
status: status,
|
150
|
+
label: label,
|
151
|
+
notes: notes) }
|
152
|
+
subject { se }
|
153
|
+
its(:save) { should eq true }
|
154
|
+
|
155
|
+
context "after save" do
|
156
|
+
before { se.save }
|
157
|
+
its(:id) { should_not be_nil }
|
158
|
+
its(:coll_id) { should eq 'ea85c776-a79b-4603-b307-d6760a400281' }
|
159
|
+
its(:digi_id) { should eq digi_id }
|
160
|
+
its(:do_type) { should eq do_type }
|
161
|
+
its(:phase) { should eq phase }
|
162
|
+
its(:step) { should eq step }
|
163
|
+
its(:status) { should eq status }
|
164
|
+
its(:label) { should eq label }
|
165
|
+
its(:notes) { should eq notes }
|
166
|
+
its(:created_at) { should_not be_nil }
|
167
|
+
its(:updated_at) { should_not be_nil }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "and a known id", vcr: {cassette_name: 'se/save-create-known-id'} do
|
172
|
+
let(:se) do
|
173
|
+
Rsbe::Client::Se.new(id: 'd72359c1-ecfd-4dbf-843c-bf1ec5f4f454',
|
174
|
+
coll_id: 'ea85c776-a79b-4603-b307-d6760a400281',
|
175
|
+
digi_id: 'AA-MX-0143',
|
176
|
+
do_type: 'map',
|
177
|
+
phase: 'upload',
|
178
|
+
step: 'upload',
|
179
|
+
status: 'done',
|
180
|
+
label: 'label',
|
181
|
+
notes: 'notes')
|
182
|
+
end
|
183
|
+
subject { se }
|
184
|
+
its(:save) { should eq true }
|
185
|
+
|
186
|
+
context "after save" do
|
187
|
+
before { se.save }
|
188
|
+
its(:id) { should eq 'd72359c1-ecfd-4dbf-843c-bf1ec5f4f454' }
|
189
|
+
its(:coll_id) { should eq 'ea85c776-a79b-4603-b307-d6760a400281' }
|
190
|
+
its(:digi_id) { should eq 'AA-MX-0143' }
|
191
|
+
its(:do_type) { should eq 'map' }
|
192
|
+
its(:phase) { should eq 'upload' }
|
193
|
+
its(:step) { should eq 'upload' }
|
194
|
+
its(:status) { should eq 'done' }
|
195
|
+
its(:label) { should eq 'label' }
|
196
|
+
its(:notes) { should eq 'notes' }
|
197
|
+
its(:created_at) { should_not be_nil }
|
198
|
+
its(:updated_at) { should_not be_nil }
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
context "with invalid attributes", vcr: {cassette_name: 'se/save-invalid'} do
|
203
|
+
let(:se) do
|
204
|
+
Rsbe::Client::Se.new(coll_id: 'ea85c776-a79b-4603-b307-d6760a400281',
|
205
|
+
phase: 'new moon')
|
206
|
+
end
|
207
|
+
subject { se }
|
208
|
+
its(:save) { should eq false }
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "when updating a Se" do
|
213
|
+
context "with valid attributes", vcr: {cassette_name: 'se/save-update-valid'} do
|
214
|
+
let(:se) { Rsbe::Client::Se.find('acf51ef2-8bf3-4f05-9042-0bfcb6860560') }
|
215
|
+
subject { se }
|
216
|
+
context "before save-as-update" do
|
217
|
+
its(:id) { should eq 'acf51ef2-8bf3-4f05-9042-0bfcb6860560' }
|
218
|
+
its(:phase) { should eq 'digitization' }
|
219
|
+
its(:step) { should eq 'qc' }
|
220
|
+
its(:created_at) { should_not be_nil }
|
221
|
+
its(:updated_at) { should_not be_nil }
|
222
|
+
end
|
223
|
+
context "on save-as-update" do
|
224
|
+
before do
|
225
|
+
se.phase = 'upload'
|
226
|
+
se.step = 'packaging'
|
227
|
+
end
|
228
|
+
its(:save) { should eq true }
|
229
|
+
context "after save" do
|
230
|
+
its(:id) { should eq 'acf51ef2-8bf3-4f05-9042-0bfcb6860560' }
|
231
|
+
its(:phase) { should eq 'upload' }
|
232
|
+
its(:step) { should eq 'packaging' }
|
233
|
+
its(:created_at) { should_not be_nil }
|
234
|
+
its(:updated_at) { should_not be_nil }
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
describe "lazy evaluation" do
|
241
|
+
context "when Se exists, but is populated with minimal attributes", vcr: {cassette_name: 'se/lazy-eval-exists'} do
|
242
|
+
let(:se) { Rsbe::Client::Se.new(id: 'c415b683-0823-4da0-b108-d729957705c5') }
|
243
|
+
it "should return values for all attributes" do
|
244
|
+
expect(se.coll_id).to eq 'ea85c776-a79b-4603-b307-d6760a400281'
|
245
|
+
expect(se.digi_id).to eq 'chk_this_out'
|
246
|
+
expect(se.do_type).to eq 'map'
|
247
|
+
expect(se.phase).to eq 'upload'
|
248
|
+
expect(se.step).to eq 'upload'
|
249
|
+
expect(se.status).to eq 'done'
|
250
|
+
expect(se.lock_version).not_to be_nil
|
251
|
+
expect(se.created_at).not_to be_nil
|
252
|
+
expect(se.updated_at).not_to be_nil
|
253
|
+
end
|
254
|
+
end
|
255
|
+
context "when Se does not exist in RSBE and does not have an id" do
|
256
|
+
let(:se) { Rsbe::Client::Se.new }
|
257
|
+
it "should return nil for all attributes" do
|
258
|
+
expect(se.id).to be_nil
|
259
|
+
expect(se.coll_id).to be_nil
|
260
|
+
expect(se.digi_id).to be_nil
|
261
|
+
expect(se.do_type).to be_nil
|
262
|
+
expect(se.phase).to be_nil
|
263
|
+
expect(se.step).to be_nil
|
264
|
+
expect(se.status).to be_nil
|
265
|
+
expect(se.label).to be_nil
|
266
|
+
expect(se.notes).to be_nil
|
267
|
+
expect(se.lock_version).to be_nil
|
268
|
+
expect(se.created_at).to be_nil
|
269
|
+
expect(se.updated_at).to be_nil
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
describe Rsbe::Client::SearchResults do
|
2
|
+
context "when searching by digi_id", vcr: {cassette_name: 'search_results/search-by-digi_id'} do
|
3
|
+
let(:search_params) {
|
4
|
+
{
|
5
|
+
params: {
|
6
|
+
digi_id: 'foo_quux_cuid370'
|
7
|
+
},
|
8
|
+
required_params: [],
|
9
|
+
scope: "ses"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
let(:response) { Rsbe::Client::Search.search(search_params) }
|
13
|
+
let(:sut) { Rsbe::Client::SearchResults.new(response) }
|
14
|
+
|
15
|
+
describe '.new' do
|
16
|
+
it 'should return the correct class' do
|
17
|
+
expect(sut.class).to eq(Rsbe::Client::SearchResults)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#success?' do
|
22
|
+
it 'should return true' do
|
23
|
+
expect(sut.success?).to eq(true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#num_found' do
|
28
|
+
it 'should return the correct number found' do
|
29
|
+
expect(sut.num_found).to eq(1)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#results' do
|
34
|
+
it 'should return the correct number of results' do
|
35
|
+
expect(sut.results.length).to eq(1)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return the correct object type' do
|
39
|
+
expect(sut.results.first.class).to eq(Rsbe::Client::Se)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return the object with the expected id' do
|
43
|
+
expect(sut.results.first.id).to eq('f903ee1f-83e3-4ba2-8234-0d0b85793705')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return the object with the expected digi_id' do
|
47
|
+
expect(sut.results.first.digi_id).to eq('foo_quux_cuid370')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'PRIVATE METHOD: #docs' do
|
52
|
+
it 'should return the correct count' do
|
53
|
+
expect(sut.send(:docs).size).to eq(1)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'PRIVATE METHOD: #urls' do
|
58
|
+
it 'should return the correct URL' do
|
59
|
+
expected = "http://localhost:3000/api/v0/ses/f903ee1f-83e3-4ba2-8234-0d0b85793705"
|
60
|
+
expect(sut.send(:urls)[0]).to eq(expected)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when searching by step", vcr: {cassette_name: 'search_results/search-by-step'} do
|
66
|
+
let(:search_params) {
|
67
|
+
{
|
68
|
+
params: {
|
69
|
+
step: 'qc'
|
70
|
+
},
|
71
|
+
required_params: [],
|
72
|
+
scope: "ses"
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
let(:response) { Rsbe::Client::Search.search(search_params) }
|
77
|
+
let(:sut) { Rsbe::Client::SearchResults.new(response) }
|
78
|
+
|
79
|
+
it 'should return the number found' do
|
80
|
+
expect(sut.num_found).to eq(3)
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#results' do
|
84
|
+
it 'should return the correct number of results' do
|
85
|
+
expect(sut.results.length).to eq(3)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should return the correct object type' do
|
89
|
+
expect(sut.results[0].class).to eq(Rsbe::Client::Se)
|
90
|
+
expect(sut.results[1].class).to eq(Rsbe::Client::Se)
|
91
|
+
expect(sut.results[2].class).to eq(Rsbe::Client::Se)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should return the objects with the expected ids' do
|
95
|
+
expect(sut.results[0].id).to eq('80354e46-1f07-47bf-9093-035000b85b7c')
|
96
|
+
expect(sut.results[1].id).to eq('6549aeb6-05e9-48a9-91dd-266afd4d53ed')
|
97
|
+
expect(sut.results[2].id).to eq('68472925-c271-4643-b90a-ee2da34e8c69')
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should return the object with the expected step' do
|
101
|
+
expect(sut.results[0].step).to eq('qc')
|
102
|
+
expect(sut.results[1].step).to eq('qc')
|
103
|
+
expect(sut.results[2].step).to eq('qc')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when searching for a non-existent item", vcr: {cassette_name: 'search_results/no-results'} do
|
109
|
+
let(:search_params) {
|
110
|
+
{
|
111
|
+
params: {
|
112
|
+
digi_id: '3d842f97-25d3-4118-85c4-b6b973a43524'
|
113
|
+
},
|
114
|
+
required_params: [],
|
115
|
+
scope: "ses"
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
let(:response) { Rsbe::Client::Search.search(search_params) }
|
120
|
+
let(:sut) { Rsbe::Client::SearchResults.new(response) }
|
121
|
+
|
122
|
+
it 'should return the correct number found' do
|
123
|
+
expect(sut.num_found).to eq(0)
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#results' do
|
127
|
+
it 'should be successful' do
|
128
|
+
expect(sut.success?).to eq(true)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should return the number of results' do
|
132
|
+
expect(sut.results.length).to eq(0)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should return the correct object type' do
|
136
|
+
expect(sut.results.class).to eq(Array)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
describe Rsbe::Client::Search do
|
2
|
+
describe ".search" do
|
3
|
+
def se_valid_params
|
4
|
+
{ :params =>
|
5
|
+
{ :coll_id => "ea85c776-a79b-4603-b307-d6760a400281",
|
6
|
+
:digi_id=>"foo_quux_cuid370"
|
7
|
+
},
|
8
|
+
:required_params => [:coll_id, :digi_id],
|
9
|
+
:scope=>"ses"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def chk_header(scope, incoming_params)
|
14
|
+
exist = []
|
15
|
+
incoming_params.each_key { |k|
|
16
|
+
s = k.to_sym
|
17
|
+
chk_key = k == "scope" ? se_valid_params :
|
18
|
+
se_valid_params[:params]
|
19
|
+
if chk_key.has_key?(s) && chk_key[s] == incoming_params[k]
|
20
|
+
exist << true
|
21
|
+
else
|
22
|
+
exist << false
|
23
|
+
end
|
24
|
+
}
|
25
|
+
exist
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "se params" do
|
29
|
+
context "with valid params", vcr: {cassette_name: 'search/search-with-existing-se'} do
|
30
|
+
let(:valid_params) { se_valid_params }
|
31
|
+
let(:rsp) { Rsbe::Client::Search.search(se_valid_params) }
|
32
|
+
let(:header) { JSON.parse(rsp.body)['responseHeader'] }
|
33
|
+
let(:results) { JSON.parse(rsp.body)['response'] }
|
34
|
+
it "should have a response status of 200" do
|
35
|
+
expect(rsp.status).to eq(200)
|
36
|
+
end
|
37
|
+
it "should have numFound of 1" do
|
38
|
+
expect(results['numFound']).to eq(1)
|
39
|
+
end
|
40
|
+
it "should have docs array of 1" do
|
41
|
+
expect(results['docs'].size).to eq(1)
|
42
|
+
end
|
43
|
+
it "should have a url of a certain value" do
|
44
|
+
expect(results['docs'][0]['url']).to eq("http://localhost:3000/api/v0/ses/f903ee1f-83e3-4ba2-8234-0d0b85793705")
|
45
|
+
end
|
46
|
+
it "should respond with a valid params in the responseHeader" do
|
47
|
+
valid_header_params = chk_header(valid_params[:scope],header["params"])
|
48
|
+
expect(valid_header_params).not_to include(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context "with invalid params" do
|
52
|
+
it "raises an error if params are empty" do
|
53
|
+
expect{ Rsbe::Client::Search.search }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
it "raises an error if a string param is sent" do
|
56
|
+
expect{ Rsbe::Client::Search.search("foo") }.to raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
it "raises an error if param with incorrect keys is sent" do
|
59
|
+
expect{ Rsbe::Client::Search.search({foo: "foo"}) }.to raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
it "raises an error if param with valid but string keys are sent" do
|
62
|
+
string_hsh = { "params" => "params", "required_params" => %w(foo bar), "scope" => "scope"}
|
63
|
+
expect{ Rsbe::Client::Search.search(string_hsh) }.to raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
it "raises an error if params has differing keys from the required params array" do
|
66
|
+
bad_keys = {:params=>{:collection_id=>"ea85c776-a79b-4603-b307-d6760a400281", :digi_id=>"AD-MT-0123"},
|
67
|
+
:required_params=>[:coll_id, :digi_id],
|
68
|
+
:scope=>"ses"}
|
69
|
+
expect{ Rsbe::Client::Search.search(bad_keys) }.to raise_error(ArgumentError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|