gds-api-adapters 71.2.0 → 71.7.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: fb0860ace845fe7016ae87832f88f46cbf9d27a660432f3314ad4b52cf4774f9
4
- data.tar.gz: e3ad07862f196e9e65f16a1d3ff231133c45d293cc8ac4a998c126f5d08aa680
3
+ metadata.gz: a1177b1955f1d71f876486faf8932550ff11330dbc69bfcf4b3e04eea88ce2fa
4
+ data.tar.gz: ca001da8d98cab308f0ce695aa46700c3c07d2fd2cd63e3ceea51868013ef4ed
5
5
  SHA512:
6
- metadata.gz: 8356685a336b23b4c0cb7f8abafd697cafd065be17f5508097e00d7503b6ae7aaaff5efa14a5430ed0f74121661d5df4d1614185717136a1b9e49d78e57ea369
7
- data.tar.gz: 232183a69a8985bd6963c475ef852e2d4d28e481d9c09232bd8dbcc9f9db102d16f22df09cd99c4abef7072e1524be76d34230be9cdf99867de08f7e0cf5a4a2
6
+ metadata.gz: 75a3f20f1364ecf6d0e76f02622b95337b2ec4a8dbb2bc77e4a46a99787c855063454fe92835dee4b105b03ab066c2b0d85c16b98bb57bce0e34009aadbf9a4b
7
+ data.tar.gz: 282abe1e9269b6fa087f1a6e7205f49eef22f12670d3d7592f3a56acce50a97fab79c68a227be7d2b7a4a1e8e29cd1805738769d2a41e5399199a8c117352ee9
@@ -45,6 +45,33 @@ class GdsApi::AccountApi < GdsApi::Base
45
45
  post_json("#{endpoint}/api/oauth2/state", attributes: attributes)
46
46
  end
47
47
 
48
+ # Get all the information about a user needed to render the account home page
49
+ #
50
+ # @param [String] govuk_account_session Value of the session header
51
+ #
52
+ # @return [Hash] Information about the user and the services they've used, and a new session header
53
+ def get_user(govuk_account_session:)
54
+ get_json("#{endpoint}/api/user", auth_headers(govuk_account_session))
55
+ end
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
+
48
75
  # Check if a user has an email subscription for the Transition Checker
49
76
  #
50
77
  # @param [String] govuk_account_session Value of the session header
@@ -96,13 +123,42 @@ class GdsApi::AccountApi < GdsApi::Base
96
123
  get_json("#{endpoint}/api/attributes/names?#{querystring}", auth_headers(govuk_account_session))
97
124
  end
98
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
+
99
155
  # Look up all pages saved by a user in their Account
100
156
  #
101
157
  # @param [String] govuk_account_session Value of the session header
102
158
  #
103
- # @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
104
160
  def get_saved_pages(govuk_account_session:)
105
- get_json("#{endpoint}/api/saved_pages", auth_headers(govuk_account_session))
161
+ get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session))
106
162
  end
107
163
 
108
164
  # Return a single page by unique URL
@@ -112,7 +168,7 @@ class GdsApi::AccountApi < GdsApi::Base
112
168
  #
113
169
  # @return [Hash] containing :saved_page, a hash of a single saved page value
114
170
  def get_saved_page(page_path:, govuk_account_session:)
115
- 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))
116
172
  end
117
173
 
118
174
  # Upsert a single saved page entry in a users account
@@ -122,7 +178,7 @@ class GdsApi::AccountApi < GdsApi::Base
122
178
  #
123
179
  # @return [Hash] A single saved page value (if sucessful)
124
180
  def save_page(page_path:, govuk_account_session:)
125
- 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))
126
182
  end
127
183
 
128
184
  # Delete a single saved page entry from a users account
@@ -133,7 +189,7 @@ class GdsApi::AccountApi < GdsApi::Base
133
189
  # @return [GdsApi::Response] A status code of 204 indicates the saved page has been successfully deleted.
134
190
  # A status code of 404 indicates there is no saved page with this path.
135
191
  def delete_saved_page(page_path:, govuk_account_session:)
136
- 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))
137
193
  end
138
194
 
139
195
  private
@@ -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
@@ -180,10 +180,10 @@ module GdsApi
180
180
  raise GdsApi::EndpointNotFound, "Could not connect to #{url}"
181
181
  rescue RestClient::Exceptions::Timeout => e
182
182
  logger.error loggable.merge(status: "timeout", error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
183
- raise GdsApi::TimedOutException
183
+ raise GdsApi::TimedOutException, e.message
184
184
  rescue URI::InvalidURIError => e
185
185
  logger.error loggable.merge(status: "invalid_uri", error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
186
- raise GdsApi::InvalidUrl
186
+ raise GdsApi::InvalidUrl, e.message
187
187
  rescue RestClient::Exception => e
188
188
  # Log the error here, since we have access to loggable, but raise the
189
189
  # exception up to the calling method to deal with
@@ -192,10 +192,10 @@ module GdsApi
192
192
  raise
193
193
  rescue Errno::ECONNRESET => e
194
194
  logger.error loggable.merge(status: "connection_reset", error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
195
- raise GdsApi::TimedOutException
195
+ raise GdsApi::TimedOutException, e.message
196
196
  rescue SocketError => e
197
197
  logger.error loggable.merge(status: "socket_error", error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
198
- raise GdsApi::SocketErrorException
198
+ raise GdsApi::SocketErrorException, e.message
199
199
  end
200
200
  end
201
201
  end
@@ -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,6 +58,156 @@ module GdsApi
38
58
  )
39
59
  end
40
60
 
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)
65
+ stub_account_api_request(
66
+ :get,
67
+ "/api/user",
68
+ response_body: {
69
+ id: id,
70
+ level_of_authentication: level_of_authentication,
71
+ email: email,
72
+ email_verified: email_verified,
73
+ has_unconfirmed_email: has_unconfirmed_email,
74
+ services: services,
75
+ },
76
+ **options,
77
+ )
78
+ end
79
+
80
+ def stub_account_api_user_info_service_state(service:, service_state: "yes", **options)
81
+ stub_account_api_user_info(
82
+ **options.merge(
83
+ services: options.fetch(:services, {}).merge(service => service_state),
84
+ ),
85
+ )
86
+ end
87
+
88
+ def stub_account_api_unauthorized_user_info(**options)
89
+ stub_account_api_request(
90
+ :get,
91
+ "/api/user",
92
+ response_status: 401,
93
+ **options,
94
+ )
95
+ end
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
+ ################################################
41
211
  def stub_account_api_has_email_subscription(**options)
42
212
  stub_account_api_request(
43
213
  :get,
@@ -75,6 +245,9 @@ module GdsApi
75
245
  )
76
246
  end
77
247
 
248
+ #################################################
249
+ # POST /api/transition-checker-email-subscription
250
+ #################################################
78
251
  def stub_account_api_set_email_subscription(slug: nil, **options)
79
252
  stub_account_api_request(
80
253
  :post,
@@ -105,6 +278,9 @@ module GdsApi
105
278
  )
106
279
  end
107
280
 
281
+ #####################
282
+ # GET /api/attributes
283
+ #####################
108
284
  def stub_account_api_has_attributes(attributes: [], values: {}, **options)
109
285
  querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
110
286
  stub_account_api_request(
@@ -136,6 +312,9 @@ module GdsApi
136
312
  )
137
313
  end
138
314
 
315
+ #######################
316
+ # PATCH /api/attributes
317
+ #######################
139
318
  def stub_account_api_set_attributes(attributes: nil, **options)
140
319
  stub_account_api_request(
141
320
  :patch,
@@ -166,6 +345,9 @@ module GdsApi
166
345
  )
167
346
  end
168
347
 
348
+ ###########################
349
+ # GET /api/attributes/names
350
+ ###########################
169
351
  def stub_account_api_get_attributes_names(attributes: [], **options)
170
352
  querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
171
353
  stub_account_api_request(
@@ -197,24 +379,13 @@ module GdsApi
197
379
  )
198
380
  end
199
381
 
200
- def stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil)
201
- with.merge!(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session }) if govuk_account_session
202
- new_govuk_account_session = nil if response_status >= 400
203
- to_return = { status: response_status, body: response_body.merge(govuk_account_session: new_govuk_account_session).compact.to_json }
204
- if with.empty?
205
- stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").to_return(**to_return)
206
- else
207
- stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return)
208
- end
209
- end
210
-
211
382
  ######################
212
- # GET /api/saved_pages
383
+ # GET /api/saved-pages
213
384
  ######################
214
385
  def stub_account_api_returning_saved_pages(saved_pages: [], **options)
215
386
  stub_account_api_request(
216
387
  :get,
217
- "/api/saved_pages",
388
+ "/api/saved-pages",
218
389
  response_body: { saved_pages: saved_pages },
219
390
  **options,
220
391
  )
@@ -223,7 +394,7 @@ module GdsApi
223
394
  def stub_account_api_unauthorized_get_saved_pages(**options)
224
395
  stub_account_api_request(
225
396
  :get,
226
- "/api/saved_pages",
397
+ "/api/saved-pages",
227
398
  response_status: 401,
228
399
  **options,
229
400
  )
@@ -232,11 +403,17 @@ module GdsApi
232
403
  #################################
233
404
  # GET /api/saved_pages/:page_path
234
405
  #################################
235
- def stub_account_api_get_saved_page(page_path:, **options)
406
+ def stub_account_api_get_saved_page(page_path:, content_id: "46163ed2-1777-4ee6-bdd4-6a2007e49d8f", title: "Ministry of Magic", **options)
236
407
  stub_account_api_request(
237
408
  :get,
238
- "/api/saved_pages/#{CGI.escape(page_path)}",
239
- response_body: { saved_page: { page_path: page_path } },
409
+ "/api/saved-pages/#{CGI.escape(page_path)}",
410
+ response_body: {
411
+ saved_page: {
412
+ page_path: page_path,
413
+ content_id: content_id,
414
+ title: title,
415
+ },
416
+ },
240
417
  **options,
241
418
  )
242
419
  end
@@ -244,7 +421,7 @@ module GdsApi
244
421
  def stub_account_api_does_not_have_saved_page(page_path:, **options)
245
422
  stub_account_api_request(
246
423
  :get,
247
- "/api/saved_pages/#{CGI.escape(page_path)}",
424
+ "/api/saved-pages/#{CGI.escape(page_path)}",
248
425
  response_status: 404,
249
426
  **options,
250
427
  )
@@ -253,20 +430,26 @@ module GdsApi
253
430
  def stub_account_api_unauthorized_get_saved_page(page_path:, **options)
254
431
  stub_account_api_request(
255
432
  :get,
256
- "/api/saved_pages/#{CGI.escape(page_path)}",
433
+ "/api/saved-pages/#{CGI.escape(page_path)}",
257
434
  response_status: 401,
258
435
  **options,
259
436
  )
260
437
  end
261
438
 
262
439
  #################################
263
- # PUT /api/saved_pages/:page_path
440
+ # PUT /api/saved-pages/:page_path
264
441
  #################################
265
- def stub_account_api_save_page(page_path:, **options)
442
+ def stub_account_api_save_page(page_path:, content_id: "c840bfa2-011a-42cc-ac7a-a6da990aff0b", title: "Ministry of Magic", **options)
266
443
  stub_account_api_request(
267
444
  :put,
268
- "/api/saved_pages/#{CGI.escape(page_path)}",
269
- response_body: { saved_page: { page_path: page_path } },
445
+ "/api/saved-pages/#{CGI.escape(page_path)}",
446
+ response_body: {
447
+ saved_page: {
448
+ page_path: page_path,
449
+ content_id: content_id,
450
+ title: title,
451
+ },
452
+ },
270
453
  **options,
271
454
  )
272
455
  end
@@ -278,9 +461,9 @@ module GdsApi
278
461
  def stub_account_api_save_page_cannot_save_page(page_path:, **options)
279
462
  stub_account_api_request(
280
463
  :put,
281
- "/api/saved_pages/#{CGI.escape(page_path)}",
464
+ "/api/saved-pages/#{CGI.escape(page_path)}",
282
465
  response_status: 422,
283
- response_body: { **cannot_save_page_problem_detail({ page_path: page_path }) },
466
+ response_body: cannot_save_page_problem_detail({ page_path: page_path }),
284
467
  **options,
285
468
  )
286
469
  end
@@ -288,7 +471,7 @@ module GdsApi
288
471
  def stub_account_api_unauthorized_save_page(page_path:, **options)
289
472
  stub_account_api_request(
290
473
  :put,
291
- "/api/saved_pages/#{CGI.escape(page_path)}",
474
+ "/api/saved-pages/#{CGI.escape(page_path)}",
292
475
  response_status: 401,
293
476
  **options,
294
477
  )
@@ -309,7 +492,7 @@ module GdsApi
309
492
  def stub_account_api_delete_saved_page(page_path:, **options)
310
493
  stub_account_api_request(
311
494
  :delete,
312
- "/api/saved_pages/#{CGI.escape(page_path)}",
495
+ "/api/saved-pages/#{CGI.escape(page_path)}",
313
496
  response_status: 204,
314
497
  **options,
315
498
  )
@@ -318,7 +501,7 @@ module GdsApi
318
501
  def stub_account_api_delete_saved_page_does_not_exist(page_path:, **options)
319
502
  stub_account_api_request(
320
503
  :delete,
321
- "/api/saved_pages/#{CGI.escape(page_path)}",
504
+ "/api/saved-pages/#{CGI.escape(page_path)}",
322
505
  response_status: 404,
323
506
  **options,
324
507
  )
@@ -327,7 +510,7 @@ module GdsApi
327
510
  def stub_account_api_delete_saved_page_unauthorised(page_path:, **options)
328
511
  stub_account_api_request(
329
512
  :delete,
330
- "/api/saved_pages/#{CGI.escape(page_path)}",
513
+ "/api/saved-pages/#{CGI.escape(page_path)}",
331
514
  response_status: 401,
332
515
  **options,
333
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,97 @@ module GdsApi
283
283
  .to_return(status: 404)
284
284
  end
285
285
 
286
+ 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)
287
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
288
+ .with(
289
+ body: { govuk_account_session: govuk_account_session }.to_json,
290
+ ).to_return(
291
+ status: 200,
292
+ body: {
293
+ govuk_account_session: new_govuk_account_session,
294
+ }.compact.merge(get_subscriber_response(subscriber_id, address, govuk_account_id)).to_json,
295
+ )
296
+ end
297
+
298
+ def stub_email_alert_api_authenticate_subscriber_by_govuk_account_session_invalid(govuk_account_session)
299
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
300
+ .with(
301
+ body: { govuk_account_session: govuk_account_session }.to_json,
302
+ ).to_return(
303
+ status: 401,
304
+ )
305
+ end
306
+
307
+ def stub_email_alert_api_authenticate_subscriber_by_govuk_account_email_unverified(govuk_account_session, new_govuk_account_session: nil)
308
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
309
+ .with(
310
+ body: { govuk_account_session: govuk_account_session }.to_json,
311
+ ).to_return(
312
+ status: 403,
313
+ body: {
314
+ govuk_account_session: new_govuk_account_session,
315
+ }.compact.to_json,
316
+ )
317
+ end
318
+
319
+ def stub_email_alert_api_authenticate_subscriber_by_govuk_account_no_subscriber(govuk_account_session, new_govuk_account_session: nil)
320
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
321
+ .with(
322
+ body: { govuk_account_session: govuk_account_session }.to_json,
323
+ ).to_return(
324
+ status: 404,
325
+ body: {
326
+ govuk_account_session: new_govuk_account_session,
327
+ }.compact.to_json,
328
+ )
329
+ end
330
+
331
+ 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)
332
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
333
+ .with(
334
+ body: { govuk_account_session: govuk_account_session }.to_json,
335
+ ).to_return(
336
+ status: 200,
337
+ body: {
338
+ govuk_account_session: new_govuk_account_session,
339
+ }.compact.merge(get_subscriber_response(subscriber_id, address, govuk_account_id)).to_json,
340
+ )
341
+ end
342
+
343
+ def stub_email_alert_api_link_subscriber_to_govuk_account_session_invalid(govuk_account_session)
344
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
345
+ .with(
346
+ body: { govuk_account_session: govuk_account_session }.to_json,
347
+ ).to_return(
348
+ status: 401,
349
+ )
350
+ end
351
+
352
+ def stub_email_alert_api_link_subscriber_to_govuk_account_email_unverified(govuk_account_session, new_govuk_account_session: nil)
353
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
354
+ .with(
355
+ body: { govuk_account_session: govuk_account_session }.to_json,
356
+ ).to_return(
357
+ status: 403,
358
+ body: {
359
+ govuk_account_session: new_govuk_account_session,
360
+ }.compact.to_json,
361
+ )
362
+ end
363
+
364
+ def stub_email_alert_api_find_subscriber_by_govuk_account(govuk_account_id, subscriber_id, address)
365
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/#{govuk_account_id}")
366
+ .to_return(
367
+ status: 200,
368
+ body: get_subscriber_response(subscriber_id, address, govuk_account_id).to_json,
369
+ )
370
+ end
371
+
372
+ def stub_email_alert_api_find_subscriber_by_govuk_account_no_subscriber(govuk_account_id)
373
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/#{govuk_account_id}")
374
+ .to_return(status: 404)
375
+ end
376
+
286
377
  def assert_unsubscribed(uuid)
287
378
  assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}", times: 1)
288
379
  end
@@ -314,11 +405,12 @@ module GdsApi
314
405
 
315
406
  private
316
407
 
317
- def get_subscriber_response(id, address)
408
+ def get_subscriber_response(id, address, govuk_account_id)
318
409
  {
319
410
  "subscriber" => {
320
411
  "id" => id,
321
412
  "address" => address,
413
+ "govuk_account_id" => govuk_account_id,
322
414
  },
323
415
  }
324
416
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "71.2.0".freeze
2
+ VERSION = "71.7.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.2.0
4
+ version: 71.7.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-05-25 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -445,7 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
445
445
  - !ruby/object:Gem::Version
446
446
  version: '0'
447
447
  requirements: []
448
- rubygems_version: 3.1.4
448
+ rubygems_version: 3.0.3
449
449
  signing_key:
450
450
  specification_version: 4
451
451
  summary: Adapters to work with GDS APIs