gds-api-adapters 59.3.0 → 59.4.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/test_helpers/email_alert_api.rb +63 -12
- data/lib/gds_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56d18ef98559e3640e67b7e74ea5515eaa8a7ef3c353d2b14f1175abc795eac8
|
4
|
+
data.tar.gz: a3280c7002add9a5e53dd730a7da7dcde062db85c6d8c7cf6ce7170752cc18d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 449724146bcd6c51ac6c71d637921216ce4bb4919401ea8bd6317bcbcd6685420edca58806acd542ac2e6d707efc025b09a323a13402909b5f6e8872e1f853e8
|
7
|
+
data.tar.gz: fe4dd739159277e71d478e4051358654c8f98cac092abe533e06b4b39190d4a461b26a05d124974b3c153654294707efb50e60e10ee6ec8eb52aecae09628310
|
@@ -53,18 +53,68 @@ module GdsApi
|
|
53
53
|
subscriber_list_id: 1000,
|
54
54
|
ended: false
|
55
55
|
)
|
56
|
+
response = get_subscription_response(
|
57
|
+
id,
|
58
|
+
frequency: frequency,
|
59
|
+
title: title,
|
60
|
+
subscriber_id: subscriber_id,
|
61
|
+
subscriber_list_id: subscriber_list_id,
|
62
|
+
ended: ended,
|
63
|
+
).to_json
|
64
|
+
|
56
65
|
stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}")
|
57
|
-
.to_return(
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
.to_return(status: 200, body: response)
|
67
|
+
stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}/latest")
|
68
|
+
.to_return(status: 200, body: response)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Stubs the API responses as if each subscription happened in the order they are passed.
|
72
|
+
# Useful if you need to query the '/latest' endpoint of a subscription.
|
73
|
+
# Takes an array of hashes.
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# stub_email_alert_api_has_subscriptions([
|
77
|
+
# {
|
78
|
+
# id: 'id-of-my-subscriber-list',
|
79
|
+
# frequency: 'weekly',
|
80
|
+
# ended: true,
|
81
|
+
# },
|
82
|
+
# {
|
83
|
+
# id: 'id-of-my-subscriber-list',
|
84
|
+
# frequency: 'daily',
|
85
|
+
# },
|
86
|
+
# ])
|
87
|
+
#
|
88
|
+
# @param subscriptions [Array]
|
89
|
+
def stub_email_alert_api_has_subscriptions(subscriptions)
|
90
|
+
subscriptions.map! { |subscription| apply_subscription_defaults(subscription) }
|
91
|
+
subscriptions.each do |id, params|
|
92
|
+
latest_id, latest_params = get_latest_matching(params, subscriptions)
|
93
|
+
stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}")
|
94
|
+
.to_return(status: 200, body: get_subscription_response(id, params).to_json)
|
95
|
+
stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}/latest")
|
96
|
+
.to_return(status: 200, body: get_subscription_response(latest_id, latest_params).to_json)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def apply_subscription_defaults(subscription)
|
101
|
+
parameters = {
|
102
|
+
title: "Some title",
|
103
|
+
subscriber_id: 1,
|
104
|
+
subscriber_list_id: 1000,
|
105
|
+
ended: true,
|
106
|
+
}.merge(subscription)
|
107
|
+
# Strip out ID as subsequent call to `get_subscription_response` throws `ArgumentError`
|
108
|
+
id = parameters.delete(:id)
|
109
|
+
[id, parameters]
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_latest_matching(params, subscriptions)
|
113
|
+
matching = subscriptions.select do |_current_id, current_params|
|
114
|
+
params[:subscriber_id] == current_params[:subscriber_id] &&
|
115
|
+
params[:subscriber_list_id] == current_params[:subscriber_list_id]
|
116
|
+
end
|
117
|
+
matching.last
|
68
118
|
end
|
69
119
|
|
70
120
|
def stub_email_alert_api_has_subscriber_list(attributes)
|
@@ -227,6 +277,7 @@ module GdsApi
|
|
227
277
|
alias_method :email_alert_api_has_subscriber_subscriptions, :stub_email_alert_api_has_subscriber_subscriptions
|
228
278
|
alias_method :email_alert_api_does_not_have_subscriber_subscriptions, :stub_email_alert_api_does_not_have_subscriber_subscriptions
|
229
279
|
alias_method :email_alert_api_has_subscription, :stub_email_alert_api_has_subscription
|
280
|
+
alias_method :email_alert_api_has_subscriptions, :stub_email_alert_api_has_subscriptions
|
230
281
|
alias_method :email_alert_api_has_subscriber_list, :stub_email_alert_api_has_subscriber_list
|
231
282
|
alias_method :email_alert_api_does_not_have_subscriber_list, :stub_email_alert_api_does_not_have_subscriber_list
|
232
283
|
alias_method :email_alert_api_creates_subscriber_list, :stub_email_alert_api_creates_subscriber_list
|
@@ -270,7 +321,7 @@ module GdsApi
|
|
270
321
|
"id" => id,
|
271
322
|
"frequency" => frequency,
|
272
323
|
"source" => "user_signed_up",
|
273
|
-
"ended_at" => ended ? Time.now.rfc3339 : nil,
|
324
|
+
"ended_at" => ended ? Time.now.to_datetime.rfc3339 : nil,
|
274
325
|
"ended_reason" => ended ? "unsubscribed" : nil,
|
275
326
|
"subscriber" => {
|
276
327
|
"id" => subscriber_id,
|
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: 59.
|
4
|
+
version: 59.4.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: 2019-05-
|
11
|
+
date: 2019-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|