gds-api-adapters 80.0.0 → 81.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f6921e5174a36bd20b7d8f6a446d4764778acac96e707108ed4fd581d8261e8
4
- data.tar.gz: 00b4f87f11ee027458c97f21216c43ba42ad371faedbc1ce4e3cb5d886b32126
3
+ metadata.gz: 8fca55d695f003f76bfe73bdec79add86ab4a2b25efadedf0f25690f54c20d4f
4
+ data.tar.gz: 12f119f94ca114d7b2c3ae3eab96554c2ec84d3cbac61c2bb8d0a502e006d022
5
5
  SHA512:
6
- metadata.gz: 62c4ee4274480082f184e019de3307961b94b2e14840a5e7a9ddf82c1521bc35e66586414bf6a5465e1e06c0c3213194945c84ad48ea0801f8f5e430bb8b2280
7
- data.tar.gz: 26baf319e1e5a0072692b570330bb0bb44fbf17d9f2fb43765f39ae9307ecb7c0ca25da823d30e960f5100362d645d47fce8e3717a4667f3533e4dd9615b3748
6
+ metadata.gz: 126f6602485893e0a6fd0731ecc579f575d2d2516f0d47a4ee23029c2bcfd0ef20750b97f01fee5a70187587ea399c6e602be69b8ddca273af1cae831cd4808d
7
+ data.tar.gz: 2bab839794240cfd0b23a04f36c0a4395377e5fd765f4548a844ce27ec868bf58055059046499ddd862dadbb3a6a9e360dd59f215e5eb1f469f8a17e6f7f3eba
data/README.md CHANGED
@@ -82,6 +82,34 @@ There are also test helpers for stubbing various requests in other apps.
82
82
 
83
83
  See [all the test helpers in lib/gds_api/test_helpers](/lib/gds_api/test_helpers).
84
84
 
85
+
86
+ ## Pact Verification During CI
87
+
88
+ During the CI test suite, Jenkins downloads and runs the pact:verify tasks for
89
+ each provider app. It's run directly on the Jenkins machine rather than in
90
+ docker containers for each app. For this reason the email-alert-api app
91
+ requires a specific setup on the CI machine - on db creation it copies the
92
+ database from the template1 db (this is the usual PG behaviour, but for some
93
+ reason rails needs to be told to do this explicitly). This template1 db has
94
+ to have the uuid-ossp extension installed by superuser, because the jenkins
95
+ user that CI runs under cannot create this extension. If this test stops
96
+ working with errors like:
97
+
98
+ ```
99
+ Caused by:
100
+ PG::InsufficientPrivilege: ERROR: permission denied to create extension "uuid-ossp"
101
+ HINT: Must be superuser to create this extension.
102
+ ```
103
+
104
+ ...the template may have been deleted or changed. Log in to the relevant CI
105
+ agent and run:
106
+
107
+ `> sudo -u postgres psql -d template1`
108
+
109
+ Then at the PSQL command line:
110
+
111
+ `template1=# CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`
112
+
85
113
  ## Licence
86
114
 
87
115
  Released under the MIT Licence, a copy of which can be found in the file
@@ -252,7 +252,7 @@ class GdsApi::EmailAlertApi < GdsApi::Base
252
252
  # optionally send a notification email explaining the reason
253
253
  #
254
254
  # @param [string] slug Identifier for the subscription list
255
- # @param [string] (optional) govuk_request_id An ID allowing us to trace requests across our infra. Required if you want to send an email.
255
+ # @param [string] (optional) govuk_request_id An ID allowing us to trace requests across our infra. Required if you want to send an email by running out-of-band processes via asynchronous workers.
256
256
  # @param [string] (optional) body Optional email body to send to alert users they are being unsubscribed. Required if you want to send an email
257
257
  # @param [string] (optional) sender_message_id A UUID to prevent multiple emails for the same event. Required if you want to send an email.
258
258
  def bulk_unsubscribe(slug:, govuk_request_id: nil, body: nil, sender_message_id: nil)
@@ -6,8 +6,18 @@ class GdsApi::LocalLinksManager < GdsApi::Base
6
6
  get_json(url)
7
7
  end
8
8
 
9
+ def local_link_by_custodian_code(local_custodian_code, lgsl, lgil)
10
+ url = "#{endpoint}/api/link?local_custodian_code=#{local_custodian_code}&lgsl=#{lgsl}&lgil=#{lgil}"
11
+ get_json(url)
12
+ end
13
+
9
14
  def local_authority(authority_slug)
10
15
  url = "#{endpoint}/api/local-authority?authority_slug=#{authority_slug}"
11
16
  get_json(url)
12
17
  end
18
+
19
+ def local_authority_by_custodian_code(local_custodian_code)
20
+ url = "#{endpoint}/api/local-authority?local_custodian_code=#{local_custodian_code}"
21
+ get_json(url)
22
+ end
13
23
  end
@@ -413,15 +413,15 @@ module GdsApi
413
413
  .to_return(status: 202)
414
414
  end
415
415
 
416
- def stub_email_alert_api_bulk_unsubscribe_with_message(slug:, govuk_request_id:, body:, sender_message_id:)
416
+ def stub_email_alert_api_bulk_unsubscribe_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
417
417
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
418
- .with(
418
+ .with({
419
419
  body: {
420
420
  body: body,
421
421
  sender_message_id: sender_message_id,
422
422
  }.to_json,
423
- headers: { "Govuk-Request-Id" => govuk_request_id },
424
- ).to_return(status: 202)
423
+ }.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
424
+ .to_return(status: 202)
425
425
  end
426
426
 
427
427
  def stub_email_alert_api_bulk_unsubscribe_not_found(slug:)
@@ -429,15 +429,15 @@ module GdsApi
429
429
  .to_return(status: 404)
430
430
  end
431
431
 
432
- def stub_email_alert_api_bulk_unsubscribe_not_found_with_message(slug:, govuk_request_id:, body:, sender_message_id:)
432
+ def stub_email_alert_api_bulk_unsubscribe_not_found_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
433
433
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
434
- .with(
434
+ .with({
435
435
  body: {
436
436
  body: body,
437
437
  sender_message_id: sender_message_id,
438
438
  }.to_json,
439
- headers: { "Govuk-Request-Id" => govuk_request_id },
440
- ).to_return(status: 404)
439
+ }.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
440
+ .to_return(status: 404)
441
441
  end
442
442
 
443
443
  def stub_email_alert_api_bulk_unsubscribe_conflict(slug:)
@@ -445,15 +445,15 @@ module GdsApi
445
445
  .to_return(status: 409)
446
446
  end
447
447
 
448
- def stub_email_alert_api_bulk_unsubscribe_conflict_with_message(slug:, govuk_request_id:, body:, sender_message_id:)
448
+ def stub_email_alert_api_bulk_unsubscribe_conflict_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
449
449
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
450
- .with(
450
+ .with({
451
451
  body: {
452
452
  body: body,
453
453
  sender_message_id: sender_message_id,
454
454
  }.to_json,
455
- headers: { "Govuk-Request-Id" => govuk_request_id },
456
- ).to_return(status: 409)
455
+ }.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
456
+ .to_return(status: 409)
457
457
  end
458
458
 
459
459
  def stub_email_alert_api_bulk_unsubscribe_bad_request(slug:)
@@ -461,15 +461,15 @@ module GdsApi
461
461
  .to_return(status: 422)
462
462
  end
463
463
 
464
- def stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(slug:, govuk_request_id:, body:, sender_message_id:)
464
+ def stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
465
465
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
466
- .with(
466
+ .with({
467
467
  body: {
468
468
  body: body,
469
469
  sender_message_id: sender_message_id,
470
470
  }.to_json,
471
- headers: { "Govuk-Request-Id" => govuk_request_id },
472
- ).to_return(status: 422)
471
+ }.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
472
+ .to_return(status: 422)
473
473
  end
474
474
 
475
475
  def stub_update_subscriber_list_details(slug:, params:)
@@ -595,6 +595,12 @@ module GdsApi
595
595
  url = "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists"
596
596
  query ? "#{url}?#{query}" : url
597
597
  end
598
+
599
+ # Find and return the subscriber list for a topic if one exists.
600
+ def email_alert_api_has_subscriber_list_for_topic(content_id:, list: {})
601
+ url = "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists?links%5Btopics%5D%5B0%5D=#{content_id}"
602
+ stub_request(:get, url).to_return(status: 200, body: { "subscriber_list" => list }.to_json)
603
+ end
598
604
  end
599
605
  end
600
606
  end
@@ -5,7 +5,7 @@ module GdsApi
5
5
  module LocalLinksManager
6
6
  LOCAL_LINKS_MANAGER_ENDPOINT = Plek.current.find("local-links-manager")
7
7
 
8
- def stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England", status: "ok")
8
+ def stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England", status: "ok", local_custodian_code: nil)
9
9
  response = {
10
10
  "local_authority" => {
11
11
  "name" => authority_slug.capitalize,
@@ -13,6 +13,7 @@ module GdsApi
13
13
  "tier" => "unitary",
14
14
  "homepage_url" => "http://#{authority_slug}.example.com",
15
15
  "country_name" => country_name,
16
+ "slug" => authority_slug,
16
17
  },
17
18
  "local_interaction" => {
18
19
  "lgsl_code" => lgsl,
@@ -25,9 +26,15 @@ module GdsApi
25
26
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
26
27
  .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
27
28
  .to_return(body: response.to_json, status: 200)
29
+
30
+ unless local_custodian_code.nil?
31
+ stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
32
+ .with(query: { local_custodian_code: local_custodian_code, lgsl: lgsl, lgil: lgil })
33
+ .to_return(body: response.to_json, status: 200)
34
+ end
28
35
  end
29
36
 
30
- def stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England")
37
+ def stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England", local_custodian_code: nil)
31
38
  response = {
32
39
  "local_authority" => {
33
40
  "name" => authority_slug.capitalize,
@@ -35,15 +42,22 @@ module GdsApi
35
42
  "tier" => "unitary",
36
43
  "homepage_url" => "http://#{authority_slug}.example.com",
37
44
  "country_name" => country_name,
45
+ "slug" => authority_slug,
38
46
  },
39
47
  }
40
48
 
41
49
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
42
50
  .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
43
51
  .to_return(body: response.to_json, status: 200)
52
+
53
+ unless local_custodian_code.nil?
54
+ stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
55
+ .with(query: { local_custodian_code: local_custodian_code, lgsl: lgsl, lgil: lgil })
56
+ .to_return(body: response.to_json, status: 200)
57
+ end
44
58
  end
45
59
 
46
- def stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England")
60
+ def stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England", local_custodian_code: nil)
47
61
  response = {
48
62
  "local_authority" => {
49
63
  "name" => authority_slug.capitalize,
@@ -51,36 +65,40 @@ module GdsApi
51
65
  "tier" => "unitary",
52
66
  "homepage_url" => nil,
53
67
  "country_name" => country_name,
68
+ "slug" => authority_slug,
54
69
  },
55
70
  }
56
71
 
57
72
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
58
73
  .with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
59
74
  .to_return(body: response.to_json, status: 200)
60
- end
61
75
 
62
- def stub_local_links_manager_request_with_missing_parameters(authority_slug, lgsl, lgil)
63
- # convert nil to an empty string, otherwise query param is not expressed correctly
64
- params = {
65
- authority_slug: authority_slug || "",
66
- lgsl: lgsl || "",
67
- lgil: lgil || "",
68
- }
76
+ unless local_custodian_code.nil?
77
+ stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
78
+ .with(query: { local_custodian_code: local_custodian_code, lgsl: lgsl, lgil: lgil })
79
+ .to_return(body: response.to_json, status: 200)
80
+ end
81
+ end
69
82
 
83
+ def stub_local_links_manager_request_with_missing_parameters(**parameters)
70
84
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
71
- .with(query: params)
85
+ .with(query: convert_to_query_string_params(parameters))
72
86
  .to_return(body: {}.to_json, status: 400)
73
87
  end
74
88
 
75
- def stub_local_links_manager_does_not_have_required_objects(authority_slug, lgsl, lgil)
76
- params = { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil }
77
-
89
+ def stub_local_links_manager_request_with_invalid_parameters(**parameters)
78
90
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
79
- .with(query: params)
91
+ .with(query: convert_to_query_string_params(parameters))
80
92
  .to_return(body: {}.to_json, status: 404)
81
93
  end
82
94
 
83
- def stub_local_links_manager_has_a_local_authority(authority_slug)
95
+ def convert_to_query_string_params(parameters)
96
+ # convert nil to an empty string, otherwise query param is not expressed correctly
97
+ parameters.each { |key, _value| parameters[key] = "" if parameters[key].nil? }
98
+ parameters
99
+ end
100
+
101
+ def stub_local_links_manager_has_a_local_authority(authority_slug, local_custodian_code: nil)
84
102
  response = {
85
103
  "local_authorities" => [
86
104
  {
@@ -88,6 +106,7 @@ module GdsApi
88
106
  "homepage_url" => "http://#{authority_slug}.example.com",
89
107
  "country_name" => "England",
90
108
  "tier" => "unitary",
109
+ "slug" => authority_slug,
91
110
  },
92
111
  ],
93
112
  }
@@ -95,9 +114,15 @@ module GdsApi
95
114
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
96
115
  .with(query: { authority_slug: authority_slug })
97
116
  .to_return(body: response.to_json, status: 200)
117
+
118
+ unless local_custodian_code.nil?
119
+ stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
120
+ .with(query: { local_custodian_code: local_custodian_code })
121
+ .to_return(body: response.to_json, status: 200)
122
+ end
98
123
  end
99
124
 
100
- def stub_local_links_manager_has_a_district_and_county_local_authority(district_slug, county_slug)
125
+ def stub_local_links_manager_has_a_district_and_county_local_authority(district_slug, county_slug, local_custodian_code: nil)
101
126
  response = {
102
127
  "local_authorities" => [
103
128
  {
@@ -105,12 +130,14 @@ module GdsApi
105
130
  "homepage_url" => "http://#{district_slug}.example.com",
106
131
  "country_name" => "England",
107
132
  "tier" => "district",
133
+ "slug" => district_slug,
108
134
  },
109
135
  {
110
136
  "name" => county_slug.capitalize,
111
137
  "homepage_url" => "http://#{county_slug}.example.com",
112
138
  "country_name" => "England",
113
139
  "tier" => "county",
140
+ "slug" => county_slug,
114
141
  },
115
142
  ],
116
143
  }
@@ -118,6 +145,12 @@ module GdsApi
118
145
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
119
146
  .with(query: { authority_slug: district_slug })
120
147
  .to_return(body: response.to_json, status: 200)
148
+
149
+ unless local_custodian_code.nil?
150
+ stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
151
+ .with(query: { local_custodian_code: local_custodian_code })
152
+ .to_return(body: response.to_json, status: 200)
153
+ end
121
154
  end
122
155
 
123
156
  def stub_local_links_manager_request_without_local_authority_slug
@@ -126,12 +159,24 @@ module GdsApi
126
159
  .to_return(body: {}.to_json, status: 400)
127
160
  end
128
161
 
162
+ def stub_local_links_manager_request_without_local_custodian_code
163
+ stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
164
+ .with(query: { local_custodian_code: "" })
165
+ .to_return(body: {}.to_json, status: 400)
166
+ end
167
+
129
168
  def stub_local_links_manager_does_not_have_an_authority(authority_slug)
130
169
  stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
131
170
  .with(query: { authority_slug: authority_slug })
132
171
  .to_return(body: {}.to_json, status: 404)
133
172
  end
134
173
 
174
+ def stub_local_links_manager_does_not_have_a_custodian_code(local_custodian_code)
175
+ stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
176
+ .with(query: { local_custodian_code: local_custodian_code })
177
+ .to_return(body: {}.to_json, status: 404)
178
+ end
179
+
135
180
  def stub_local_links_manager_has_a_local_authority_without_homepage(authority_slug)
136
181
  response = {
137
182
  "local_authorities" => [
@@ -140,6 +185,7 @@ module GdsApi
140
185
  "homepage_url" => "",
141
186
  "country_name" => "England",
142
187
  "tier" => "unitary",
188
+ "slug" => authority_slug,
143
189
  },
144
190
  ],
145
191
  }
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "80.0.0".freeze
2
+ VERSION = "81.0.1".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: 80.0.0
4
+ version: 81.0.1
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: 2022-06-21 00:00:00.000000000 Z
11
+ date: 2022-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -440,14 +440,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
440
440
  requirements:
441
441
  - - ">="
442
442
  - !ruby/object:Gem::Version
443
- version: 2.6.0
443
+ version: 2.7.0
444
444
  required_rubygems_version: !ruby/object:Gem::Requirement
445
445
  requirements:
446
446
  - - ">="
447
447
  - !ruby/object:Gem::Version
448
448
  version: '0'
449
449
  requirements: []
450
- rubygems_version: 3.0.3
450
+ rubygems_version: 3.1.6
451
451
  signing_key:
452
452
  specification_version: 4
453
453
  summary: Adapters to work with GDS APIs