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


172
173
174
175
176
177
178
179
180
181
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 172

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_email_alert_api_message_created(attributes = nil) ⇒ Object


183
184
185
186
187
188
189
190
191
192
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 183

def assert_email_alert_api_message_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}/messages", times: 1, &matcher)
end

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


386
387
388
389
390
391
392
393
394
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 386

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: subscriber_list_id,
      address: address,
      frequency: frequency,
    }
  end
end

#assert_unsubscribed(uuid) ⇒ Object


382
383
384
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 382

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


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

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


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

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_accepts_messageObject


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

def stub_email_alert_api_accepts_message
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/messages")
    .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


291
292
293
294
295
296
297
298
299
300
301
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 291

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


312
313
314
315
316
317
318
319
320
321
322
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 312

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


324
325
326
327
328
329
330
331
332
333
334
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 324

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


303
304
305
306
307
308
309
310
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 303

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


411
412
413
414
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 411

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


459
460
461
462
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 459

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:, govuk_request_id:, body:, sender_message_id:) ⇒ Object


464
465
466
467
468
469
470
471
472
473
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 464

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

#stub_email_alert_api_bulk_unsubscribe_conflict(slug:) ⇒ Object


443
444
445
446
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 443

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:, govuk_request_id:, body:, sender_message_id:) ⇒ Object


448
449
450
451
452
453
454
455
456
457
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 448

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

#stub_email_alert_api_bulk_unsubscribe_not_found(slug:) ⇒ Object


427
428
429
430
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 427

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:, govuk_request_id:, body:, sender_message_id:) ⇒ Object


432
433
434
435
436
437
438
439
440
441
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 432

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

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


416
417
418
419
420
421
422
423
424
425
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 416

def stub_email_alert_api_bulk_unsubscribe_with_message(slug:, govuk_request_id:, body:, sender_message_id:)
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
  .with(
    body: {
      body: body,
      sender_message_id: sender_message_id,
    }.to_json,
    headers: { "Govuk-Request-Id" => 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


216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 216

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: frequency,
    subscriber_list_id: subscriber_list_id,
    subscriber_id: subscriber_id,
  )

  request_params = {
    subscriber_list_id: subscriber_list_id,
    address: address,
    frequency: frequency,
    skip_confirmation_email: 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


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

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


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

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


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

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


211
212
213
214
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 211

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


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

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


396
397
398
399
400
401
402
403
404
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 396

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: 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: frequency,
    title: title,
    subscriber_id: subscriber_id,
    subscriber_list_id: subscriber_list_id,
    ended: 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: 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

336
337
338
339
340
341
342
343
344
345
346
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 336

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

357
358
359
360
361
362
363
364
365
366
367
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 357

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

348
349
350
351
352
353
354
355
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 348

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


243
244
245
246
247
248
249
250
251
252
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 243

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: subscriber_list_id,
        address: address,
        frequency: frequency,
      ),
    ).to_return(status: 422)
end

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


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

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


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

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: address, frequency: frequency, topic_id: topic_id }.to_json,
    ).to_return(status: 200)
end

#stub_email_alert_api_subscriber_verification_email_invalidObject


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

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


286
287
288
289
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 286

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


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

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


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

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: address, frequency: frequency, topic_id: topic_id }.to_json,
    ).to_return(status: 422)
end

#stub_email_alert_api_unsubscribes_a_subscriber(subscriber_id) ⇒ Object


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

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


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

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_update_subscriber_list_details(slug:, params:) ⇒ Object


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

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


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

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


490
491
492
493
494
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 490

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