gds-api-adapters 39.0.0 → 39.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/lib/gds_api/railtie.rb +5 -0
- data/lib/gds_api/test_helpers/publishing_api_v2.rb +151 -49
- data/lib/gds_api/version.rb +1 -1
- 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: f3acffcc1511f8d85e7ee52c2bb523c7d0cc9466
|
4
|
+
data.tar.gz: 70c23a71b3cd1eb1e14f0e7b398520abcb6039f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31b7e70207db38128aaa253364a9bcc29637902f34f84691f50788e6ab728ff95630a438b7740ba85335f10b17c10b9e9e0132d8d2cab6d0863e406f02407668
|
7
|
+
data.tar.gz: 6cb54eea0cec2a11f48ac03f0ce1499dc17b6065bbc56c07821ef22254a8111a7553ca8ecf51e5ab45c7ee99c947dec75a70a83105017a946448349fe4d95cc2
|
data/lib/gds_api/railtie.rb
CHANGED
@@ -16,5 +16,10 @@ module GdsApi
|
|
16
16
|
Rails.logger.info "Using middleware GdsApi::GovukHeaderSniffer to sniff for X-GOVUK-Authenticated-User header"
|
17
17
|
app.middleware.use GdsApi::GovukHeaderSniffer, 'HTTP_X_GOVUK_AUTHENTICATED_USER'
|
18
18
|
end
|
19
|
+
|
20
|
+
initializer "gds_api.initialize_govuk_content_id_sniffer" do |app|
|
21
|
+
Rails.logger.info "Using middleware GdsApi::GovukHeaderSniffer to sniff for GOVUK-Fact-Check-Id header"
|
22
|
+
app.middleware.use GdsApi::GovukHeaderSniffer, 'HTTP_GOVUK_FACT_CHECK_ID'
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
@@ -5,31 +5,46 @@ require 'json'
|
|
5
5
|
|
6
6
|
module GdsApi
|
7
7
|
module TestHelpers
|
8
|
+
# @api documented
|
8
9
|
module PublishingApiV2
|
9
10
|
include ContentItemHelpers
|
10
11
|
|
11
12
|
PUBLISHING_API_V2_ENDPOINT = Plek.current.find('publishing-api') + '/v2'
|
12
13
|
|
13
|
-
#
|
14
|
+
# Stub a PUT /v2/content/:content_id request with the given content id and request body.
|
14
15
|
# if no response_hash is given, a default response as follows is created:
|
15
16
|
# {status: 200, body: '{}', headers: {"Content-Type" => "application/json; charset=utf-8"}}
|
16
17
|
#
|
17
18
|
# if a response is given, then it will be merged with the default response.
|
18
19
|
# if the given parameter for the response body is a Hash, it will be converted to JSON.
|
19
20
|
#
|
20
|
-
#
|
21
|
+
# The following two examples are equivalent:
|
22
|
+
# @example
|
23
|
+
# stub_publishing_api_put_content(my_content_id, my_request_body, { status: 201, body: {version: 33}.to_json })
|
21
24
|
#
|
22
|
-
#
|
23
|
-
#
|
25
|
+
# @example
|
26
|
+
# stub_publishing_api_put_content(my_content_id, my_request_body, { status: 201, body: {version: 33} })
|
24
27
|
#
|
28
|
+
# @param content_id [UUID]
|
29
|
+
# @param body [String]
|
30
|
+
# @param response_hash [Hash]
|
25
31
|
def stub_publishing_api_put_content(content_id, body, response_hash = {})
|
26
32
|
stub_publishing_api_put(content_id, body, '/content', response_hash)
|
27
33
|
end
|
28
34
|
|
35
|
+
# Stub a PATCH /v2/links/:content_id request
|
36
|
+
#
|
37
|
+
# @param content_id [UUID]
|
38
|
+
# @param body [String]
|
29
39
|
def stub_publishing_api_patch_links(content_id, body)
|
30
40
|
stub_publishing_api_patch(content_id, body, '/links')
|
31
41
|
end
|
32
42
|
|
43
|
+
# Stub a POST /v2/content/:content_id/publish request
|
44
|
+
#
|
45
|
+
# @param content_id [UUID]
|
46
|
+
# @param body [String]
|
47
|
+
# @param response_hash [Hash]
|
33
48
|
def stub_publishing_api_publish(content_id, body, response_hash = {})
|
34
49
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/publish"
|
35
50
|
response = {
|
@@ -40,6 +55,11 @@ module GdsApi
|
|
40
55
|
stub_request(:post, url).with(body: body).to_return(response)
|
41
56
|
end
|
42
57
|
|
58
|
+
# Stub a POST /v2/content/:content_id/unpublish request
|
59
|
+
#
|
60
|
+
# @param content_id [UUID]
|
61
|
+
# @param params [Hash]
|
62
|
+
# @param body [String]
|
43
63
|
def stub_publishing_api_unpublish(content_id, params, response_hash = {})
|
44
64
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/unpublish"
|
45
65
|
response = {
|
@@ -50,11 +70,22 @@ module GdsApi
|
|
50
70
|
stub_request(:post, url).with(params).to_return(response)
|
51
71
|
end
|
52
72
|
|
73
|
+
# Stub a POST /v2/content/:content_id/discard-draft request
|
74
|
+
#
|
75
|
+
# @param content_id [UUID]
|
53
76
|
def stub_publishing_api_discard_draft(content_id)
|
54
77
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/discard-draft"
|
55
78
|
stub_request(:post, url).to_return(status: 200, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
56
79
|
end
|
57
80
|
|
81
|
+
# Stub requests issued when publishing a new draft.
|
82
|
+
# - PUT /v2/content/:content_id
|
83
|
+
# - POST /v2/content/:content_id/publish
|
84
|
+
# - PATCH /v2/links/:content_id
|
85
|
+
#
|
86
|
+
# @param body [String]
|
87
|
+
# @param content_id [UUID]
|
88
|
+
# @param publish_body [Hash]
|
58
89
|
def stub_publishing_api_put_content_links_and_publish(body, content_id = nil, publish_body = nil)
|
59
90
|
content_id ||= body[:content_id]
|
60
91
|
if publish_body.nil?
|
@@ -68,39 +99,55 @@ module GdsApi
|
|
68
99
|
stubs
|
69
100
|
end
|
70
101
|
|
102
|
+
# Stub any PUT /v2/content/* request
|
71
103
|
def stub_any_publishing_api_put_content
|
72
104
|
stub_request(:put, %r{\A#{PUBLISHING_API_V2_ENDPOINT}/content/})
|
73
105
|
end
|
74
106
|
|
107
|
+
# Stub any PATCH /v2/links/* request
|
75
108
|
def stub_any_publishing_api_patch_links
|
76
109
|
stub_request(:patch, %r{\A#{PUBLISHING_API_V2_ENDPOINT}/links/})
|
77
110
|
end
|
78
111
|
|
112
|
+
# Stub any POST /v2/content/*/publish request
|
79
113
|
def stub_any_publishing_api_publish
|
80
114
|
stub_request(:post, %r{\A#{PUBLISHING_API_V2_ENDPOINT}/content/.*/publish})
|
81
115
|
end
|
82
116
|
|
117
|
+
# Stub any POST /v2/content/*/unpublish request
|
83
118
|
def stub_any_publishing_api_unpublish
|
84
119
|
stub_request(:post, %r{\A#{PUBLISHING_API_V2_ENDPOINT}/content/.*/unpublish})
|
85
120
|
end
|
86
121
|
|
122
|
+
# Stub any POST /v2/content/*/discard-draft request
|
87
123
|
def stub_any_publishing_api_discard_draft
|
88
124
|
stub_request(:post, %r{\A#{PUBLISHING_API_V2_ENDPOINT}/content/.*/discard-draft})
|
89
125
|
end
|
90
126
|
|
127
|
+
# Stub any version 2 request to the publishing API
|
91
128
|
def stub_any_publishing_api_call
|
92
129
|
stub_request(:any, %r{\A#{PUBLISHING_API_V2_ENDPOINT}})
|
93
130
|
end
|
94
131
|
|
132
|
+
# Stub any version 2 request to the publishing API to return a 404 response
|
95
133
|
def stub_any_publishing_api_call_to_return_not_found
|
96
134
|
stub_request(:any, %r{\A#{PUBLISHING_API_V2_ENDPOINT}})
|
97
135
|
.to_return(status: 404, headers: { "Content-Type" => "application/json; charset=utf-8" })
|
98
136
|
end
|
99
137
|
|
138
|
+
# Stub any version 2 request to the publishing API to return a 503 response
|
100
139
|
def publishing_api_isnt_available
|
101
140
|
stub_request(:any, /#{PUBLISHING_API_V2_ENDPOINT}\/.*/).to_return(status: 503)
|
102
141
|
end
|
103
142
|
|
143
|
+
# Assert that a draft was saved and published, and links were updated.
|
144
|
+
# - PUT /v2/content/:content_id
|
145
|
+
# - POST /v2/content/:content_id/publish
|
146
|
+
# - PATCH /v2/links/:content_id
|
147
|
+
#
|
148
|
+
# @param body [String]
|
149
|
+
# @param content_id [UUID]
|
150
|
+
# @param publish_body [Hash]
|
104
151
|
def assert_publishing_api_put_content_links_and_publish(body, content_id = nil, publish_body = nil)
|
105
152
|
content_id ||= body[:content_id]
|
106
153
|
if publish_body.nil?
|
@@ -112,31 +159,62 @@ module GdsApi
|
|
112
159
|
assert_publishing_api_publish(content_id, publish_body)
|
113
160
|
end
|
114
161
|
|
162
|
+
# Assert that content was saved (PUT /v2/content/:content_id)
|
163
|
+
#
|
164
|
+
# @param content_id [UUID]
|
165
|
+
# @param attributes_or_matcher [Object]
|
166
|
+
# @param times [Integer]
|
115
167
|
def assert_publishing_api_put_content(content_id, attributes_or_matcher = nil, times = 1)
|
116
168
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
|
117
169
|
assert_publishing_api(:put, url, attributes_or_matcher, times)
|
118
170
|
end
|
119
171
|
|
172
|
+
# Assert that content was published (POST /v2/content/:content_id/publish)
|
173
|
+
#
|
174
|
+
# @param content_id [UUID]
|
175
|
+
# @param attributes_or_matcher [Object]
|
176
|
+
# @param times [Integer]
|
120
177
|
def assert_publishing_api_publish(content_id, attributes_or_matcher = nil, times = 1)
|
121
178
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/publish"
|
122
179
|
assert_publishing_api(:post, url, attributes_or_matcher, times)
|
123
180
|
end
|
124
181
|
|
182
|
+
# Assert that content was unpublished (POST /v2/content/:content_id/unpublish)
|
183
|
+
#
|
184
|
+
# @param content_id [UUID]
|
185
|
+
# @param attributes_or_matcher [Object]
|
186
|
+
# @param times [Integer]
|
125
187
|
def assert_publishing_api_unpublish(content_id, attributes_or_matcher = nil, times = 1)
|
126
188
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/unpublish"
|
127
189
|
assert_publishing_api(:post, url, attributes_or_matcher, times)
|
128
190
|
end
|
129
191
|
|
192
|
+
# Assert that links were updated (PATCH /v2/links/:content_id)
|
193
|
+
#
|
194
|
+
# @param content_id [UUID]
|
195
|
+
# @param attributes_or_matcher [Object]
|
196
|
+
# @param times [Integer]
|
130
197
|
def assert_publishing_api_patch_links(content_id, attributes_or_matcher = nil, times = 1)
|
131
198
|
url = PUBLISHING_API_V2_ENDPOINT + "/links/" + content_id
|
132
199
|
assert_publishing_api(:patch, url, attributes_or_matcher, times)
|
133
200
|
end
|
134
201
|
|
202
|
+
# Assert that a draft was discarded (POST /v2/content/:content_id/discard-draft)
|
203
|
+
#
|
204
|
+
# @param content_id [UUID]
|
205
|
+
# @param attributes_or_matcher [Object]
|
206
|
+
# @param times [Integer]
|
135
207
|
def assert_publishing_api_discard_draft(content_id, attributes_or_matcher = nil, times = 1)
|
136
208
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/#{content_id}/discard-draft"
|
137
209
|
assert_publishing_api(:post, url, attributes_or_matcher, times)
|
138
210
|
end
|
139
211
|
|
212
|
+
# Assert that a request was made to the publishing API
|
213
|
+
#
|
214
|
+
# @param verb [String]
|
215
|
+
# @param url [String]
|
216
|
+
# @param attributes_or_matcher [Object]
|
217
|
+
# @param times [Integer]
|
140
218
|
def assert_publishing_api(verb, url, attributes_or_matcher = nil, times = 1)
|
141
219
|
if attributes_or_matcher.is_a?(Hash)
|
142
220
|
matcher = request_json_matches(attributes_or_matcher)
|
@@ -151,6 +229,7 @@ module GdsApi
|
|
151
229
|
end
|
152
230
|
end
|
153
231
|
|
232
|
+
# Get a request matcher that checks if a JSON request includes a set of attributes
|
154
233
|
def request_json_includes(required_attributes)
|
155
234
|
->(request) do
|
156
235
|
data = JSON.parse(request.body)
|
@@ -159,6 +238,7 @@ module GdsApi
|
|
159
238
|
end
|
160
239
|
end
|
161
240
|
|
241
|
+
# Get a request matcher that checks if a JSON request matches a hash
|
162
242
|
def request_json_matches(required_attributes)
|
163
243
|
->(request) do
|
164
244
|
data = JSON.parse(request.body)
|
@@ -166,15 +246,19 @@ module GdsApi
|
|
166
246
|
end
|
167
247
|
end
|
168
248
|
|
169
|
-
#
|
170
|
-
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
249
|
+
# Stub GET /v2/content/ to return a set of content items
|
250
|
+
#
|
251
|
+
# @example
|
252
|
+
#
|
253
|
+
# publishing_api_has_content(
|
254
|
+
# vehicle_recalls_and_faults, # this is a variable containing an array of content items
|
255
|
+
# document_type: described_class.publishing_api_document_type, #example of a document_type: "vehicle_recalls_and_faults_alert"
|
256
|
+
# fields: fields, #example: let(:fields) { %i[base_path content_id public_updated_at title publication_state] }
|
257
|
+
# page: 1,
|
258
|
+
# per_page: 50
|
259
|
+
# )
|
260
|
+
# @param items [Array]
|
261
|
+
# @param params [Hash]
|
178
262
|
def publishing_api_has_content(items, params = {})
|
179
263
|
url = PUBLISHING_API_V2_ENDPOINT + "/content"
|
180
264
|
|
@@ -224,17 +308,26 @@ module GdsApi
|
|
224
308
|
stub_request(:get, url).to_return(status: 200, body: { results: body }.to_json, headers: {})
|
225
309
|
end
|
226
310
|
|
311
|
+
# Stub GET /v2/linkables to return a set of content items with a specific document type
|
312
|
+
#
|
313
|
+
# @param linkables [Array]
|
227
314
|
def publishing_api_has_linkables(linkables, document_type:)
|
228
315
|
url = PUBLISHING_API_V2_ENDPOINT + "/linkables?document_type=#{document_type}"
|
229
316
|
stub_request(:get, url).to_return(status: 200, body: linkables.to_json, headers: {})
|
230
317
|
end
|
231
318
|
|
319
|
+
# Stub GET /v2/content/:content_id to return a specific content item hash
|
320
|
+
#
|
321
|
+
# @param item [Hash]
|
232
322
|
def publishing_api_has_item(item)
|
233
323
|
item = item.with_indifferent_access
|
234
324
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + item[:content_id]
|
235
325
|
stub_request(:get, url).to_return(status: 200, body: item.to_json, headers: {})
|
236
326
|
end
|
237
327
|
|
328
|
+
# Stub GET /v2/content/:content_id to progress through a series of responses.
|
329
|
+
#
|
330
|
+
# @param items [Array]
|
238
331
|
def publishing_api_has_item_in_sequence(content_id, items)
|
239
332
|
items = items.map(&:with_indifferent_access)
|
240
333
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
|
@@ -248,12 +341,15 @@ module GdsApi
|
|
248
341
|
end
|
249
342
|
end
|
250
343
|
|
344
|
+
# Stub GET /v2/content/:content_id to return a 404 response
|
345
|
+
#
|
346
|
+
# @param content_id [UUID]
|
251
347
|
def publishing_api_does_not_have_item(content_id)
|
252
348
|
url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
|
253
349
|
stub_request(:get, url).to_return(status: 404, body: resource_not_found(content_id, "content item").to_json, headers: {})
|
254
350
|
end
|
255
351
|
|
256
|
-
#
|
352
|
+
# Stub a request to links endpoint
|
257
353
|
#
|
258
354
|
# @param [Hash] links the structure of the links hash
|
259
355
|
#
|
@@ -271,23 +367,25 @@ module GdsApi
|
|
271
367
|
# }
|
272
368
|
# )
|
273
369
|
#
|
274
|
-
#
|
275
|
-
#
|
276
|
-
#
|
277
|
-
#
|
278
|
-
# "
|
279
|
-
# "
|
280
|
-
#
|
281
|
-
#
|
282
|
-
#
|
283
|
-
#
|
370
|
+
# @example
|
371
|
+
#
|
372
|
+
# Services.publishing_api.get_links("64aadc14-9bca-40d9-abb6-4f21f9792a05")
|
373
|
+
# => {
|
374
|
+
# "content_id" => "64aadc14-9bca-40d9-abb6-4f21f9792a05",
|
375
|
+
# "links" => {
|
376
|
+
# "mainstream_browse_pages" => ["df2e7a3e-2078-45de-a75a-fd37d027427e"],
|
377
|
+
# "parent" => ["df2e7a3e-2078-45de-a75a-fd37d027427e"],
|
378
|
+
# "organisations" => ["569a9ee5-c195-4b7f-b9dc-edc17a09113f", "5c54ae52-341b-499e-a6dd-67f04633b8cf"]
|
379
|
+
# },
|
380
|
+
# "version" => 6
|
381
|
+
# }
|
284
382
|
def publishing_api_has_links(links)
|
285
383
|
links = links.with_indifferent_access
|
286
384
|
url = PUBLISHING_API_V2_ENDPOINT + "/links/" + links[:content_id]
|
287
385
|
stub_request(:get, url).to_return(status: 200, body: links.to_json, headers: {})
|
288
386
|
end
|
289
387
|
|
290
|
-
#
|
388
|
+
# Stub a request to the expanded links endpoint
|
291
389
|
#
|
292
390
|
# @param [Hash] links the structure of the links hash
|
293
391
|
#
|
@@ -303,48 +401,52 @@ module GdsApi
|
|
303
401
|
# "document_type" => "mainstream_browse_page",
|
304
402
|
# "locale" => "en",
|
305
403
|
# "links" => {},
|
306
|
-
# ...
|
404
|
+
# # ...
|
307
405
|
# }
|
308
406
|
# ],
|
309
407
|
# "parent" => [
|
310
408
|
# {
|
311
409
|
# "content_id" => "df2e7a3e-2028-45de-a75a-fd37d027427e",
|
312
410
|
# "document_type" => "mainstream_browse_page",
|
313
|
-
# ...
|
411
|
+
# # ...
|
314
412
|
# },
|
315
413
|
# ]
|
316
414
|
# }
|
317
415
|
# }
|
318
416
|
# )
|
319
417
|
#
|
320
|
-
#
|
321
|
-
#
|
322
|
-
#
|
323
|
-
#
|
324
|
-
# "
|
325
|
-
#
|
326
|
-
#
|
327
|
-
#
|
328
|
-
#
|
329
|
-
#
|
330
|
-
#
|
331
|
-
#
|
332
|
-
#
|
333
|
-
#
|
334
|
-
#
|
335
|
-
#
|
336
|
-
#
|
337
|
-
#
|
338
|
-
#
|
339
|
-
#
|
340
|
-
#
|
418
|
+
# @example
|
419
|
+
# Services.publishing_api.expanded_links("64aadc14-9bca-40d9-abb4-4f21f9792a05")
|
420
|
+
# => {
|
421
|
+
# "content_id" => "64aadc14-9bca-40d9-abb4-4f21f9792a05",
|
422
|
+
# "expanded_links" => {
|
423
|
+
# "mainstream_browse_pages" => [
|
424
|
+
# {
|
425
|
+
# "content_id" => "df2e7a3e-2078-45de-a76a-fd37d027427a",
|
426
|
+
# "base_path" => "/a/base/path",
|
427
|
+
# "document_type" => "mainstream_browse_page",
|
428
|
+
# "locale" => "en",
|
429
|
+
# "links" => {},
|
430
|
+
# ...
|
431
|
+
# }
|
432
|
+
# ],
|
433
|
+
# "parent" => [
|
434
|
+
# {
|
435
|
+
# "content_id" => "df2e7a3e-2028-45de-a75a-fd37d027427e",
|
436
|
+
# "document_type" => "mainstream_browse_page",
|
437
|
+
# ...
|
438
|
+
# },
|
439
|
+
# ]
|
440
|
+
# }
|
341
441
|
# }
|
342
|
-
# }
|
343
442
|
def publishing_api_has_expanded_links(links)
|
344
443
|
url = PUBLISHING_API_V2_ENDPOINT + "/expanded-links/" + links[:content_id]
|
345
444
|
stub_request(:get, url).to_return(status: 200, body: links.to_json, headers: {})
|
346
445
|
end
|
347
446
|
|
447
|
+
# Stub GET /v2/links/:content_id to return a 404 response
|
448
|
+
#
|
449
|
+
# @param content_id [UUID]
|
348
450
|
def publishing_api_does_not_have_links(content_id)
|
349
451
|
url = PUBLISHING_API_V2_ENDPOINT + "/links/" + content_id
|
350
452
|
stub_request(:get, url).to_return(status: 404, body: resource_not_found(content_id, "link set").to_json, headers: {})
|
data/lib/gds_api/version.rb
CHANGED
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: 39.
|
4
|
+
version: 39.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: 2017-01-
|
11
|
+
date: 2017-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|