Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Three improvements to the email-alert-api test helpers #1132

Merged
merged 3 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# unreleased

* Add both with- and without-message variants for bulk unsubscribe test helpers (for Email Alert API)
* BREAKING: Add `sender_message_id` and `govuk_request_id` to bulk unsubscribe (bad request) test helper (for Email Alert API)
* Add `content_id` to subscriber lists URL helper (for Email Alert API)

# 78.1.0

* Fix `bulk_unsubscribe` requires a `govuk_request_id` if you want to send a message
Expand Down
20 changes: 18 additions & 2 deletions lib/gds_api/test_helpers/email_alert_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ def stub_email_alert_api_bulk_unsubscribe_not_found_with_message(slug:, govuk_re
).to_return(status: 404)
end

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

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(
Expand All @@ -451,10 +456,19 @@ def stub_email_alert_api_bulk_unsubscribe_conflict_with_message(slug:, govuk_req
).to_return(status: 409)
end

def stub_email_alert_api_bulk_unsubscribe_bad_request(slug:, body:)
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

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 }.to_json,
body: {
body: body,
sender_message_id: sender_message_id,
}.to_json,
headers: { "Govuk-Request-Id" => govuk_request_id },
).to_return(status: 422)
end

Expand Down Expand Up @@ -537,6 +551,7 @@ def build_subscriber_lists_url(attributes = nil)
if attributes
tags = attributes["tags"]
links = attributes["links"]
content_id = attributes["content_id"]
document_type = attributes["document_type"]
email_document_supertype = attributes["email_document_supertype"]
government_document_supertype = attributes["government_document_supertype"]
Expand All @@ -546,6 +561,7 @@ def build_subscriber_lists_url(attributes = nil)
params = {}
params[:tags] = tags if tags
params[:links] = links if links
params[:content_id] = content_id if content_id
params[:document_type] = document_type if document_type
params[:email_document_supertype] = email_document_supertype if email_document_supertype
params[:government_document_supertype] = government_document_supertype if government_document_supertype
Expand Down
32 changes: 28 additions & 4 deletions test/email_alert_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,14 @@
end
end

it "returns 409 if a message has already been received" do
it "returns 409 on conflict" do
stub_email_alert_api_bulk_unsubscribe_conflict(slug: slug)
assert_raises GdsApi::HTTPConflict do
api_client.bulk_unsubscribe(slug: slug)
end
end

it "returns 409 on conflict if a message is provided" do
stub_email_alert_api_bulk_unsubscribe_conflict_with_message(
slug: slug,
govuk_request_id: "govuk_request_id",
Expand All @@ -878,10 +885,27 @@
end
end

it "returns 422 if a body is sent without a sender_message_id" do
stub_email_alert_api_bulk_unsubscribe_bad_request(slug: slug, body: body)
it "returns 422 on bad request" do
stub_email_alert_api_bulk_unsubscribe_bad_request(slug: slug)
assert_raises GdsApi::HTTPUnprocessableEntity do
api_client.bulk_unsubscribe(slug: slug, body: body)
api_client.bulk_unsubscribe(slug: slug)
end
end

it "returns 422 on bad request if a message is provided" do
stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(
slug: slug,
govuk_request_id: "govuk_request_id",
body: body,
sender_message_id: sender_message_id,
)
assert_raises GdsApi::HTTPUnprocessableEntity do
api_client.bulk_unsubscribe(
slug: slug,
govuk_request_id: "govuk_request_id",
body: body,
sender_message_id: sender_message_id,
)
end
end
end
Expand Down