Module: GdsApi::TestHelpers::EmailAlertApi

Defined in:
lib/gds_api/test_helpers/email_alert_api.rb

Constant Summary collapse

EMAIL_ALERT_API_ENDPOINT =
Plek.find("email-alert-api")

Instance Method Summary collapse

Instance Method Details

#apply_subscription_defaults(subscription) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 107

def apply_subscription_defaults(subscription)
  parameters = {
    title: "Some title",
    subscriber_id: 1,
    subscriber_list_id: 1000,
    ended: true,
  }.merge(subscription)
  # Strip out ID as subsequent call to `get_subscription_response` throws `ArgumentError`
  id = parameters.delete(:id)
  [id, parameters]
end

#assert_email_alert_api_content_change_created(attributes = nil) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 177

def assert_email_alert_api_content_change_created(attributes = nil)
  if attributes
    matcher = lambda do |request|
      payload = JSON.parse(request.body)
      payload.select { |k, _| attributes.key?(k) } == attributes
    end
  end

  assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/content-changes", times: 1, &matcher)
end

#assert_subscribed(subscriber_list_id, address, frequency = "immediately") ⇒ Object



380
381
382
383
384
385
386
387
388
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 380

def assert_subscribed(subscriber_list_id, address, frequency = "immediately")
  assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions") do |req|
    JSON.parse(req.body).symbolize_keys == {
      subscriber_list_id:,
      address:,
      frequency:,
    }
  end
end

#assert_unsubscribed(uuid) ⇒ Object



376
377
378
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 376

def assert_unsubscribed(uuid)
  assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}", times: 1)
end

#get_latest_matching(params, subscriptions) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 119

def get_latest_matching(params, subscriptions)
  matching = subscriptions.select do |_current_id, current_params|
    params[:subscriber_id] == current_params[:subscriber_id] &&
      params[:subscriber_list_id] == current_params[:subscriber_list_id]
  end
  matching.last
end

#stub_any_email_alert_api_callObject



163
164
165
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 163

def stub_any_email_alert_api_call
  stub_request(:any, %r{\A#{EMAIL_ALERT_API_ENDPOINT}})
end

#stub_email_alert_api_accepts_content_changeObject



153
154
155
156
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 153

def stub_email_alert_api_accepts_content_change
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/content-changes")
    .to_return(status: 202, body: {}.to_json)
end

#stub_email_alert_api_accepts_emailObject



158
159
160
161
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 158

def stub_email_alert_api_accepts_email
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/emails")
    .to_return(status: 202, body: {}.to_json)
end

#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) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 285

def (, subscriber_id, address, govuk_account_id: "user-id", new_govuk_account_session: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
    .with(
      body: { govuk_account_session: }.to_json,
    ).to_return(
      status: 200,
      body: {
        govuk_account_session: ,
      }.compact.merge(get_subscriber_response(subscriber_id, address, )).to_json,
    )
end

#stub_email_alert_api_authenticate_subscriber_by_govuk_account_email_unverified(govuk_account_session, new_govuk_account_session: nil) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 306

def (, new_govuk_account_session: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
    .with(
      body: { govuk_account_session: }.to_json,
    ).to_return(
      status: 403,
      body: {
        govuk_account_session: ,
      }.compact.to_json,
    )
end

#stub_email_alert_api_authenticate_subscriber_by_govuk_account_no_subscriber(govuk_account_session, new_govuk_account_session: nil) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 318

def (, new_govuk_account_session: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
    .with(
      body: { govuk_account_session: }.to_json,
    ).to_return(
      status: 404,
      body: {
        govuk_account_session: ,
      }.compact.to_json,
    )
end

#stub_email_alert_api_authenticate_subscriber_by_govuk_account_session_invalid(govuk_account_session) ⇒ Object



297
298
299
300
301
302
303
304
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 297

def ()
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
    .with(
      body: { govuk_account_session: }.to_json,
    ).to_return(
      status: 401,
    )
end

#stub_email_alert_api_bulk_unsubscribe(slug:) ⇒ Object



405
406
407
408
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 405

def stub_email_alert_api_bulk_unsubscribe(slug:)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
    .to_return(status: 202)
end

#stub_email_alert_api_bulk_unsubscribe_bad_request(slug:) ⇒ Object



453
454
455
456
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 453

def stub_email_alert_api_bulk_unsubscribe_bad_request(slug:)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
    .to_return(status: 422)
end

#stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil) ⇒ Object



458
459
460
461
462
463
464
465
466
467
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 458

def stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
  .with({
    body: {
      body:,
      sender_message_id:,
    }.to_json,
  }.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
  .to_return(status: 422)
end

#stub_email_alert_api_bulk_unsubscribe_conflict(slug:) ⇒ Object



437
438
439
440
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 437

def stub_email_alert_api_bulk_unsubscribe_conflict(slug:)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
    .to_return(status: 409)
end

#stub_email_alert_api_bulk_unsubscribe_conflict_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil) ⇒ Object



442
443
444
445
446
447
448
449
450
451
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 442

def stub_email_alert_api_bulk_unsubscribe_conflict_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
  .with({
    body: {
      body:,
      sender_message_id:,
    }.to_json,
  }.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
  .to_return(status: 409)
end

#stub_email_alert_api_bulk_unsubscribe_not_found(slug:) ⇒ Object



421
422
423
424
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 421

def stub_email_alert_api_bulk_unsubscribe_not_found(slug:)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
    .to_return(status: 404)
end

#stub_email_alert_api_bulk_unsubscribe_not_found_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil) ⇒ Object



426
427
428
429
430
431
432
433
434
435
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 426

def stub_email_alert_api_bulk_unsubscribe_not_found_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
  .with({
    body: {
      body:,
      sender_message_id:,
    }.to_json,
  }.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
  .to_return(status: 404)
end

#stub_email_alert_api_bulk_unsubscribe_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil) ⇒ Object



410
411
412
413
414
415
416
417
418
419
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 410

def stub_email_alert_api_bulk_unsubscribe_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
  .with({
    body: {
      body:,
      sender_message_id:,
    }.to_json,
  }.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
  .to_return(status: 202)
end

#stub_email_alert_api_creates_a_subscription(subscriber_list_id: nil, address: nil, frequency: nil, returned_subscription_id: nil, skip_confirmation_email: false, subscriber_id: nil) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 210

def stub_email_alert_api_creates_a_subscription(
  subscriber_list_id: nil,
  address: nil,
  frequency: nil,
  returned_subscription_id: nil,
  skip_confirmation_email: false,
  subscriber_id: nil
)
  response = get_subscription_response(
    returned_subscription_id,
    frequency:,
    subscriber_list_id:,
    subscriber_id:,
  )

  request_params = {
    subscriber_list_id:,
    address:,
    frequency:,
    skip_confirmation_email:,
  }

  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions")
    .with(body: hash_including(request_params.compact))
    .to_return(status: 200, body: response.to_json)
end

#stub_email_alert_api_creates_subscriber_list(attributes) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 127

def stub_email_alert_api_creates_subscriber_list(attributes)
  stub_request(:post, build_subscriber_lists_url)
    .to_return(
      status: 201,
      body: get_subscriber_list_response(attributes).to_json,
    )
end

#stub_email_alert_api_does_not_have_subscriber_list(attributes) ⇒ Object



143
144
145
146
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 143

def stub_email_alert_api_does_not_have_subscriber_list(attributes)
  stub_request(:get, build_subscriber_lists_url(attributes))
    .to_return(status: 404)
end

#stub_email_alert_api_does_not_have_subscriber_list_by_slug(slug:) ⇒ Object



400
401
402
403
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 400

def stub_email_alert_api_does_not_have_subscriber_list_by_slug(slug:)
  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}")
    .to_return(status: 404)
end

#stub_email_alert_api_does_not_have_subscriber_subscriptions(id) ⇒ Object



50
51
52
53
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 50

def stub_email_alert_api_does_not_have_subscriber_subscriptions(id)
  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}/subscriptions")
    .to_return(status: 404)
end

#stub_email_alert_api_does_not_have_updated_subscriber(id) ⇒ Object



17
18
19
20
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 17

def stub_email_alert_api_does_not_have_updated_subscriber(id)
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}")
    .to_return(status: 404)
end

#stub_email_alert_api_does_not_have_updated_subscription(subscription_id) ⇒ Object



35
36
37
38
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 35

def stub_email_alert_api_does_not_have_updated_subscription(subscription_id)
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{subscription_id}")
    .to_return(status: 404)
end

#stub_email_alert_api_find_subscriber_by_govuk_account(govuk_account_id, subscriber_id, address) ⇒ Object



363
364
365
366
367
368
369
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 363

def (, subscriber_id, address)
  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/#{}")
    .to_return(
      status: 200,
      body: get_subscriber_response(subscriber_id, address, ).to_json,
    )
end

#stub_email_alert_api_find_subscriber_by_govuk_account_no_subscriber(govuk_account_id) ⇒ Object



371
372
373
374
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 371

def ()
  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/#{}")
    .to_return(status: 404)
end

#stub_email_alert_api_has_no_subscriber(subscriber_id) ⇒ Object



205
206
207
208
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 205

def stub_email_alert_api_has_no_subscriber(subscriber_id)
  stub_request(:delete, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{subscriber_id}")
    .to_return(status: 404)
end

#stub_email_alert_api_has_no_subscription_for_uuid(uuid) ⇒ Object



194
195
196
197
198
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 194

def stub_email_alert_api_has_no_subscription_for_uuid(uuid)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}")
    .with(body: "{}")
    .to_return(status: 404)
end

#stub_email_alert_api_has_subscriber_list(attributes) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 135

def stub_email_alert_api_has_subscriber_list(attributes)
  stub_request(:get, build_subscriber_lists_url(attributes))
    .to_return(
      status: 200,
      body: get_subscriber_list_response(attributes).to_json,
    )
end

#stub_email_alert_api_has_subscriber_list_by_slug(slug:, returned_attributes:) ⇒ Object



390
391
392
393
394
395
396
397
398
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 390

def stub_email_alert_api_has_subscriber_list_by_slug(slug:, returned_attributes:)
  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}")
    .to_return(
      status: 200,
      body: {
        subscriber_list: returned_attributes,
      }.to_json,
    )
end

#stub_email_alert_api_has_subscriber_subscriptions(id, address, order = nil, subscriptions: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 40

def stub_email_alert_api_has_subscriber_subscriptions(id, address, order = nil, subscriptions: nil)
  params = order ? "?order=#{order}" : ""

  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}/subscriptions#{params}")
    .to_return(
      status: 200,
      body: get_subscriber_subscriptions_response(id, address, subscriptions:).to_json,
    )
end

#stub_email_alert_api_has_subscription(id, frequency, title: "Some title", subscriber_id: 1, subscriber_list_id: 1000, ended: false) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 55

def stub_email_alert_api_has_subscription(
  id,
  frequency,
  title: "Some title",
  subscriber_id: 1,
  subscriber_list_id: 1000,
  ended: false
)
  response = get_subscription_response(
    id,
    frequency:,
    title:,
    subscriber_id:,
    subscriber_list_id:,
    ended:,
  ).to_json

  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}")
    .to_return(status: 200, body: response)
  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}/latest")
    .to_return(status: 200, body: response)
end

#stub_email_alert_api_has_subscriptions(subscriptions) ⇒ Object

Stubs the API responses as if each subscription happened in the order they are passed. Useful if you need to query the ‘/latest’ endpoint of a subscription. Takes an array of hashes.

Examples:

stub_email_alert_api_has_subscriptions([
  {
    id: 'id-of-my-subscriber-list',
    frequency: 'weekly',
    ended: true,
  },
  {
    id: 'id-of-my-subscriber-list',
    frequency: 'daily',
  },
])

Parameters:

  • subscriptions (Array)


96
97
98
99
100
101
102
103
104
105
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 96

def stub_email_alert_api_has_subscriptions(subscriptions)
  subscriptions.map! { |subscription| apply_subscription_defaults(subscription) }
  subscriptions.each do |id, params|
    latest_id, latest_params = get_latest_matching(params, subscriptions)
    stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}")
      .to_return(status: 200, body: get_subscription_response(id, **params).to_json)
    stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}/latest")
      .to_return(status: 200, body: get_subscription_response(latest_id, **latest_params).to_json)
  end
end

#stub_email_alert_api_has_updated_subscriber(id, new_address, govuk_account_id: nil) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 9

def stub_email_alert_api_has_updated_subscriber(id, new_address, govuk_account_id: nil)
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}")
    .to_return(
      status: 200,
      body: get_subscriber_response(id, new_address, ).to_json,
    )
end

#stub_email_alert_api_has_updated_subscription(subscription_id, frequency) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 27

def stub_email_alert_api_has_updated_subscription(subscription_id, frequency)
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{subscription_id}")
    .to_return(
      status: 200,
      body: get_subscription_response(subscription_id, frequency:).to_json,
    )
end

#stub_email_alert_api_invalid_update_subscriber(id) ⇒ Object



22
23
24
25
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 22

def stub_email_alert_api_invalid_update_subscriber(id)
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}")
    .to_return(status: 422)
end


330
331
332
333
334
335
336
337
338
339
340
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 330

def (, subscriber_id, address, govuk_account_id: "user-id", new_govuk_account_session: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
    .with(
      body: { govuk_account_session: }.to_json,
    ).to_return(
      status: 200,
      body: {
        govuk_account_session: ,
      }.compact.merge(get_subscriber_response(subscriber_id, address, )).to_json,
    )
end


351
352
353
354
355
356
357
358
359
360
361
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 351

def (, new_govuk_account_session: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
    .with(
      body: { govuk_account_session: }.to_json,
    ).to_return(
      status: 403,
      body: {
        govuk_account_session: ,
      }.compact.to_json,
    )
end


342
343
344
345
346
347
348
349
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 342

def ()
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account/link")
    .with(
      body: { govuk_account_session: }.to_json,
    ).to_return(
      status: 401,
    )
end

#stub_email_alert_api_refuses_to_create_subscriber_listObject



148
149
150
151
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 148

def stub_email_alert_api_refuses_to_create_subscriber_list
  stub_request(:post, build_subscriber_lists_url)
    .to_return(status: 422)
end

#stub_email_alert_api_refuses_to_create_subscription(subscriber_list_id, address, frequency) ⇒ Object



237
238
239
240
241
242
243
244
245
246
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 237

def stub_email_alert_api_refuses_to_create_subscription(subscriber_list_id, address, frequency)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions")
    .with(
      body: hash_including(
        subscriber_list_id:,
        address:,
        frequency:,
      ),
    ).to_return(status: 422)
end

#stub_email_alert_api_sends_subscriber_verification_email(subscriber_id, address, govuk_account_id: nil) ⇒ Object



262
263
264
265
266
267
268
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 262

def stub_email_alert_api_sends_subscriber_verification_email(subscriber_id, address, govuk_account_id: nil)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
    .to_return(
      status: 201,
      body: get_subscriber_response(subscriber_id, address, ).to_json,
    )
end

#stub_email_alert_api_sends_subscription_verification_email(address, frequency, topic_id) ⇒ Object



248
249
250
251
252
253
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 248

def stub_email_alert_api_sends_subscription_verification_email(address, frequency, topic_id)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/auth-token")
    .with(
      body: { address:, frequency:, topic_id: }.to_json,
    ).to_return(status: 200)
end

#stub_email_alert_api_subscriber_verification_email_invalidObject



270
271
272
273
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 270

def stub_email_alert_api_subscriber_verification_email_invalid
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
    .to_return(status: 422)
end

#stub_email_alert_api_subscriber_verification_email_linked_to_govuk_accountObject



280
281
282
283
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 280

def 
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
    .to_return(status: 403)
end

#stub_email_alert_api_subscriber_verification_email_no_subscriberObject



275
276
277
278
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 275

def stub_email_alert_api_subscriber_verification_email_no_subscriber
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
    .to_return(status: 404)
end

#stub_email_alert_api_subscription_verification_email_invalid(address, frequency, topic_id) ⇒ Object



255
256
257
258
259
260
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 255

def stub_email_alert_api_subscription_verification_email_invalid(address, frequency, topic_id)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/auth-token")
    .with(
      body: { address:, frequency:, topic_id: }.to_json,
    ).to_return(status: 422)
end

#stub_email_alert_api_unsubscribes_a_subscriber(subscriber_id) ⇒ Object



200
201
202
203
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 200

def stub_email_alert_api_unsubscribes_a_subscriber(subscriber_id)
  stub_request(:delete, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{subscriber_id}")
    .to_return(status: 204)
end

#stub_email_alert_api_unsubscribes_a_subscription(uuid) ⇒ Object



188
189
190
191
192
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 188

def stub_email_alert_api_unsubscribes_a_subscription(uuid)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}")
    .with(body: "{}")
    .to_return(status: 204)
end

#stub_get_subscriber_list_metrics(path:, response:) ⇒ Object



167
168
169
170
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 167

def stub_get_subscriber_list_metrics(path:, response:)
  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/metrics#{path}")
    .to_return(status: 200, body: response)
end

#stub_get_subscriber_list_metrics_not_found(path:) ⇒ Object



172
173
174
175
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 172

def stub_get_subscriber_list_metrics_not_found(path:)
  stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/metrics#{path}")
    .to_return(status: 404)
end

#stub_update_subscriber_list_details(slug:, params:) ⇒ Object



469
470
471
472
473
474
475
476
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 469

def stub_update_subscriber_list_details(slug:, params:)
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}")
  .with(body: params.to_json)
  .to_return(
    status: 200,
    body: get_subscriber_list_response(params).to_json,
  )
end

#stub_update_subscriber_list_details_not_found(slug:, params:) ⇒ Object



478
479
480
481
482
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 478

def stub_update_subscriber_list_details_not_found(slug:, params:)
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}")
  .with(body: params.to_json)
  .to_return(status: 404)
end

#stub_update_subscriber_list_details_unprocessible_entity(slug:, params: {}) ⇒ Object



484
485
486
487
488
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 484

def stub_update_subscriber_list_details_unprocessible_entity(slug:, params: {})
  stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}")
  .with(body: params.to_json)
  .to_return(status: 422)
end