gds-api-adapters 34.0.0 → 34.1.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 +4 -4
- data/README.md +1 -1
- data/lib/gds_api/rummager.rb +12 -1
- data/lib/gds_api/test_helpers/rummager.rb +5 -5
- data/lib/gds_api/version.rb +1 -1
- data/test/publishing_api_v2_test.rb +110 -71
- data/test/rummager_test.rb +69 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43d2b87fd0e5761a6e0f58ba5cf043625d32ba1f
|
4
|
+
data.tar.gz: 2806a9f5c8d029e6f1de2dd040f6b2f437b68333
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a44f33186db19f7f1c30b11d1e9fb6bd1cf9bbd31dbe3209150c8b67650c6b681df303bec317775fb127b4b3690a6686a9b90748ebcdc91d65e3518d4dfcd37
|
7
|
+
data.tar.gz: 6289d4f548c633be92764965903deb86955921c971e29f9dc45e87f755090cf9978b2ec7ad9eecf1ca50a200ba18dde19940489259e576962a8f20291fc6574f
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Example usage:
|
|
7
7
|
```ruby
|
8
8
|
require 'gds_api/rummager'
|
9
9
|
rummager = GdsApi::Rummager.new(Plek.new.find('rummager'))
|
10
|
-
results = rummager.
|
10
|
+
results = rummager.search(q: "taxes")
|
11
11
|
```
|
12
12
|
|
13
13
|
Example adapters for frequently used applications:
|
data/lib/gds_api/rummager.rb
CHANGED
@@ -6,6 +6,7 @@ module GdsApi
|
|
6
6
|
|
7
7
|
# Perform a search.
|
8
8
|
#
|
9
|
+
# @deprecated Alias for `#search`.
|
9
10
|
# @param query [Hash] A valid search query. See Rummager documentation for options.
|
10
11
|
#
|
11
12
|
# @see https://github.com/alphagov/rummager/blob/master/docs/unified-search-api.md
|
@@ -14,9 +15,19 @@ module GdsApi
|
|
14
15
|
get_json!(request_url)
|
15
16
|
end
|
16
17
|
|
18
|
+
# Perform a search.
|
19
|
+
#
|
20
|
+
# @param query [Hash] A valid search query. See Rummager documentation for options.
|
21
|
+
#
|
22
|
+
# @see https://github.com/alphagov/rummager/blob/master/docs/unified-search-api.md
|
23
|
+
def search(args)
|
24
|
+
request_url = "#{base_url}/search.json?#{Rack::Utils.build_nested_query(args)}"
|
25
|
+
get_json!(request_url)
|
26
|
+
end
|
27
|
+
|
17
28
|
# Advanced search.
|
18
29
|
#
|
19
|
-
# @deprecated Only in use by Whitehall. Use the `
|
30
|
+
# @deprecated Only in use by Whitehall. Use the `#search` method.
|
20
31
|
def advanced_search(args)
|
21
32
|
raise ArgumentError.new("Args cannot be blank") if args.nil? || args.empty?
|
22
33
|
request_path = "#{base_url}/advanced_search?#{Rack::Utils.build_nested_query(args)}"
|
@@ -94,27 +94,27 @@ module GdsApi
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def rummager_has_no_policies_for_any_type
|
97
|
-
stub_request(:get, %r{/
|
97
|
+
stub_request(:get, %r{/search.json})
|
98
98
|
.to_return(body: no_search_results_found)
|
99
99
|
end
|
100
100
|
|
101
101
|
def rummager_has_policies_for_every_type(options = {})
|
102
102
|
if count = options[:count]
|
103
|
-
stub_request(:get, %r{/
|
103
|
+
stub_request(:get, %r{/search.json.*count=#{count}.*})
|
104
104
|
.to_return(body: first_n_results(new_policies_results, n: count))
|
105
105
|
else
|
106
|
-
stub_request(:get, %r{/
|
106
|
+
stub_request(:get, %r{/search.json})
|
107
107
|
.to_return(body: new_policies_results)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
111
|
private
|
112
112
|
def stub_request_for(result_set)
|
113
|
-
stub_request(:get, /example.com\/
|
113
|
+
stub_request(:get, /example.com\/search/).to_return(body: result_set)
|
114
114
|
end
|
115
115
|
|
116
116
|
def run_example_query
|
117
|
-
client.
|
117
|
+
client.search(example_query)
|
118
118
|
end
|
119
119
|
|
120
120
|
def search_results_found
|
data/lib/gds_api/version.rb
CHANGED
@@ -26,8 +26,12 @@ describe GdsApi::PublishingApiV2 do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
before do
|
29
|
+
@bearer_token = "example-bearer-token"
|
29
30
|
@base_api_url = Plek.current.find("publishing-api")
|
30
|
-
@api_client = GdsApi::PublishingApiV2.new(
|
31
|
+
@api_client = GdsApi::PublishingApiV2.new(
|
32
|
+
"http://localhost:3093",
|
33
|
+
bearer_token: @bearer_token,
|
34
|
+
)
|
31
35
|
|
32
36
|
@content_id = "bed722e6-db68-43e5-9079-063f623335a7"
|
33
37
|
end
|
@@ -44,9 +48,9 @@ describe GdsApi::PublishingApiV2 do
|
|
44
48
|
method: :put,
|
45
49
|
path: "/v2/content/#{@content_id}",
|
46
50
|
body: @content_item,
|
47
|
-
headers:
|
48
|
-
"
|
49
|
-
|
51
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
52
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
53
|
+
),
|
50
54
|
)
|
51
55
|
.will_respond_with(
|
52
56
|
status: 200,
|
@@ -70,9 +74,9 @@ describe GdsApi::PublishingApiV2 do
|
|
70
74
|
method: :put,
|
71
75
|
path: "/v2/content/#{@content_id}",
|
72
76
|
body: @content_item,
|
73
|
-
headers:
|
74
|
-
"
|
75
|
-
|
77
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
78
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
79
|
+
),
|
76
80
|
)
|
77
81
|
.will_respond_with(
|
78
82
|
status: 422,
|
@@ -110,9 +114,9 @@ describe GdsApi::PublishingApiV2 do
|
|
110
114
|
method: :put,
|
111
115
|
path: "/v2/content/#{@content_id}",
|
112
116
|
body: @content_item,
|
113
|
-
headers:
|
114
|
-
"
|
115
|
-
|
117
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
118
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
119
|
+
),
|
116
120
|
)
|
117
121
|
.will_respond_with(
|
118
122
|
status: 422,
|
@@ -152,9 +156,9 @@ describe GdsApi::PublishingApiV2 do
|
|
152
156
|
method: :put,
|
153
157
|
path: "/v2/content/#{@content_id}",
|
154
158
|
body: @content_item,
|
155
|
-
headers:
|
156
|
-
"
|
157
|
-
|
159
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
160
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
161
|
+
),
|
158
162
|
)
|
159
163
|
.will_respond_with(
|
160
164
|
status: 200,
|
@@ -178,9 +182,9 @@ describe GdsApi::PublishingApiV2 do
|
|
178
182
|
method: :put,
|
179
183
|
path: "/v2/content/#{@content_id}",
|
180
184
|
body: @content_item,
|
181
|
-
headers:
|
182
|
-
"
|
183
|
-
|
185
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
186
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
187
|
+
),
|
184
188
|
)
|
185
189
|
.will_respond_with(
|
186
190
|
status: 409,
|
@@ -221,6 +225,9 @@ describe GdsApi::PublishingApiV2 do
|
|
221
225
|
.with(
|
222
226
|
method: :get,
|
223
227
|
path: "/v2/content/#{@content_id}",
|
228
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
229
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
230
|
+
),
|
224
231
|
)
|
225
232
|
.will_respond_with(
|
226
233
|
status: 200,
|
@@ -259,6 +266,9 @@ describe GdsApi::PublishingApiV2 do
|
|
259
266
|
method: :get,
|
260
267
|
path: "/v2/content/#{@content_id}",
|
261
268
|
query: "locale=fr",
|
269
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
270
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
271
|
+
),
|
262
272
|
)
|
263
273
|
.will_respond_with(
|
264
274
|
status: 200,
|
@@ -298,6 +308,9 @@ describe GdsApi::PublishingApiV2 do
|
|
298
308
|
method: :get,
|
299
309
|
path: "/v2/content/#{@content_id}",
|
300
310
|
query: "version=1",
|
311
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
312
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
313
|
+
),
|
301
314
|
)
|
302
315
|
.will_respond_with(
|
303
316
|
status: 200,
|
@@ -337,6 +350,9 @@ describe GdsApi::PublishingApiV2 do
|
|
337
350
|
method: :get,
|
338
351
|
path: "/v2/content/#{@content_id}",
|
339
352
|
query: "version=2",
|
353
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
354
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
355
|
+
),
|
340
356
|
)
|
341
357
|
.will_respond_with(
|
342
358
|
status: 200,
|
@@ -375,6 +391,9 @@ describe GdsApi::PublishingApiV2 do
|
|
375
391
|
.with(
|
376
392
|
method: :get,
|
377
393
|
path: "/v2/content/#{@content_id}",
|
394
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
395
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
396
|
+
),
|
378
397
|
)
|
379
398
|
.will_respond_with(
|
380
399
|
status: 200,
|
@@ -412,6 +431,9 @@ describe GdsApi::PublishingApiV2 do
|
|
412
431
|
.with(
|
413
432
|
method: :get,
|
414
433
|
path: "/v2/content/#{@content_id}",
|
434
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
435
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
436
|
+
),
|
415
437
|
)
|
416
438
|
.will_respond_with(
|
417
439
|
status: 404,
|
@@ -445,9 +467,9 @@ describe GdsApi::PublishingApiV2 do
|
|
445
467
|
body: {
|
446
468
|
update_type: "major",
|
447
469
|
},
|
448
|
-
headers:
|
449
|
-
"
|
450
|
-
|
470
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
471
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
472
|
+
),
|
451
473
|
)
|
452
474
|
.will_respond_with(
|
453
475
|
status: 200
|
@@ -471,9 +493,9 @@ describe GdsApi::PublishingApiV2 do
|
|
471
493
|
body: {
|
472
494
|
update_type: "major",
|
473
495
|
},
|
474
|
-
headers:
|
475
|
-
"
|
476
|
-
|
496
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
497
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
498
|
+
),
|
477
499
|
)
|
478
500
|
.will_respond_with(
|
479
501
|
status: 404
|
@@ -500,9 +522,9 @@ describe GdsApi::PublishingApiV2 do
|
|
500
522
|
body: {
|
501
523
|
"update_type" => ""
|
502
524
|
},
|
503
|
-
headers:
|
504
|
-
"
|
505
|
-
|
525
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
526
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
527
|
+
),
|
506
528
|
)
|
507
529
|
.will_respond_with(
|
508
530
|
status: 422,
|
@@ -539,9 +561,9 @@ describe GdsApi::PublishingApiV2 do
|
|
539
561
|
body: {
|
540
562
|
update_type: "major",
|
541
563
|
},
|
542
|
-
headers:
|
543
|
-
"
|
544
|
-
|
564
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
565
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
566
|
+
),
|
545
567
|
)
|
546
568
|
.will_respond_with(
|
547
569
|
status: 400,
|
@@ -575,9 +597,9 @@ describe GdsApi::PublishingApiV2 do
|
|
575
597
|
update_type: "major",
|
576
598
|
locale: "fr",
|
577
599
|
},
|
578
|
-
headers:
|
579
|
-
"
|
580
|
-
|
600
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
601
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
602
|
+
),
|
581
603
|
)
|
582
604
|
.will_respond_with(
|
583
605
|
status: 200,
|
@@ -603,9 +625,9 @@ describe GdsApi::PublishingApiV2 do
|
|
603
625
|
update_type: "minor",
|
604
626
|
previous_version: 3,
|
605
627
|
},
|
606
|
-
headers:
|
607
|
-
"
|
608
|
-
|
628
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
629
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
630
|
+
),
|
609
631
|
)
|
610
632
|
.will_respond_with(
|
611
633
|
status: 200,
|
@@ -630,9 +652,9 @@ describe GdsApi::PublishingApiV2 do
|
|
630
652
|
update_type: "minor",
|
631
653
|
previous_version: 2,
|
632
654
|
},
|
633
|
-
headers:
|
634
|
-
"
|
635
|
-
|
655
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
656
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
657
|
+
),
|
636
658
|
)
|
637
659
|
.will_respond_with(
|
638
660
|
status: 409,
|
@@ -674,9 +696,9 @@ describe GdsApi::PublishingApiV2 do
|
|
674
696
|
body: {
|
675
697
|
type: "gone",
|
676
698
|
},
|
677
|
-
headers:
|
678
|
-
"
|
679
|
-
|
699
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
700
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
701
|
+
),
|
680
702
|
)
|
681
703
|
.will_respond_with(
|
682
704
|
status: 200
|
@@ -700,9 +722,9 @@ describe GdsApi::PublishingApiV2 do
|
|
700
722
|
body: {
|
701
723
|
type: "gone",
|
702
724
|
},
|
703
|
-
headers:
|
704
|
-
"
|
705
|
-
|
725
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
726
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
727
|
+
),
|
706
728
|
)
|
707
729
|
.will_respond_with(
|
708
730
|
status: 404
|
@@ -729,9 +751,9 @@ describe GdsApi::PublishingApiV2 do
|
|
729
751
|
body: {
|
730
752
|
type: "not-a-valid-type",
|
731
753
|
},
|
732
|
-
headers:
|
733
|
-
"
|
734
|
-
|
754
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
755
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
756
|
+
),
|
735
757
|
)
|
736
758
|
.will_respond_with(
|
737
759
|
status: 422,
|
@@ -766,9 +788,9 @@ describe GdsApi::PublishingApiV2 do
|
|
766
788
|
body: {
|
767
789
|
type: "gone",
|
768
790
|
},
|
769
|
-
headers:
|
770
|
-
"
|
771
|
-
|
791
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
792
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
793
|
+
),
|
772
794
|
)
|
773
795
|
.will_respond_with(
|
774
796
|
status: 200
|
@@ -794,9 +816,9 @@ describe GdsApi::PublishingApiV2 do
|
|
794
816
|
type: "gone",
|
795
817
|
previous_version: 3,
|
796
818
|
},
|
797
|
-
headers:
|
798
|
-
"
|
799
|
-
|
819
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
820
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
821
|
+
),
|
800
822
|
)
|
801
823
|
.will_respond_with(
|
802
824
|
status: 200,
|
@@ -821,9 +843,9 @@ describe GdsApi::PublishingApiV2 do
|
|
821
843
|
type: "gone",
|
822
844
|
previous_version: 2,
|
823
845
|
},
|
824
|
-
headers:
|
825
|
-
"
|
826
|
-
|
846
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
847
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
848
|
+
),
|
827
849
|
)
|
828
850
|
.will_respond_with(
|
829
851
|
status: 409,
|
@@ -1121,7 +1143,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1121
1143
|
method: :get,
|
1122
1144
|
path: "/v2/linkables",
|
1123
1145
|
query: "document_type=topic",
|
1124
|
-
headers:
|
1146
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1147
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1148
|
+
),
|
1125
1149
|
)
|
1126
1150
|
.will_respond_with(
|
1127
1151
|
status: 200,
|
@@ -1148,7 +1172,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1148
1172
|
method: :get,
|
1149
1173
|
path: "/v2/content",
|
1150
1174
|
query: "content_format=topic&fields%5B%5D=title&fields%5B%5D=base_path",
|
1151
|
-
headers:
|
1175
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1176
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1177
|
+
),
|
1152
1178
|
)
|
1153
1179
|
.will_respond_with(
|
1154
1180
|
status: 200,
|
@@ -1192,7 +1218,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1192
1218
|
method: :get,
|
1193
1219
|
path: "/v2/content",
|
1194
1220
|
query: "content_format=topic&fields%5B%5D=content_id&fields%5B%5D=locale",
|
1195
|
-
headers:
|
1221
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1222
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1223
|
+
),
|
1196
1224
|
)
|
1197
1225
|
.will_respond_with(
|
1198
1226
|
status: 200,
|
@@ -1234,7 +1262,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1234
1262
|
method: :get,
|
1235
1263
|
path: "/v2/content",
|
1236
1264
|
query: "content_format=topic&fields%5B%5D=content_id&fields%5B%5D=locale&locale=fr",
|
1237
|
-
headers:
|
1265
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1266
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1267
|
+
),
|
1238
1268
|
)
|
1239
1269
|
.will_respond_with(
|
1240
1270
|
status: 200,
|
@@ -1276,7 +1306,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1276
1306
|
method: :get,
|
1277
1307
|
path: "/v2/content",
|
1278
1308
|
query: "content_format=topic&fields%5B%5D=content_id&fields%5B%5D=locale&locale=all",
|
1279
|
-
headers:
|
1309
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1310
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1311
|
+
),
|
1280
1312
|
)
|
1281
1313
|
.will_respond_with(
|
1282
1314
|
status: 200,
|
@@ -1323,7 +1355,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1323
1355
|
method: :get,
|
1324
1356
|
path: "/v2/content",
|
1325
1357
|
query: "content_format=topic&fields%5B%5D=content_id&fields%5B%5D=details",
|
1326
|
-
headers:
|
1358
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1359
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1360
|
+
),
|
1327
1361
|
)
|
1328
1362
|
.will_respond_with(
|
1329
1363
|
status: 200,
|
@@ -1368,9 +1402,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1368
1402
|
method: :post,
|
1369
1403
|
path: "/v2/content/#{@content_id}/discard-draft",
|
1370
1404
|
body: {},
|
1371
|
-
headers:
|
1372
|
-
"
|
1373
|
-
|
1405
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
1406
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1407
|
+
),
|
1374
1408
|
)
|
1375
1409
|
.will_respond_with(
|
1376
1410
|
status: 200,
|
@@ -1394,9 +1428,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1394
1428
|
body: {
|
1395
1429
|
locale: "fr",
|
1396
1430
|
},
|
1397
|
-
headers:
|
1398
|
-
"
|
1399
|
-
|
1431
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
1432
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1433
|
+
),
|
1400
1434
|
)
|
1401
1435
|
.will_respond_with(
|
1402
1436
|
status: 200,
|
@@ -1418,9 +1452,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1418
1452
|
method: :post,
|
1419
1453
|
path: "/v2/content/#{@content_id}/discard-draft",
|
1420
1454
|
body: {},
|
1421
|
-
headers:
|
1422
|
-
"
|
1423
|
-
|
1455
|
+
headers: GdsApi::JsonClient.default_request_with_json_body_headers.merge(
|
1456
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1457
|
+
),
|
1424
1458
|
)
|
1425
1459
|
.will_respond_with(
|
1426
1460
|
status: 404,
|
@@ -1446,6 +1480,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1446
1480
|
method: :get,
|
1447
1481
|
path: "/v2/linked/#{@content_id}",
|
1448
1482
|
query: "fields%5B%5D=content_id&fields%5B%5D=base_path&link_type=topic",
|
1483
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1484
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1485
|
+
),
|
1449
1486
|
)
|
1450
1487
|
.will_respond_with(
|
1451
1488
|
status: 404,
|
@@ -1497,7 +1534,9 @@ describe GdsApi::PublishingApiV2 do
|
|
1497
1534
|
method: :get,
|
1498
1535
|
path: "/v2/linked/" + @linked_content_item['content_id'],
|
1499
1536
|
query: "fields%5B%5D=content_id&fields%5B%5D=base_path&link_type=topic",
|
1500
|
-
headers:
|
1537
|
+
headers: GdsApi::JsonClient.default_request_headers.merge(
|
1538
|
+
"Authorization" => "Bearer #{@bearer_token}"
|
1539
|
+
),
|
1501
1540
|
)
|
1502
1541
|
.will_respond_with(
|
1503
1542
|
status: 200,
|
data/test/rummager_test.rb
CHANGED
@@ -5,6 +5,7 @@ describe GdsApi::Rummager do
|
|
5
5
|
before(:each) do
|
6
6
|
stub_request(:get, /example.com\/advanced_search/).to_return(body: "[]")
|
7
7
|
stub_request(:get, /example.com\/unified_search/).to_return(body: "[]")
|
8
|
+
stub_request(:get, /example.com\/search/).to_return(body: "[]")
|
8
9
|
end
|
9
10
|
|
10
11
|
# tests for #advanced_search
|
@@ -132,6 +133,74 @@ describe GdsApi::Rummager do
|
|
132
133
|
assert_requested :get, /order=-public_timestamp/
|
133
134
|
end
|
134
135
|
|
136
|
+
# tests for search
|
137
|
+
|
138
|
+
it "#search should raise an exception if the service at the search URI returns a 500" do
|
139
|
+
stub_request(:get, /example.com\/search.json/).to_return(status: [500, "Internal Server Error"])
|
140
|
+
assert_raises(GdsApi::HTTPServerError) do
|
141
|
+
GdsApi::Rummager.new("http://example.com").search(q: "query")
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it "#search should raise an exception if the service at the search URI returns a 404" do
|
146
|
+
stub_request(:get, /example.com\/search/).to_return(status: [404, "Not Found"])
|
147
|
+
assert_raises(GdsApi::HTTPNotFound) do
|
148
|
+
GdsApi::Rummager.new("http://example.com").search(q: "query")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it "#search should raise an exception if the service at the unified search URI returns a 400" do
|
153
|
+
stub_request(:get, /example.com\/search/).to_return(
|
154
|
+
status: [400, "Bad Request"],
|
155
|
+
body: %q("error":"Filtering by \"coffee\" is not allowed"),
|
156
|
+
)
|
157
|
+
assert_raises(GdsApi::HTTPClientError) do
|
158
|
+
GdsApi::Rummager.new("http://example.com").search(q: "query", filter_coffee: "tea")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it "#search should raise an exception if the service at the unified search URI returns a 422" do
|
163
|
+
stub_request(:get, /example.com\/search/).to_return(
|
164
|
+
status: [422, "Bad Request"],
|
165
|
+
body: %q("error":"Filtering by \"coffee\" is not allowed"),
|
166
|
+
)
|
167
|
+
assert_raises(GdsApi::HTTPClientError) do
|
168
|
+
GdsApi::Rummager.new("http://example.com").search(q: "query", filter_coffee: "tea")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it "#search should raise an exception if the service at the search URI times out" do
|
173
|
+
stub_request(:get, /example.com\/search/).to_timeout
|
174
|
+
assert_raises(GdsApi::TimedOutException) do
|
175
|
+
GdsApi::Rummager.new("http://example.com").search(q: "query")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it "#search should return the search deserialized from json" do
|
180
|
+
search_results = [{"title" => "document-title"}]
|
181
|
+
stub_request(:get, /example.com\/search/).to_return(body: search_results.to_json)
|
182
|
+
results = GdsApi::Rummager.new("http://example.com").search(q: "query")
|
183
|
+
assert_equal search_results, results.to_hash
|
184
|
+
end
|
185
|
+
|
186
|
+
it "#search should request the search results in JSON format" do
|
187
|
+
GdsApi::Rummager.new("http://example.com").search(q: "query")
|
188
|
+
|
189
|
+
assert_requested :get, /.*/, headers: {"Accept" => "application/json"}
|
190
|
+
end
|
191
|
+
|
192
|
+
it "#search should issue a request for all the params supplied" do
|
193
|
+
GdsApi::Rummager.new("http://example.com").search(
|
194
|
+
q: "query & stuff",
|
195
|
+
filter_topics: ["1", "2"],
|
196
|
+
order: "-public_timestamp",
|
197
|
+
)
|
198
|
+
|
199
|
+
assert_requested :get, /q=query%20%26%20stuff/
|
200
|
+
assert_requested :get, /filter_topics\[\]=1&filter_topics\[\]=2/
|
201
|
+
assert_requested :get, /order=-public_timestamp/
|
202
|
+
end
|
203
|
+
|
135
204
|
it "#delete_content removes a document" do
|
136
205
|
request = stub_request(:delete, "http://example.com/content?link=/foo/bar")
|
137
206
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 34.
|
4
|
+
version: 34.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|