qa 5.5.1 → 5.8.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.
@@ -357,7 +357,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
357
357
  context 'producing internal server error' do
358
358
  context 'when server returns 500' do
359
359
  before do
360
- stub_request(:get, 'http://id.worldcat.org/fast/530369').to_return(status: 500)
360
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml').to_return(status: 500)
361
361
  end
362
362
  it 'returns 500' do
363
363
  expect(Rails.logger).to receive(:warn).with(graph_load_failure)
@@ -369,7 +369,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
369
369
 
370
370
  context 'when data normalization error' do
371
371
  before do
372
- stub_request(:get, 'http://id.worldcat.org/fast/530369')
372
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml')
373
373
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_bad_id.nt'), headers: { 'Content-Type' => 'application/ntriples' })
374
374
  end
375
375
  it 'returns 500' do
@@ -381,7 +381,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
381
381
 
382
382
  context 'when rdf format error' do
383
383
  before do
384
- stub_request(:get, 'http://id.worldcat.org/fast/530369').to_return(status: 200)
384
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml').to_return(status: 200)
385
385
  allow(RDF::Graph).to receive(:load).and_raise(RDF::FormatError)
386
386
  end
387
387
  it 'returns 500' do
@@ -395,7 +395,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
395
395
 
396
396
  context "when error isn't specifically handled" do
397
397
  before do
398
- stub_request(:get, 'http://id.worldcat.org/fast/530369').to_return(status: 501)
398
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml').to_return(status: 501)
399
399
  end
400
400
  it 'returns 500' do
401
401
  expect(Rails.logger).to receive(:warn).with(graph_load_failure)
@@ -408,7 +408,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
408
408
 
409
409
  context 'when service unavailable' do
410
410
  before do
411
- stub_request(:get, 'http://id.worldcat.org/fast/530369').to_return(status: 503)
411
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml').to_return(status: 503)
412
412
  end
413
413
  it 'returns 503' do
414
414
  expect(Rails.logger).to receive(:warn).with(graph_load_failure)
@@ -420,7 +420,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
420
420
 
421
421
  context 'when requested term is not found at the server' do
422
422
  before do
423
- stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID').to_return(status: 404, body: '', headers: {})
423
+ stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID.rdf.xml').to_return(status: 404, body: '', headers: {})
424
424
  end
425
425
  it 'returns 404' do
426
426
  expect(Rails.logger).to receive(:warn).with(graph_load_failure)
@@ -433,7 +433,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
433
433
  context 'in OCLC_FAST authority' do
434
434
  context 'term found' do
435
435
  before do
436
- stub_request(:get, 'http://id.worldcat.org/fast/530369')
436
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml')
437
437
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
438
438
  end
439
439
  it 'succeeds and defaults to json content type' do
@@ -481,7 +481,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
481
481
  context 'when cors headers are enabled' do
482
482
  before do
483
483
  Qa.config.enable_cors_headers
484
- stub_request(:get, 'http://id.worldcat.org/fast/530369')
484
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml')
485
485
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
486
486
  end
487
487
  it 'Access-Control-Allow-Origin is *' do
@@ -493,7 +493,7 @@ describe Qa::LinkedDataTermsController, type: :controller do
493
493
  context 'when cors headers are disabled' do
494
494
  before do
495
495
  Qa.config.disable_cors_headers
496
- stub_request(:get, 'http://id.worldcat.org/fast/530369')
496
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml')
497
497
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
498
498
  end
499
499
  it 'Access-Control-Allow-Origin is not present' do
@@ -69,7 +69,7 @@ describe Qa::TermsController, type: :controller do
69
69
  end
70
70
 
71
71
  def search(_arg1, _arg2)
72
- true
72
+ []
73
73
  end
74
74
  end
75
75
  Qa::Authorities::Local.register_subauthority('two_args', 'Qa::Authorities::Local::TwoArgs')
@@ -122,6 +122,78 @@ describe Qa::TermsController, type: :controller do
122
122
  expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
123
123
  end
124
124
  end
125
+
126
+ context 'when pagination parameters are set' do
127
+ context 'and no format is specified' do
128
+ let(:params) do
129
+ {
130
+ q: "Berry", vocab: "loc", subauthority: "names",
131
+ page_limit: "5", page_offset: "6"
132
+ }
133
+ end
134
+
135
+ it "returns a subset of results as an Array<Hash>" do
136
+ # query without pagination is expected to return 20 results
137
+ get :search, params: params
138
+ expect(response).to be_successful
139
+ expect(response.content_type.split(';')).to include 'application/json'
140
+ results = JSON.parse(response.body)
141
+ expect(results.count).to eq 5
142
+ end
143
+ end
144
+
145
+ context 'and format is specified as :jsonapi' do
146
+ let(:params) do
147
+ {
148
+ q: "Berry", vocab: "loc", subauthority: "names",
149
+ page_limit: "5", page_offset: "6", format: "jsonapi"
150
+ }
151
+ end
152
+ let(:total_num_found) { "20" } # query without pagination is expected to return 20 results
153
+
154
+ it "returns a subset of results in the JSON-API format" do
155
+ get :search, params: params
156
+ expect(response).to be_successful
157
+ expect(response.content_type.split(';')).to include 'application/vnd.api+json'
158
+ json_api_response = JSON.parse(response.body)
159
+ expect(json_api_response['data'].count).to eq 5
160
+ end
161
+
162
+ it "sets meta['page'] stats" do
163
+ get :search, params: params
164
+ json_api_response = JSON.parse(response.body)
165
+ expect(json_api_response["meta"]["page"]["page_offset"]).to eq "6"
166
+ expect(json_api_response["meta"]["page"]["page_limit"]).to eq "5"
167
+ expect(json_api_response["meta"]["page"]["actual_page_size"]).to eq "5"
168
+ expect(json_api_response["meta"]["page"]["total_num_found"]).to eq total_num_found
169
+ end
170
+
171
+ it 'sets links with prev and next having values' do
172
+ get :search, params: params
173
+
174
+ base_url = request.base_url
175
+ url_path = request.path
176
+ first_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=1"
177
+ second_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=6"
178
+ third_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=11"
179
+ fourth_page = "#{base_url}#{url_path}?q=Berry&page_limit=5&page_offset=16"
180
+ last_page = fourth_page
181
+
182
+ json_api_response = JSON.parse(response.body)
183
+ expect(json_api_response['links']["self"]).to eq second_page
184
+ expect(json_api_response['links']["first"]).to eq first_page
185
+ expect(json_api_response['links']["prev"]).to eq first_page
186
+ expect(json_api_response['links']["next"]).to eq third_page
187
+ expect(json_api_response['links']["last"]).to eq last_page
188
+ end
189
+
190
+ it 'does not include errors' do
191
+ get :search, params: params
192
+ json_api_response = JSON.parse(response.body)
193
+ expect(json_api_response.key?('errors')).to eq false
194
+ end
195
+ end
196
+ end
125
197
  end
126
198
 
127
199
  context "assign_fast" do
@@ -253,4 +325,33 @@ describe Qa::TermsController, type: :controller do
253
325
  end
254
326
  end
255
327
  end
328
+
329
+ describe "#fetch" do
330
+ context "with supported authorities" do
331
+ it "returns an individual state term" do
332
+ get :fetch, params: { vocab: "local", subauthority: "authority_U", uri: "http://my.domain/terms/a2" }
333
+ expect(response).to be_successful
334
+ end
335
+
336
+ context 'when cors headers are enabled' do
337
+ before do
338
+ Qa.config.enable_cors_headers
339
+ end
340
+ it 'Access-Control-Allow-Origin is *' do
341
+ get :fetch, params: { vocab: "local", subauthority: "authority_U", uri: "http://my.domain/terms/a2" }
342
+ expect(response.headers['Access-Control-Allow-Origin']).to eq '*'
343
+ end
344
+ end
345
+
346
+ context 'when cors headers are disabled' do
347
+ before do
348
+ Qa.config.disable_cors_headers
349
+ end
350
+ it 'Access-Control-Allow-Origin is not present' do
351
+ get :fetch, params: { vocab: "local", subauthority: "authority_U", uri: "http://my.domain/terms/a2" }
352
+ expect(response.headers.key?('Access-Control-Allow-Origin')).to be false
353
+ end
354
+ end
355
+ end
356
+ end
256
357
  end
@@ -0,0 +1,13 @@
1
+ :terms:
2
+ - :id: A1
3
+ :term: Abc Term A1
4
+ :uri: http://my.domain/terms/a1
5
+ :active: true
6
+ - :id: A2
7
+ :term: Term A2
8
+ :uri: http://my.domain/terms/a2
9
+ :active: false
10
+ - :id: A3
11
+ :term: Abc Term A3
12
+ :uri: http://my.domain/terms/a3
13
+ :active: true
@@ -8,18 +8,18 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
8
8
  context 'basic parameter testing' do
9
9
  context 'with bad id' do
10
10
  before do
11
- stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID')
11
+ stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID.rdf.xml')
12
12
  .to_return(status: 404, body: '', headers: {})
13
13
  end
14
14
  it 'raises a TermNotFound exception' do
15
- expect { lod_oclc.find('FAKE_ID') }.to raise_error Qa::TermNotFound, /.*\/FAKE_ID\ Not Found - Term may not exist at LOD Authority./
15
+ expect { lod_oclc.find('FAKE_ID') }.to raise_error Qa::TermNotFound, /.*\/FAKE_ID.rdf.xml\ Not Found - Term may not exist at LOD Authority./
16
16
  end
17
17
  end
18
18
  end
19
19
 
20
20
  context 'performance stats' do
21
21
  before do
22
- stub_request(:get, 'http://id.worldcat.org/fast/530369')
22
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml')
23
23
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
24
24
  end
25
25
  context 'when set to true' do
@@ -55,7 +55,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
55
55
 
56
56
  context 'response header' do
57
57
  before do
58
- stub_request(:get, 'http://id.worldcat.org/fast/530369')
58
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml')
59
59
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
60
60
  end
61
61
  context 'when set to true' do
@@ -91,7 +91,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
91
91
  context 'in OCLC_FAST authority' do
92
92
  context 'term found' do
93
93
  let :results do
94
- stub_request(:get, 'http://id.worldcat.org/fast/530369')
94
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml')
95
95
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
96
96
  lod_oclc.find('530369')
97
97
  end
@@ -128,7 +128,7 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
128
128
 
129
129
  context "ID in graph doesn't match ID in request URI" do
130
130
  before do
131
- stub_request(:get, 'http://id.worldcat.org/fast/530369')
131
+ stub_request(:get, 'http://id.worldcat.org/fast/530369.rdf.xml')
132
132
  .to_return(status: 200, body: webmock_fixture('lod_oclc_term_bad_id.nt'), headers: { 'Content-Type' => 'application/ntriples' })
133
133
  end
134
134
 
@@ -5,6 +5,7 @@ describe Qa::Authorities::Local::FileBasedAuthority do
5
5
  let(:authority_b) { Qa::Authorities::Local.subauthority_for("authority_B") }
6
6
  let(:authority_c) { Qa::Authorities::Local.subauthority_for("authority_C") }
7
7
  let(:authority_d) { Qa::Authorities::Local.subauthority_for("authority_D") }
8
+ let(:authority_u) { Qa::Authorities::Local.subauthority_for("authority_U") }
8
9
 
9
10
  describe "#all" do
10
11
  let(:expected) do
@@ -35,6 +36,16 @@ describe Qa::Authorities::Local::FileBasedAuthority do
35
36
  expect(authority_c.all).to eq(expected)
36
37
  end
37
38
  end
39
+ context "when terms have uris" do
40
+ let(:expected) do
41
+ [{ 'id' => "A1", 'label' => "Abc Term A1", 'active' => true, 'uri' => 'http://my.domain/terms/a1' },
42
+ { 'id' => "A2", 'label' => "Term A2", 'active' => false, 'uri' => 'http://my.domain/terms/a2' },
43
+ { 'id' => "A3", 'label' => "Abc Term A3", 'active' => true, 'uri' => 'http://my.domain/terms/a3' }]
44
+ end
45
+ it "sets the id to be same as the label" do
46
+ expect(authority_u.all).to eq(expected)
47
+ end
48
+ end
38
49
  context "YAML file is malformed" do
39
50
  it "raises an error" do
40
51
  expect { authority_d.all }.to raise_error Psych::SyntaxError
@@ -33,7 +33,9 @@ describe Qa::Authorities::Local do
33
33
 
34
34
  describe "#names" do
35
35
  it "returns a list of yaml files" do
36
- expect(described_class.names).to include("authority_A", "authority_B", "authority_C", "authority_D", "states")
36
+ expect(described_class.names)
37
+ .to include("authority_A", "authority_B", "authority_C",
38
+ "authority_D", "authority_U", "states")
37
39
  end
38
40
 
39
41
  context "when the path doesn't exist" do
@@ -83,16 +83,22 @@ RSpec.describe Qa::LinkedData::AuthorityUrlService do
83
83
  let(:action_request) { 'mark twain' }
84
84
 
85
85
  it 'returns template with substitutions' do
86
- expected_url = 'http://experimental.worldcat.org/fast/search?query=oclc.personalName+all+%22mark twain%22&sortKeys=usage&maximumRecords=10'
86
+ expected_url = 'http://experimental.worldcat.org/fast/search?query=oclc.personalName+all+%22mark%20twain%22&sortKeys=usage&maximumRecords=10'
87
87
  expect(subject).to eq expected_url
88
88
  end
89
+
90
+ it 'does not mutate substitutions hash' do
91
+ before_substitutions = substitutions.clone
92
+ subject
93
+ expect(substitutions).to eq before_substitutions
94
+ end
89
95
  end
90
96
 
91
97
  context 'when no substitutions specified' do
92
98
  let(:action_request) { 'mark twain' }
93
99
 
94
100
  it 'returns template with substitutions' do
95
- expected_url = 'http://experimental.worldcat.org/fast/search?query=cql.any+all+%22mark twain%22&sortKeys=usage&maximumRecords=20'
101
+ expected_url = 'http://experimental.worldcat.org/fast/search?query=cql.any+all+%22mark%20twain%22&sortKeys=usage&maximumRecords=20'
96
102
  expect(subject).to eq expected_url
97
103
  end
98
104
  end
@@ -104,7 +110,7 @@ RSpec.describe Qa::LinkedData::AuthorityUrlService do
104
110
  let(:action_request) { 'n79021164' }
105
111
 
106
112
  it 'returns template with substitutions' do
107
- expected_url = 'http://id.worldcat.org/fast/n79021164'
113
+ expected_url = 'http://id.worldcat.org/fast/n79021164.rdf.xml'
108
114
  expect(subject).to eq expected_url
109
115
  end
110
116
  end