Skip to content

Commit

Permalink
Add test helpers for subscriber list metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
peteglondon committed Jan 9, 2024
1 parent 22a0a7c commit 45c8313
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/gds_api/test_helpers/email_alert_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ def stub_any_email_alert_api_call
stub_request(:any, %r{\A#{EMAIL_ALERT_API_ENDPOINT}})
end

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

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

def assert_email_alert_api_content_change_created(attributes = nil)
if attributes
matcher = lambda do |request|
Expand Down
20 changes: 20 additions & 0 deletions test/test_helpers/email_alert_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,24 @@
assert_equal(2, result["subscriptions"].count)
end
end

describe "#stub_get_subscriber_list_metrics_not_found" do
it "raises 404" do
stub_get_subscriber_list_metrics_not_found(path: "/some/path")
assert_raises(GdsApi::HTTPNotFound) do
email_alert_api.get_subscriber_list_metrics(path: "/some/path")
end
end
end

describe "#stub_get_subscriber_list_metrics" do
it "returns the stubbed data" do
json = { subscriber_list_count: 3, all_notify_count: 10 }.to_json
stub_get_subscriber_list_metrics(path: "/some/path", response: json)
response = email_alert_api.get_subscriber_list_metrics(path: "/some/path")
expected = { "subscriber_list_count" => 3, "all_notify_count" => 10 }
assert_equal 200, response.code
assert_equal expected, response.to_h
end
end
end

0 comments on commit 45c8313

Please sign in to comment.