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

#assert_email_alert_sent(attributes = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 64

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

  assert_requested(:post, notifications_url, times: 1, &matcher)
end

#email_alert_api_accepts_alertObject



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

def email_alert_api_accepts_alert
  stub_request(:post, notifications_url)
    .to_return(
      :status => 202,
      :body => {}.to_json,
    )
end

#email_alert_api_creates_subscriber_list(attributes) ⇒ Object



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

def email_alert_api_creates_subscriber_list(attributes)
  stub_request(:post, subscriber_lists_url)
    .to_return(
      :status => 201,
      :body => get_subscriber_list_response(attributes).to_json,
    )
end

#email_alert_api_does_not_have_subscriber_list(attributes) ⇒ Object



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

def email_alert_api_does_not_have_subscriber_list(attributes)
  stub_request(:get, subscriber_lists_url(attributes))
    .to_return(status: 404)
end

#email_alert_api_has_subscriber_list(attributes) ⇒ Object



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

def email_alert_api_has_subscriber_list(attributes)
  stub_request(:get, subscriber_lists_url(attributes))
    .to_return(
      :status => 200,
      :body => get_subscriber_list_response(attributes).to_json,
    )
end

#email_alert_api_refuses_to_create_subscriber_listObject



30
31
32
33
34
35
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 30

def email_alert_api_refuses_to_create_subscriber_list
  stub_request(:post, subscriber_lists_url)
    .to_return(
      :status => 422,
    )
end

#get_subscriber_list_response(attributes) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 37

def get_subscriber_list_response(attributes)
  {
    "subscriber_list" => {
      "id" => "447135c3-07d6-4c3a-8a3b-efa49ef70e52",
      "subscription_url" => "https://stage-public.govdelivery.com/accounts/UKGOVUK/subscriber/new?topic_id=UKGOVUK_1234",
      "gov_delivery_id" => "UKGOVUK_1234",
      "title" => "Some title",
    }.merge(attributes)
  }
end

#post_alert_responseObject



56
57
58
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 56

def post_alert_response
  {}
end

#stub_any_email_alert_api_callObject



60
61
62
# File 'lib/gds_api/test_helpers/email_alert_api.rb', line 60

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