qa 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/controllers/qa/linked_data_terms_controller.rb +30 -9
  4. data/app/controllers/qa/terms_controller.rb +3 -2
  5. data/app/models/qa/linked_data/config/context_property_map.rb +6 -25
  6. data/app/services/qa/iri_template_service.rb +32 -24
  7. data/app/services/qa/linked_data/authority_service.rb +8 -0
  8. data/app/services/qa/linked_data/authority_url_service.rb +27 -8
  9. data/app/services/qa/linked_data/deep_sort_service.rb +3 -2
  10. data/app/services/qa/linked_data/graph_service.rb +13 -0
  11. data/app/services/qa/linked_data/language_service.rb +12 -0
  12. data/app/services/qa/linked_data/language_sort_service.rb +7 -2
  13. data/app/services/qa/linked_data/ldpath_service.rb +40 -0
  14. data/app/services/qa/linked_data/mapper/graph_ldpath_mapper_service.rb +49 -0
  15. data/app/services/qa/linked_data/mapper/graph_mapper_service.rb +3 -11
  16. data/app/services/qa/linked_data/mapper/graph_predicate_mapper_service.rb +40 -0
  17. data/app/services/qa/linked_data/mapper/search_results_mapper_service.rb +58 -11
  18. data/app/services/qa/linked_data/mapper/term_results_mapper_service.rb +80 -0
  19. data/config/authorities/linked_data/loc.json +13 -7
  20. data/config/authorities/linked_data/oclc_fast.json +13 -8
  21. data/lib/generators/qa/discogs/USAGE +10 -0
  22. data/lib/generators/qa/discogs/discogs_generator.rb +12 -0
  23. data/lib/generators/qa/discogs/templates/config/discogs-formats.yml +346 -0
  24. data/lib/generators/qa/discogs/templates/config/discogs-genres.yml +627 -0
  25. data/lib/generators/qa/install/templates/config/initializers/qa.rb +4 -0
  26. data/lib/qa.rb +6 -0
  27. data/lib/qa/authorities.rb +2 -0
  28. data/lib/qa/authorities/discogs.rb +28 -0
  29. data/lib/qa/authorities/discogs/discogs_instance_builder.rb +145 -0
  30. data/lib/qa/authorities/discogs/discogs_translation.rb +126 -0
  31. data/lib/qa/authorities/discogs/discogs_utils.rb +89 -0
  32. data/lib/qa/authorities/discogs/discogs_works_builder.rb +153 -0
  33. data/lib/qa/authorities/discogs/generic_authority.rb +151 -0
  34. data/lib/qa/authorities/discogs_subauthority.rb +9 -0
  35. data/lib/qa/authorities/linked_data/config.rb +7 -3
  36. data/lib/qa/authorities/linked_data/config/search_config.rb +99 -11
  37. data/lib/qa/authorities/linked_data/config/term_config.rb +112 -8
  38. data/lib/qa/authorities/linked_data/find_term.rb +154 -84
  39. data/lib/qa/authorities/linked_data/search_query.rb +76 -13
  40. data/lib/qa/configuration.rb +8 -0
  41. data/lib/qa/version.rb +1 -1
  42. data/spec/controllers/linked_data_terms_controller_spec.rb +151 -30
  43. data/spec/controllers/terms_controller_spec.rb +4 -0
  44. data/spec/features/linked_data/language_spec.rb +298 -0
  45. data/spec/fixtures/authorities/linked_data/lod_full_config.json +21 -5
  46. data/spec/fixtures/authorities/linked_data/lod_lang_defaults.json +4 -4
  47. data/spec/fixtures/authorities/linked_data/lod_lang_multi_defaults.json +4 -4
  48. data/spec/fixtures/authorities/linked_data/lod_lang_no_defaults.json +4 -5
  49. data/spec/fixtures/authorities/linked_data/lod_lang_param.json +4 -4
  50. data/spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json +1 -1
  51. data/spec/fixtures/discogs-find-response-json.json +1 -0
  52. data/spec/fixtures/discogs-find-response-jsonld-master.json +1 -0
  53. data/spec/fixtures/discogs-find-response-jsonld-release.json +1 -0
  54. data/spec/fixtures/discogs-id-matches-master.json +1 -0
  55. data/spec/fixtures/discogs-id-matches-release.json +1 -0
  56. data/spec/fixtures/discogs-id-not-found-master.json +1 -0
  57. data/spec/fixtures/discogs-id-not-found-release.json +1 -0
  58. data/spec/fixtures/discogs-search-response-no-auth.json +1 -0
  59. data/spec/fixtures/discogs-search-response-no-subauth.json +1 -0
  60. data/spec/fixtures/discogs-search-response-subauth.json +1 -0
  61. data/spec/fixtures/lod_lang_search_enesfrde.rdf.xml +60 -0
  62. data/spec/fixtures/lod_lang_search_sv.rdf.xml +42 -0
  63. data/spec/fixtures/lod_loc_term_found.rdf.xml +5 -0
  64. data/spec/lib/authorities/discogs/generic_authority_spec.rb +235 -0
  65. data/spec/lib/authorities/discogs_spec.rb +17 -0
  66. data/spec/lib/authorities/linked_data/config_spec.rb +68 -5
  67. data/spec/lib/authorities/linked_data/find_term_spec.rb +298 -3
  68. data/spec/lib/authorities/linked_data/generic_authority_spec.rb +46 -485
  69. data/spec/lib/authorities/linked_data/search_config_spec.rb +154 -3
  70. data/spec/lib/authorities/linked_data/search_query_spec.rb +240 -3
  71. data/spec/lib/authorities/linked_data/term_config_spec.rb +193 -5
  72. data/spec/lib/configuration_spec.rb +18 -0
  73. data/spec/models/linked_data/config/context_property_map_spec.rb +3 -31
  74. data/spec/services/iri_template_service_spec.rb +54 -12
  75. data/spec/{lib/authorities → services}/linked_data/authority_service_spec.rb +47 -0
  76. data/spec/services/linked_data/language_service_spec.rb +52 -11
  77. data/spec/services/linked_data/ldpath_service_spec.rb +61 -0
  78. data/spec/services/linked_data/mapper/graph_ldpath_mapper_service_spec.rb +118 -0
  79. data/spec/services/linked_data/mapper/graph_predicate_mapper_service_spec.rb +110 -0
  80. data/spec/services/linked_data/mapper/term_results_mapper_service_spec.rb +94 -0
  81. data/spec/spec_helper.rb +1 -1
  82. data/spec/support/matchers/include_hash.rb +5 -0
  83. data/spec/test_app_templates/lib/generators/test_app_generator.rb +4 -0
  84. metadata +73 -5
  85. data/lib/qa/authorities/linked_data/rdf_helper.rb +0 -49
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'qa/authorities/linked_data/config/term_config'
2
3
 
3
4
  describe Qa::Authorities::LinkedData::TermConfig do
4
5
  let(:full_config) { Qa::Authorities::LinkedData::Config.new(:LOD_FULL_CONFIG).term }
@@ -6,13 +7,24 @@ describe Qa::Authorities::LinkedData::TermConfig do
6
7
  let(:search_only_config) { Qa::Authorities::LinkedData::Config.new(:LOD_SEARCH_ONLY_CONFIG).term }
7
8
  let(:encoding_config) { Qa::Authorities::LinkedData::Config.new(:LOD_ENCODING_CONFIG).term }
8
9
 
10
+ let(:ldpath_results_config) do
11
+ {
12
+ id_ldpath: 'schema:identifier ::xsd:string',
13
+ label_ldpath: 'skos:prefLabel ::xsd:string',
14
+ altlabel_ldpath: 'skos:altLabel ::xsd:string',
15
+ broader_ldpath: 'skos:broader ::xsd:string',
16
+ narrower_ldpath: 'skos:narrower ::xsd:string',
17
+ sameas_ldpath: 'skos:exactMatch ::xsd:string'
18
+ }
19
+ end
20
+
9
21
  describe '#term_config' do
10
22
  let(:full_term_config) do
11
23
  {
12
24
  url: {
13
25
  :@context => 'http://www.w3.org/ns/hydra/context.jsonld',
14
26
  :@type => 'IriTemplate',
15
- template: 'http://localhost/test_default/term/{subauth}/{term_id}?{?param1}&{?param2}',
27
+ template: 'http://localhost/test_default/term/{subauth}/{term_id}?{?param1}&{?param2}&{?lang}',
16
28
  variableRepresentation: 'BasicRepresentation',
17
29
  mapping: [
18
30
  {
@@ -41,15 +53,23 @@ describe Qa::Authorities::LinkedData::TermConfig do
41
53
  property: 'hydra:freetextQuery',
42
54
  required: false,
43
55
  default: 'beta'
56
+ },
57
+ {
58
+ :@type => 'IriTemplateMapping',
59
+ variable: 'lang',
60
+ property: 'hydra:freetextQuery',
61
+ required: false,
62
+ default: 'de'
44
63
  }
45
64
  ]
46
65
  },
47
66
  qa_replacement_patterns: {
48
67
  term_id: 'term_id',
49
- subauth: 'subauth'
68
+ subauth: 'subauth',
69
+ lang: 'lang'
50
70
  },
51
71
  term_id: 'ID',
52
- language: ['en'],
72
+ language: ['es'],
53
73
  results: {
54
74
  id_predicate: 'http://purl.org/dc/terms/identifier',
55
75
  label_predicate: 'http://www.w3.org/2004/02/skos/core#prefLabel',
@@ -88,7 +108,7 @@ describe Qa::Authorities::LinkedData::TermConfig do
88
108
  {
89
109
  :@context => 'http://www.w3.org/ns/hydra/context.jsonld',
90
110
  :@type => 'IriTemplate',
91
- template: 'http://localhost/test_default/term/{subauth}/{term_id}?{?param1}&{?param2}',
111
+ template: 'http://localhost/test_default/term/{subauth}/{term_id}?{?param1}&{?param2}&{?lang}',
92
112
  variableRepresentation: 'BasicRepresentation',
93
113
  mapping: [
94
114
  {
@@ -117,6 +137,13 @@ describe Qa::Authorities::LinkedData::TermConfig do
117
137
  property: 'hydra:freetextQuery',
118
138
  required: false,
119
139
  default: 'beta'
140
+ },
141
+ {
142
+ :@type => 'IriTemplateMapping',
143
+ variable: 'lang',
144
+ property: 'hydra:freetextQuery',
145
+ required: false,
146
+ default: 'de'
120
147
  }
121
148
  ]
122
149
  }
@@ -156,7 +183,7 @@ describe Qa::Authorities::LinkedData::TermConfig do
156
183
  expect(min_config.term_language).to eq nil
157
184
  end
158
185
  it 'returns the preferred language for selecting literal values if configured for term' do
159
- expect(full_config.term_language).to eq [:en]
186
+ expect(full_config.term_language).to eq [:es]
160
187
  end
161
188
  end
162
189
 
@@ -188,6 +215,19 @@ describe Qa::Authorities::LinkedData::TermConfig do
188
215
  end
189
216
  end
190
217
 
218
+ describe '#term_results_id_ldpath' do
219
+ it 'returns nil if only search configuration is defined' do
220
+ expect(search_only_config.term_results_id_ldpath).to eq nil
221
+ end
222
+
223
+ context 'when id specified as ldpath' do
224
+ before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
225
+ it 'returns the ldpath' do
226
+ expect(full_config.term_results_id_ldpath).to eq 'schema:identifier ::xsd:string'
227
+ end
228
+ end
229
+ end
230
+
191
231
  describe '#term_results_label_predicate' do
192
232
  it 'returns nil if only search configuration is defined' do
193
233
  expect(search_only_config.term_results_label_predicate).to eq nil
@@ -197,6 +237,19 @@ describe Qa::Authorities::LinkedData::TermConfig do
197
237
  end
198
238
  end
199
239
 
240
+ describe '#term_results_label_ldpath' do
241
+ it 'returns nil if only search configuration is defined' do
242
+ expect(search_only_config.term_results_label_ldpath).to eq nil
243
+ end
244
+
245
+ context 'when label specified as ldpath' do
246
+ before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
247
+ it 'returns the ldpath' do
248
+ expect(full_config.term_results_label_ldpath).to eq 'skos:prefLabel ::xsd:string'
249
+ end
250
+ end
251
+ end
252
+
200
253
  describe '#term_results_altlabel_predicate' do
201
254
  it 'returns nil if only search configuration is defined' do
202
255
  expect(search_only_config.term_results_altlabel_predicate).to eq nil
@@ -209,6 +262,22 @@ describe Qa::Authorities::LinkedData::TermConfig do
209
262
  end
210
263
  end
211
264
 
265
+ describe '#term_results_altlabel_ldpath' do
266
+ it 'returns nil if only search configuration is defined' do
267
+ expect(search_only_config.term_results_altlabel_ldpath).to eq nil
268
+ end
269
+ it 'return nil if altlabel predicate is not defined' do
270
+ expect(min_config.term_results_altlabel_ldpath).to eq nil
271
+ end
272
+
273
+ context 'when altlabel specified as ldpath' do
274
+ before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
275
+ it 'returns the ldpath' do
276
+ expect(full_config.term_results_altlabel_ldpath).to eq 'skos:altLabel ::xsd:string'
277
+ end
278
+ end
279
+ end
280
+
212
281
  describe '#term_results_broader_predicate' do
213
282
  it 'returns nil if only search configuration is defined' do
214
283
  expect(search_only_config.term_results_broader_predicate).to eq nil
@@ -221,6 +290,22 @@ describe Qa::Authorities::LinkedData::TermConfig do
221
290
  end
222
291
  end
223
292
 
293
+ describe '#term_results_broader_ldpath' do
294
+ it 'returns nil if only search configuration is defined' do
295
+ expect(search_only_config.term_results_broader_ldpath).to eq nil
296
+ end
297
+ it 'return nil if broader predicate is not defined' do
298
+ expect(min_config.term_results_broader_ldpath).to eq nil
299
+ end
300
+
301
+ context 'when broader specified as ldpath' do
302
+ before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
303
+ it 'returns the ldpath' do
304
+ expect(full_config.term_results_broader_ldpath).to eq 'skos:broader ::xsd:string'
305
+ end
306
+ end
307
+ end
308
+
224
309
  describe '#term_results_narrower_predicate' do
225
310
  it 'returns nil if only search configuration is defined' do
226
311
  expect(search_only_config.term_results_narrower_predicate).to eq nil
@@ -233,6 +318,22 @@ describe Qa::Authorities::LinkedData::TermConfig do
233
318
  end
234
319
  end
235
320
 
321
+ describe '#term_results_narrower_ldpath' do
322
+ it 'returns nil if only search configuration is defined' do
323
+ expect(search_only_config.term_results_narrower_ldpath).to eq nil
324
+ end
325
+ it 'return nil if narrower predicate is not defined' do
326
+ expect(min_config.term_results_narrower_ldpath).to eq nil
327
+ end
328
+
329
+ context 'when narrower specified as ldpath' do
330
+ before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
331
+ it 'returns the ldpath' do
332
+ expect(full_config.term_results_narrower_ldpath).to eq 'skos:narrower ::xsd:string'
333
+ end
334
+ end
335
+ end
336
+
236
337
  describe '#term_results_sameas_predicate' do
237
338
  it 'returns nil if only search configuration is defined' do
238
339
  expect(search_only_config.term_results_sameas_predicate).to eq nil
@@ -245,6 +346,46 @@ describe Qa::Authorities::LinkedData::TermConfig do
245
346
  end
246
347
  end
247
348
 
349
+ describe '#term_results_sameas_ldpath' do
350
+ it 'returns nil if only search configuration is defined' do
351
+ expect(search_only_config.term_results_sameas_ldpath).to eq nil
352
+ end
353
+ it 'return nil if sameas predicate is not defined' do
354
+ expect(min_config.term_results_sameas_ldpath).to eq nil
355
+ end
356
+
357
+ context 'when sameas specified as ldpath' do
358
+ before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
359
+ it 'returns the ldpath' do
360
+ expect(full_config.term_results_sameas_ldpath).to eq 'skos:exactMatch ::xsd:string'
361
+ end
362
+ end
363
+ end
364
+
365
+ describe '#supports_language_parameter?' do
366
+ it 'returns false if only search configuration is defined' do
367
+ expect(search_only_config.supports_language_parameter?).to eq false
368
+ end
369
+ it 'returns false if the configuration does NOT define the lang replacement' do
370
+ expect(min_config.supports_language_parameter?).to eq false
371
+ end
372
+ it 'returns true if the configuration defines the lang replacement' do
373
+ expect(full_config.supports_language_parameter?).to eq true
374
+ end
375
+ end
376
+
377
+ describe '#supports_subauthorities?' do
378
+ it 'returns false if only search configuration is defined' do
379
+ expect(search_only_config.supports_subauthorities?).to eq false
380
+ end
381
+ it 'returns false if the configuration does NOT define the subauth replacement' do
382
+ expect(min_config.supports_subauthorities?).to eq false
383
+ end
384
+ it 'returns true if the configuration defines the subauth replacement' do
385
+ expect(full_config.supports_subauthorities?).to eq true
386
+ end
387
+ end
388
+
248
389
  describe '#term_subauthorities?' do
249
390
  it 'returns false if only search configuration is defined' do
250
391
  expect(search_only_config.term_subauthorities?).to eq false
@@ -302,4 +443,51 @@ describe Qa::Authorities::LinkedData::TermConfig do
302
443
  expect(full_config.term_subauthorities).to eq expected_hash
303
444
  end
304
445
  end
446
+
447
+ describe '#info' do
448
+ let(:term_details) do
449
+ {
450
+ "label" => "oclc_fast term (QA)",
451
+ "uri" => "urn:qa:term:oclc_fast",
452
+ "authority" => "oclc_fast",
453
+ "action" => "term",
454
+ "language" => ["en"]
455
+ }
456
+ end
457
+
458
+ let(:search_details) do
459
+ {
460
+ "label" => "oclc_fast search (QA)",
461
+ "uri" => "urn:qa:search:oclc_fast",
462
+ "authority" => "oclc_fast",
463
+ "action" => "search",
464
+ "language" => ["en"]
465
+ }
466
+ end
467
+
468
+ let(:search_details_with_subauth) do
469
+ {
470
+ "label" => "oclc_fast search topic (QA)",
471
+ "uri" => "urn:qa:search:oclc_fast:topic",
472
+ "authority" => "oclc_fast",
473
+ "subauthority" => "topic",
474
+ "action" => "search",
475
+ "language" => ["en"]
476
+ }
477
+ end
478
+
479
+ let(:details) { Qa::Authorities::LinkedData::Config.new(:OCLC_FAST).term.info }
480
+
481
+ it "returns a list with details for term without subauthorities" do
482
+ expect(details).to include_hash(term_details)
483
+ end
484
+
485
+ it "does not return a list with details for search without subauthorities" do
486
+ expect(details).not_to include_hash(search_details)
487
+ end
488
+
489
+ it "does not return a list with details for search with a subauthority" do
490
+ expect(details).not_to include_hash(search_details_with_subauth)
491
+ end
492
+ end
305
493
  end
@@ -68,4 +68,22 @@ RSpec.describe Qa::Configuration do
68
68
  end
69
69
  end
70
70
  end
71
+
72
+ describe '#limit_ldpath_to_context' do
73
+ context 'when NOT configured' do
74
+ it 'returns true' do
75
+ expect(subject.limit_ldpath_to_context?).to be true
76
+ end
77
+ end
78
+
79
+ context 'when configured' do
80
+ before do
81
+ subject.limit_ldpath_to_context = false
82
+ end
83
+
84
+ it 'returns the configured value' do
85
+ expect(subject.limit_ldpath_to_context?).to be false
86
+ end
87
+ end
88
+ end
71
89
  end
@@ -209,34 +209,6 @@ RSpec.describe Qa::LinkedData::Config::ContextPropertyMap do
209
209
  it 'returns the values selected from the graph' do
210
210
  expect(subject.values(graph, subject_uri)).to match_array coordinates
211
211
  end
212
-
213
- context 'when ldpath_program gets parse error' do
214
- let(:ldpath) { property_map[:ldpath] }
215
- let(:cause) { "undefined method `ascii_tree' for nil:NilClass" }
216
- let(:warning) { I18n.t('qa.linked_data.ldpath.parse_logger_error') }
217
- let(:log_message) { "WARNING: #{warning} (ldpath='#{ldpath}')\n cause: #{cause}" }
218
-
219
- before { allow(Ldpath::Program).to receive(:parse).with(anything).and_raise(cause) }
220
-
221
- it 'logs error and returns PARSE ERROR as the value' do
222
- expect(Rails.logger).to receive(:warn).with(log_message)
223
- expect { subject.values(graph, subject_uri) }.to raise_error StandardError, I18n.t('qa.linked_data.ldpath.parse_error')
224
- end
225
- end
226
-
227
- context 'when ldpath_evaluate gets parse error' do
228
- let(:ldpath) { property_map[:ldpath] }
229
- let(:cause) { "unknown cause" }
230
- let(:warning) { I18n.t('qa.linked_data.ldpath.evaluate_logger_error') }
231
- let(:log_message) { "WARNING: #{warning} (ldpath='#{ldpath}')\n cause: #{cause}" }
232
-
233
- before { allow(program).to receive(:evaluate).with(subject_uri, graph).and_raise(cause) }
234
-
235
- it 'logs error and returns PARSE ERROR as the value' do
236
- expect(Rails.logger).to receive(:warn).with(log_message)
237
- expect { subject.values(graph, subject_uri) }.to raise_error StandardError, I18n.t('qa.linked_data.ldpath.evaluate_error')
238
- end
239
- end
240
212
  end
241
213
 
242
214
  describe '#expand_uri?' do
@@ -271,9 +243,9 @@ RSpec.describe Qa::LinkedData::Config::ContextPropertyMap do
271
243
  allow(Ldpath::Program).to receive(:parse).with('property = madsrdf:identifiesRWO/madsrdf:birthDate/schema:label ;').and_return(basic_program)
272
244
  allow(Ldpath::Program).to receive(:parse).with('property = skos:prefLabel ::xsd:string ;').and_return(expanded_label_program)
273
245
  allow(Ldpath::Program).to receive(:parse).with('property = loc:lccn ::xsd:string ;').and_return(expanded_id_program)
274
- allow(basic_program).to receive(:evaluate).with(subject_uri, graph).and_return('property' => [expanded_uri])
275
- allow(expanded_label_program).to receive(:evaluate).with(RDF::URI.new(subject_uri), graph).and_return('property' => [expanded_label])
276
- allow(expanded_id_program).to receive(:evaluate).with(RDF::URI.new(subject_uri), graph).and_return('property' => [expanded_id])
246
+ allow(basic_program).to receive(:evaluate).with(subject_uri, context: graph, limit_to_context: true).and_return('property' => [expanded_uri])
247
+ allow(expanded_label_program).to receive(:evaluate).with(RDF::URI.new(subject_uri), context: graph, limit_to_context: true).and_return('property' => [expanded_label])
248
+ allow(expanded_id_program).to receive(:evaluate).with(RDF::URI.new(subject_uri), context: graph, limit_to_context: true).and_return('property' => [expanded_id])
277
249
  end
278
250
  it 'returns the uri, id, label for the expanded uri value' do
279
251
  expanded_values = subject.expanded_values(graph, subject_uri).first
@@ -5,7 +5,7 @@ RSpec.describe Qa::IriTemplateService do
5
5
  {
6
6
  :'@context' => 'http://www.w3.org/ns/hydra/context.jsonld',
7
7
  :'@type' => 'IriTemplate',
8
- template: 'http://localhost/test_default/search?{?subauth}&{?query}&{?max_records}&{?language}',
8
+ template: 'http://localhost/test_default/search?{?subauth}&{?query}&{?max_records}&{?lang}',
9
9
  variableRepresentation: 'BasicRepresentation',
10
10
  mapping: [
11
11
  {
@@ -18,8 +18,7 @@ RSpec.describe Qa::IriTemplateService do
18
18
  :'@type' => 'IriTemplateMapping',
19
19
  variable: 'subauth',
20
20
  property: 'hydra:freetextQuery',
21
- required: false,
22
- default: 'personal_names'
21
+ required: false
23
22
  },
24
23
  {
25
24
  :'@type' => 'IriTemplateMapping',
@@ -30,10 +29,9 @@ RSpec.describe Qa::IriTemplateService do
30
29
  },
31
30
  {
32
31
  :'@type' => 'IriTemplateMapping',
33
- variable: 'language',
32
+ variable: 'lang',
34
33
  property: 'hydra:freetextQuery',
35
- required: false,
36
- default: 'en'
34
+ required: false
37
35
  }
38
36
  ]
39
37
  }
@@ -47,22 +45,66 @@ RSpec.describe Qa::IriTemplateService do
47
45
  query: 'mark twain',
48
46
  subauth: 'corporate_names',
49
47
  max_records: 10,
50
- language: 'fr'
48
+ lang: 'fr'
51
49
  )
52
50
  end
53
51
 
54
52
  it 'returns template with substitutions' do
55
- expected_url = 'http://localhost/test_default/search?subauth=corporate_names&query=mark twain&max_records=10&language=fr'
53
+ expected_url = 'http://localhost/test_default/search?subauth=corporate_names&query=mark twain&max_records=10&lang=fr'
56
54
  expect(described_class.build_url(url_config: url_config, substitutions: substitutions)).to eq expected_url
57
55
  end
58
56
  end
59
57
 
60
58
  context 'when minimal substitutions specified' do
61
- let(:substitutions) { HashWithIndifferentAccess.new(query: 'mark twain') }
59
+ context 'and default specified for maxRecords only' do
60
+ let(:substitutions) { HashWithIndifferentAccess.new(query: 'mark twain') }
62
61
 
63
- it 'returns template with substitutions' do
64
- expected_url = 'http://localhost/test_default/search?subauth=personal_names&query=mark twain&max_records=20&language=en'
65
- expect(described_class.build_url(url_config: url_config, substitutions: substitutions)).to eq expected_url
62
+ it 'returns template with substitutions' do
63
+ expected_url = 'http://localhost/test_default/search?query=mark twain&max_records=20'
64
+ expect(described_class.build_url(url_config: url_config, substitutions: substitutions)).to eq expected_url
65
+ end
66
+ end
67
+
68
+ context 'and defaults specified for all' do
69
+ let(:substitutions) { HashWithIndifferentAccess.new(query: 'mark twain') }
70
+ let(:mapping) do
71
+ [
72
+ {
73
+ :'@type' => 'IriTemplateMapping',
74
+ variable: 'query',
75
+ property: 'hydra:freetextQuery',
76
+ required: true
77
+ },
78
+ {
79
+ :'@type' => 'IriTemplateMapping',
80
+ variable: 'subauth',
81
+ property: 'hydra:freetextQuery',
82
+ required: false,
83
+ default: 'personal_names'
84
+ },
85
+ {
86
+ :'@type' => 'IriTemplateMapping',
87
+ variable: 'max_records',
88
+ property: 'hydra:freetextQuery',
89
+ required: false,
90
+ default: 20
91
+ },
92
+ {
93
+ :'@type' => 'IriTemplateMapping',
94
+ variable: 'lang',
95
+ property: 'hydra:freetextQuery',
96
+ required: false,
97
+ default: 'en'
98
+ }
99
+ ]
100
+ end
101
+
102
+ before { url_template[:mapping] = mapping }
103
+
104
+ it 'returns template with substitutions' do
105
+ expected_url = 'http://localhost/test_default/search?subauth=personal_names&query=mark twain&max_records=20&lang=en'
106
+ expect(described_class.build_url(url_config: url_config, substitutions: substitutions)).to eq expected_url
107
+ end
66
108
  end
67
109
  end
68
110
  end