gds-api-adapters 71.3.0 → 71.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea739e39026f239c010c4810ba88c6c0f8f77a0fb2375e24c9026cd2a388465e
4
- data.tar.gz: c18db19adc96aab183ab99edfc30db4691d7ab5d055def3fbcfc406f6b16c1a8
3
+ metadata.gz: 7748e3505408224466ce191efa83ee616ae6bd602f3cec8760fedb09aaaed859
4
+ data.tar.gz: c4e7b3e9f9af207d97e5a62e776f6de9dfbea8791e20636e64740e362a8a0457
5
5
  SHA512:
6
- metadata.gz: 1b03304634769b69d8549664720619081836366bacb76948e19275751b0f4d2482f0adf14977b82569e4e265b081e590c338f9a2167e78170bab9af0f8c27a68
7
- data.tar.gz: b5dfc1690a1e783e67bf350d2d5fb8d66c9aa0eaaa758bdbb7be381cd34a76780de465c9bfc78b539c9712ba3e6b586788f7139edab07aa8fab7ea2d6ae974f9
6
+ metadata.gz: ebd5592b71e1ccea18a2578e52307227689036b8bbd35daf20c7cd0bf7eb67bd85af32fbe8a016e010bdecd1b28e37a4bdeebc3513b9d4f17a0178078828c1db
7
+ data.tar.gz: dd41b35ed23b58a7049c5b3327225781a85fa4396f278d3ef064909e453be3b898272504d82beff32c0a06c71e620956d9fa9d0984b04e1be31bd5ed40c00bb5
@@ -54,6 +54,24 @@ class GdsApi::AccountApi < GdsApi::Base
54
54
  get_json("#{endpoint}/api/user", auth_headers(govuk_account_session))
55
55
  end
56
56
 
57
+ # Update the user record with privileged information from the auth service. Only the auth service will call this.
58
+ #
59
+ # @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
60
+ # @param [String, nil] email The user's current
61
+ # @param [Boolean, nil] email_verified Whether the user's current email address is verified
62
+ # @param [Boolean, nil] has_unconfirmed_email Whether the user has a new, pending, email address
63
+ #
64
+ # @return [Hash] The user's subject identifier and email attributes
65
+ def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil)
66
+ params = {
67
+ email: email,
68
+ email_verified: email_verified,
69
+ has_unconfirmed_email: has_unconfirmed_email,
70
+ }.compact
71
+
72
+ patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
73
+ end
74
+
57
75
  # Check if a user has an email subscription for the Transition Checker
58
76
  #
59
77
  # @param [String] govuk_account_session Value of the session header
@@ -105,13 +123,42 @@ class GdsApi::AccountApi < GdsApi::Base
105
123
  get_json("#{endpoint}/api/attributes/names?#{querystring}", auth_headers(govuk_account_session))
106
124
  end
107
125
 
126
+ # Get the details of an account-linked email subscription.
127
+ #
128
+ # @param [String] name Name of the subscription
129
+ # @param [String] govuk_account_session Value of the session header
130
+ #
131
+ # @return [Hash] Details of the subscription, if it exists.
132
+ def get_email_subscription(name:, govuk_account_session:)
133
+ get_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", auth_headers(govuk_account_session))
134
+ end
135
+
136
+ # Create or update an account-linked email subscription.
137
+ #
138
+ # @param [String] name Name of the subscription
139
+ # @param [String] topic_slug The email-alert-api topic slug to subscribe to
140
+ # @param [String] govuk_account_session Value of the session header
141
+ #
142
+ # @return [Hash] Details of the newly created subscription.
143
+ def put_email_subscription(name:, topic_slug:, govuk_account_session:)
144
+ put_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", { topic_slug: topic_slug }, auth_headers(govuk_account_session))
145
+ end
146
+
147
+ # Unsubscribe and delete an account-linked email subscription.
148
+ #
149
+ # @param [String] name Name of the subscription
150
+ # @param [String] govuk_account_session Value of the session header
151
+ def delete_email_subscription(name:, govuk_account_session:)
152
+ delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session))
153
+ end
154
+
108
155
  # Look up all pages saved by a user in their Account
109
156
  #
110
157
  # @param [String] govuk_account_session Value of the session header
111
158
  #
112
- # @return [Hash] containing :saved_pages, an array of single saved page hashes def get_saved_pages(govuk_account_session:)
159
+ # @return [Hash] containing :saved_pages, an array of single saved page hashes
113
160
  def get_saved_pages(govuk_account_session:)
114
- get_json("#{endpoint}/api/saved_pages", auth_headers(govuk_account_session))
161
+ get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session))
115
162
  end
116
163
 
117
164
  # Return a single page by unique URL
@@ -121,7 +168,7 @@ class GdsApi::AccountApi < GdsApi::Base
121
168
  #
122
169
  # @return [Hash] containing :saved_page, a hash of a single saved page value
123
170
  def get_saved_page(page_path:, govuk_account_session:)
124
- get_json("#{endpoint}/api/saved_pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session))
171
+ get_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session))
125
172
  end
126
173
 
127
174
  # Upsert a single saved page entry in a users account
@@ -131,7 +178,7 @@ class GdsApi::AccountApi < GdsApi::Base
131
178
  #
132
179
  # @return [Hash] A single saved page value (if sucessful)
133
180
  def save_page(page_path:, govuk_account_session:)
134
- put_json("#{endpoint}/api/saved_pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
181
+ put_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
135
182
  end
136
183
 
137
184
  # Delete a single saved page entry from a users account
@@ -142,7 +189,7 @@ class GdsApi::AccountApi < GdsApi::Base
142
189
  # @return [GdsApi::Response] A status code of 204 indicates the saved page has been successfully deleted.
143
190
  # A status code of 404 indicates there is no saved page with this path.
144
191
  def delete_saved_page(page_path:, govuk_account_session:)
145
- delete_json("#{endpoint}/api/saved_pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
192
+ delete_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
146
193
  end
147
194
 
148
195
  private
@@ -156,10 +156,10 @@ class GdsApi::EmailAlertApi < GdsApi::Base
156
156
  # @param [string] Subscriber new_address
157
157
  #
158
158
  # @return [Hash] subscriber
159
- def change_subscriber(id:, new_address:)
159
+ def change_subscriber(id:, new_address:, on_conflict: nil)
160
160
  patch_json(
161
161
  "#{endpoint}/subscribers/#{uri_encode(id)}",
162
- new_address: new_address,
162
+ { new_address: new_address, on_conflict: on_conflict }.compact,
163
163
  )
164
164
  end
165
165
 
@@ -176,6 +176,44 @@ class GdsApi::EmailAlertApi < GdsApi::Base
176
176
  )
177
177
  end
178
178
 
179
+ # Verify a GOV.UK Account-holder has a corresponding subscriber
180
+ #
181
+ # @param [string] govuk_account_session The request's session identifier
182
+ #
183
+ # @return [Hash] subscriber
184
+ def authenticate_subscriber_by_govuk_account(govuk_account_session:)
185
+ post_json(
186
+ "#{endpoint}/subscribers/govuk-account",
187
+ govuk_account_session: govuk_account_session,
188
+ )
189
+ end
190
+
191
+ # Mark a subscriber as "linked" to its corresponding GOV.UK Account.
192
+ # In practice "linking" will mean that email-alert-frontend and
193
+ # account-api will treat the subscriber specially (eg, only allowing
194
+ # address changes via the account).
195
+ #
196
+ # @param [string] govuk_account_session The request's session identifier
197
+ #
198
+ # @return [Hash] subscriber
199
+ def link_subscriber_to_govuk_account(govuk_account_session:)
200
+ post_json(
201
+ "#{endpoint}/subscribers/govuk-account/link",
202
+ govuk_account_session: govuk_account_session,
203
+ )
204
+ end
205
+
206
+ # Find a subscriber which has been "linked" to a GOV.UK Account.
207
+ #
208
+ # @param [String] govuk_account_id An ID for the account.
209
+ #
210
+ # @return [Hash] subscriber
211
+ def find_subscriber_by_govuk_account(govuk_account_id:)
212
+ get_json(
213
+ "#{endpoint}/subscribers/govuk-account/#{govuk_account_id}",
214
+ )
215
+ end
216
+
179
217
  # Verify a subscriber has control of a provided email
180
218
  #
181
219
  # @param [string] address Address to send verification email to
@@ -5,6 +5,20 @@ module GdsApi
5
5
  module AccountApi
6
6
  ACCOUNT_API_ENDPOINT = Plek.find("account-api")
7
7
 
8
+ def stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil)
9
+ with.merge!(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session }) if govuk_account_session
10
+ new_govuk_account_session = nil if response_status >= 400
11
+ to_return = { status: response_status, body: response_body.merge(govuk_account_session: new_govuk_account_session).compact.to_json }
12
+ if with.empty?
13
+ stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").to_return(**to_return)
14
+ else
15
+ stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return)
16
+ end
17
+ end
18
+
19
+ #########################
20
+ # GET /api/oauth2/sign-in
21
+ #########################
8
22
  def stub_account_api_get_sign_in_url(redirect_path: nil, state_id: nil, level_of_authentication: nil, auth_uri: "http://auth/provider", state: "state")
9
23
  querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, state_id: state_id, level_of_authentication: level_of_authentication }.compact)
10
24
  stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/sign-in?#{querystring}")
@@ -14,6 +28,9 @@ module GdsApi
14
28
  )
15
29
  end
16
30
 
31
+ ###########################
32
+ # POST /api/oauth2/callback
33
+ ###########################
17
34
  def stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id")
18
35
  stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback")
19
36
  .with(body: hash_including({ code: code, state: state }.compact))
@@ -29,6 +46,9 @@ module GdsApi
29
46
  .to_return(status: 401)
30
47
  end
31
48
 
49
+ ########################
50
+ # POST /api/oauth2/state
51
+ ########################
32
52
  def stub_account_api_create_registration_state(attributes: nil, state_id: "state-id")
33
53
  stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/state")
34
54
  .with(body: hash_including({ attributes: attributes }.compact))
@@ -38,14 +58,19 @@ module GdsApi
38
58
  )
39
59
  end
40
60
 
41
- def stub_account_api_user_info(level_of_authentication: "level0", email: "email@example.com", email_verified: true, services: {}, **options)
61
+ ###############
62
+ # GET /api/user
63
+ ###############
64
+ def stub_account_api_user_info(id: "user-id", level_of_authentication: "level0", email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
42
65
  stub_account_api_request(
43
66
  :get,
44
67
  "/api/user",
45
68
  response_body: {
69
+ id: id,
46
70
  level_of_authentication: level_of_authentication,
47
71
  email: email,
48
72
  email_verified: email_verified,
73
+ has_unconfirmed_email: has_unconfirmed_email,
49
74
  services: services,
50
75
  },
51
76
  **options,
@@ -69,6 +94,120 @@ module GdsApi
69
94
  )
70
95
  end
71
96
 
97
+ ###########################################
98
+ # PATCH /api/oidc-users/:subject_identifier
99
+ ###########################################
100
+ def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, old_email: nil, old_email_verified: nil, old_has_unconfirmed_email: nil)
101
+ stub_account_api_request(
102
+ :patch,
103
+ "/api/oidc-users/#{subject_identifier}",
104
+ with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email }.compact) },
105
+ response_body: {
106
+ sub: subject_identifier,
107
+ email: email || old_email,
108
+ email_verified: email_verified || old_email_verified,
109
+ has_unconfirmed_email: has_unconfirmed_email || old_has_unconfirmed_email,
110
+ },
111
+ )
112
+ end
113
+
114
+ ####################################
115
+ # GET /api/email-subscriptions/:name
116
+ ####################################
117
+ def stub_account_api_get_email_subscription(name:, topic_slug: "slug", email_alert_api_subscription_id: "12345", **options)
118
+ stub_account_api_request(
119
+ :get,
120
+ "/api/email-subscriptions/#{name}",
121
+ response_body: {
122
+ email_subscription: {
123
+ name: name,
124
+ topic_slug: topic_slug,
125
+ email_alert_api_subscription_id: email_alert_api_subscription_id,
126
+ },
127
+ },
128
+ **options,
129
+ )
130
+ end
131
+
132
+ def stub_account_api_get_email_subscription_does_not_exist(name:, **options)
133
+ stub_account_api_request(
134
+ :get,
135
+ "/api/email-subscriptions/#{name}",
136
+ response_status: 404,
137
+ **options,
138
+ )
139
+ end
140
+
141
+ def stub_account_api_get_email_subscription_unauthorized(name:, **options)
142
+ stub_account_api_request(
143
+ :get,
144
+ "/api/email-subscriptions/#{name}",
145
+ response_status: 401,
146
+ **options,
147
+ )
148
+ end
149
+
150
+ ####################################
151
+ # PUT /api/email-subscriptions/:name
152
+ ####################################
153
+ def stub_account_api_put_email_subscription(name:, topic_slug: nil, **options)
154
+ stub_account_api_request(
155
+ :put,
156
+ "/api/email-subscriptions/#{name}",
157
+ with: { body: hash_including({ topic_slug: topic_slug }.compact) },
158
+ response_body: {
159
+ email_subscription: {
160
+ name: name,
161
+ topic_slug: topic_slug || "slug",
162
+ },
163
+ },
164
+ **options,
165
+ )
166
+ end
167
+
168
+ def stub_account_api_unauthorized_put_email_subscription(name:, topic_slug: nil, **options)
169
+ stub_account_api_request(
170
+ :put,
171
+ "/api/email-subscriptions/#{name}",
172
+ with: { body: hash_including({ topic_slug: topic_slug }.compact) },
173
+ response_status: 401,
174
+ **options,
175
+ )
176
+ end
177
+
178
+ #######################################
179
+ # DELETE /api/email-subscriptions/:name
180
+ #######################################
181
+ def stub_account_api_delete_email_subscription(name:, **options)
182
+ stub_account_api_request(
183
+ :delete,
184
+ "/api/email-subscriptions/#{name}",
185
+ response_status: 204,
186
+ **options,
187
+ )
188
+ end
189
+
190
+ def stub_account_api_delete_email_subscription_does_not_exist(name:, **options)
191
+ stub_account_api_request(
192
+ :delete,
193
+ "/api/email-subscriptions/#{name}",
194
+ response_status: 404,
195
+ **options,
196
+ )
197
+ end
198
+
199
+ def stub_account_api_unauthorized_delete_email_subscription(name:, **options)
200
+ stub_account_api_request(
201
+ :delete,
202
+ "/api/email-subscriptions/#{name}",
203
+ response_status: 401,
204
+ **options,
205
+ )
206
+ end
207
+
208
+ ################################################
209
+ # GET /api/transition-checker-email-subscription
210
+ ################################################
72
211
  def stub_account_api_has_email_subscription(**options)
73
212
  stub_account_api_request(
74
213
  :get,
@@ -106,6 +245,9 @@ module GdsApi
106
245
  )
107
246
  end
108
247
 
248
+ #################################################
249
+ # POST /api/transition-checker-email-subscription
250
+ #################################################
109
251
  def stub_account_api_set_email_subscription(slug: nil, **options)
110
252
  stub_account_api_request(
111
253
  :post,
@@ -136,6 +278,9 @@ module GdsApi
136
278
  )
137
279
  end
138
280
 
281
+ #####################
282
+ # GET /api/attributes
283
+ #####################
139
284
  def stub_account_api_has_attributes(attributes: [], values: {}, **options)
140
285
  querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
141
286
  stub_account_api_request(
@@ -167,6 +312,9 @@ module GdsApi
167
312
  )
168
313
  end
169
314
 
315
+ #######################
316
+ # PATCH /api/attributes
317
+ #######################
170
318
  def stub_account_api_set_attributes(attributes: nil, **options)
171
319
  stub_account_api_request(
172
320
  :patch,
@@ -197,6 +345,9 @@ module GdsApi
197
345
  )
198
346
  end
199
347
 
348
+ ###########################
349
+ # GET /api/attributes/names
350
+ ###########################
200
351
  def stub_account_api_get_attributes_names(attributes: [], **options)
201
352
  querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
202
353
  stub_account_api_request(
@@ -228,24 +379,13 @@ module GdsApi
228
379
  )
229
380
  end
230
381
 
231
- def stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil)
232
- with.merge!(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session }) if govuk_account_session
233
- new_govuk_account_session = nil if response_status >= 400
234
- to_return = { status: response_status, body: response_body.merge(govuk_account_session: new_govuk_account_session).compact.to_json }
235
- if with.empty?
236
- stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").to_return(**to_return)
237
- else
238
- stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return)
239
- end
240
- end
241
-
242
382
  ######################
243
- # GET /api/saved_pages
383
+ # GET /api/saved-pages
244
384
  ######################
245
385
  def stub_account_api_returning_saved_pages(saved_pages: [], **options)
246
386
  stub_account_api_request(
247
387
  :get,
248
- "/api/saved_pages",
388
+ "/api/saved-pages",
249
389
  response_body: { saved_pages: saved_pages },
250
390
  **options,
251
391
  )
@@ -254,7 +394,7 @@ module GdsApi
254
394
  def stub_account_api_unauthorized_get_saved_pages(**options)
255
395
  stub_account_api_request(
256
396
  :get,
257
- "/api/saved_pages",
397
+ "/api/saved-pages",
258
398
  response_status: 401,
259
399
  **options,
260
400
  )
@@ -266,7 +406,7 @@ module GdsApi
266
406
  def stub_account_api_get_saved_page(page_path:, content_id: "46163ed2-1777-4ee6-bdd4-6a2007e49d8f", title: "Ministry of Magic", **options)
267
407
  stub_account_api_request(
268
408
  :get,
269
- "/api/saved_pages/#{CGI.escape(page_path)}",
409
+ "/api/saved-pages/#{CGI.escape(page_path)}",
270
410
  response_body: {
271
411
  saved_page: {
272
412
  page_path: page_path,
@@ -281,7 +421,7 @@ module GdsApi
281
421
  def stub_account_api_does_not_have_saved_page(page_path:, **options)
282
422
  stub_account_api_request(
283
423
  :get,
284
- "/api/saved_pages/#{CGI.escape(page_path)}",
424
+ "/api/saved-pages/#{CGI.escape(page_path)}",
285
425
  response_status: 404,
286
426
  **options,
287
427
  )
@@ -290,19 +430,19 @@ module GdsApi
290
430
  def stub_account_api_unauthorized_get_saved_page(page_path:, **options)
291
431
  stub_account_api_request(
292
432
  :get,
293
- "/api/saved_pages/#{CGI.escape(page_path)}",
433
+ "/api/saved-pages/#{CGI.escape(page_path)}",
294
434
  response_status: 401,
295
435
  **options,
296
436
  )
297
437
  end
298
438
 
299
439
  #################################
300
- # PUT /api/saved_pages/:page_path
440
+ # PUT /api/saved-pages/:page_path
301
441
  #################################
302
442
  def stub_account_api_save_page(page_path:, content_id: "c840bfa2-011a-42cc-ac7a-a6da990aff0b", title: "Ministry of Magic", **options)
303
443
  stub_account_api_request(
304
444
  :put,
305
- "/api/saved_pages/#{CGI.escape(page_path)}",
445
+ "/api/saved-pages/#{CGI.escape(page_path)}",
306
446
  response_body: {
307
447
  saved_page: {
308
448
  page_path: page_path,
@@ -321,7 +461,7 @@ module GdsApi
321
461
  def stub_account_api_save_page_cannot_save_page(page_path:, **options)
322
462
  stub_account_api_request(
323
463
  :put,
324
- "/api/saved_pages/#{CGI.escape(page_path)}",
464
+ "/api/saved-pages/#{CGI.escape(page_path)}",
325
465
  response_status: 422,
326
466
  response_body: cannot_save_page_problem_detail({ page_path: page_path }),
327
467
  **options,
@@ -331,7 +471,7 @@ module GdsApi
331
471
  def stub_account_api_unauthorized_save_page(page_path:, **options)
332
472
  stub_account_api_request(
333
473
  :put,
334
- "/api/saved_pages/#{CGI.escape(page_path)}",
474
+ "/api/saved-pages/#{CGI.escape(page_path)}",
335
475
  response_status: 401,
336
476
  **options,
337
477
  )
@@ -352,7 +492,7 @@ module GdsApi
352
492
  def stub_account_api_delete_saved_page(page_path:, **options)
353
493
  stub_account_api_request(
354
494
  :delete,
355
- "/api/saved_pages/#{CGI.escape(page_path)}",
495
+ "/api/saved-pages/#{CGI.escape(page_path)}",
356
496
  response_status: 204,
357
497
  **options,
358
498
  )
@@ -361,7 +501,7 @@ module GdsApi
361
501
  def stub_account_api_delete_saved_page_does_not_exist(page_path:, **options)
362
502
  stub_account_api_request(
363
503
  :delete,
364
- "/api/saved_pages/#{CGI.escape(page_path)}",
504
+ "/api/saved-pages/#{CGI.escape(page_path)}",
365
505
  response_status: 404,
366
506
  **options,
367
507
  )
@@ -370,7 +510,7 @@ module GdsApi
370
510
  def stub_account_api_delete_saved_page_unauthorised(page_path:, **options)
371
511
  stub_account_api_request(
372
512
  :delete,
373
- "/api/saved_pages/#{CGI.escape(page_path)}",
513
+ "/api/saved-pages/#{CGI.escape(page_path)}",
374
514
  response_status: 401,
375
515
  **options,
376
516
  )
@@ -6,11 +6,11 @@ module GdsApi
6
6
  module EmailAlertApi
7
7
  EMAIL_ALERT_API_ENDPOINT = Plek.find("email-alert-api")
8
8
 
9
- def stub_email_alert_api_has_updated_subscriber(id, new_address)
9
+ def stub_email_alert_api_has_updated_subscriber(id, new_address, govuk_account_id: nil)
10
10
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}")
11
11
  .to_return(
12
12
  status: 200,
13
- body: get_subscriber_response(id, new_address).to_json,
13
+ body: get_subscriber_response(id, new_address, govuk_account_id).to_json,
14
14
  )
15
15
  end
16
16
 
@@ -265,11 +265,11 @@ module GdsApi
265
265
  ).to_return(status: 422)
266
266
  end
267
267
 
268
- def stub_email_alert_api_sends_subscriber_verification_email(subscriber_id, address)
268
+ def stub_email_alert_api_sends_subscriber_verification_email(subscriber_id, address, govuk_account_id: nil)
269
269
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
270
270
  .to_return(
271
271
  status: 201,
272
- body: get_subscriber_response(subscriber_id, address).to_json,
272
+ body: get_subscriber_response(subscriber_id, address, govuk_account_id).to_json,
273
273
  )
274
274
  end
275
275
 
@@ -283,6 +283,102 @@ module GdsApi
283
283
  .to_return(status: 404)
284
284
  end
285
285
 
286
+ def stub_email_alert_api_subscriber_verification_email_linked_to_govuk_account
287
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
288
+ .to_return(status: 403)
289
+ end
290
+
291
+ def stub_email_alert_api_authenticate_subscriber_by_govuk_account(govuk_account_session, subscriber_id, address, govuk_account_id: "user-id", new_govuk_account_session: nil)
292
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
293
+ .with(
294
+ body: { govuk_account_session: govuk_account_session }.to_json,
295
+ ).to_return(
296
+ status: 200,
297
+ body: {
298
+ govuk_account_session: new_govuk_account_session,
299
+ }.compact.merge(get_subscriber_response(subscriber_id, address, govuk_account_id)).to_json,
300
+ )
301
+ end
302
+
303
+ def stub_email_alert_api_authenticate_subscriber_by_govuk_account_session_invalid(govuk_account_session)
304
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
305
+ .with(
306
+ body: { govuk_account_session: govuk_account_session }.to_json,
307
+ ).to_return(
308
+ status: 401,
309
+ )
310
+ end
311
+
312
+ def stub_email_alert_api_authenticate_subscriber_by_govuk_account_email_unverified(govuk_account_session, new_govuk_account_session: nil)
313
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
314
+ .with(
315
+ body: { govuk_account_session: govuk_account_session }.to_json,
316
+ ).to_return(
317
+ status: 403,
318
+ body: {
319
+ govuk_account_session: new_govuk_account_session,
320
+ }.compact.to_json,
321
+ )
322
+ end
323
+
324
+ def stub_email_alert_api_authenticate_subscriber_by_govuk_account_no_subscriber(govuk_account_session, new_govuk_account_session: nil)
325
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
326
+ .with(
327
+ body: { govuk_account_session: govuk_account_session }.to_json,
328
+ ).to_return(
329
+ status: 404,
330
+ body: {
331
+ govuk_account_session: new_govuk_account_session,
332
+ }.compact.to_json,
333
+ )
334
+ end
335
+
336
+ def stub_email_alert_api_link_subscriber_to_govuk_account(govuk_account_session, subscriber_id, address, govuk_account_id: "user-id", new_govuk_account_session: nil)
337
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
338
+ .with(
339
+ body: { govuk_account_session: govuk_account_session }.to_json,
340
+ ).to_return(
341
+ status: 200,
342
+ body: {
343
+ govuk_account_session: new_govuk_account_session,
344
+ }.compact.merge(get_subscriber_response(subscriber_id, address, govuk_account_id)).to_json,
345
+ )
346
+ end
347
+
348
+ def stub_email_alert_api_link_subscriber_to_govuk_account_session_invalid(govuk_account_session)
349
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
350
+ .with(
351
+ body: { govuk_account_session: govuk_account_session }.to_json,
352
+ ).to_return(
353
+ status: 401,
354
+ )
355
+ end
356
+
357
+ def stub_email_alert_api_link_subscriber_to_govuk_account_email_unverified(govuk_account_session, new_govuk_account_session: nil)
358
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
359
+ .with(
360
+ body: { govuk_account_session: govuk_account_session }.to_json,
361
+ ).to_return(
362
+ status: 403,
363
+ body: {
364
+ govuk_account_session: new_govuk_account_session,
365
+ }.compact.to_json,
366
+ )
367
+ end
368
+
369
+ def stub_email_alert_api_find_subscriber_by_govuk_account(govuk_account_id, subscriber_id, address)
370
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/#{govuk_account_id}")
371
+ .to_return(
372
+ status: 200,
373
+ body: get_subscriber_response(subscriber_id, address, govuk_account_id).to_json,
374
+ )
375
+ end
376
+
377
+ def stub_email_alert_api_find_subscriber_by_govuk_account_no_subscriber(govuk_account_id)
378
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/#{govuk_account_id}")
379
+ .to_return(status: 404)
380
+ end
381
+
286
382
  def assert_unsubscribed(uuid)
287
383
  assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}", times: 1)
288
384
  end
@@ -314,11 +410,12 @@ module GdsApi
314
410
 
315
411
  private
316
412
 
317
- def get_subscriber_response(id, address)
413
+ def get_subscriber_response(id, address, govuk_account_id)
318
414
  {
319
415
  "subscriber" => {
320
416
  "id" => id,
321
417
  "address" => address,
418
+ "govuk_account_id" => govuk_account_id,
322
419
  },
323
420
  }
324
421
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "71.3.0".freeze
2
+ VERSION = "71.8.0".freeze
3
3
  end
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: 71.3.0
4
+ version: 71.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable