qa 5.7.0 → 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.
@@ -1 +1,3 @@
1
- Qa::LinkedData::AuthorityService.load_authorities
1
+ Rails.application.reloader.to_prepare do
2
+ Qa::LinkedData::AuthorityService.load_authorities
3
+ end
@@ -0,0 +1,4 @@
1
+ Mime::Type.register 'application/vnd.api+json', :jsonapi
2
+ Mime::Type.register 'application/ld+json', :jsonld
3
+ Mime::Type.register 'text/n3', :n3
4
+ Mime::Type.register 'application/n-triples', :ntriples
data/lib/qa/version.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  module Qa
2
- VERSION = "5.7.0".freeze
2
+ VERSION = "5.8.0".freeze
3
3
  end
4
+
@@ -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