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

Add update_subscriber_list_details (for Email Alert API) #1131

Merged
merged 1 commit into from Jan 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,9 @@
# unreleased
# 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)
* Add `update_subscriber_list_details` (for Email Alert API)

# 78.1.0

Expand Down
11 changes: 11 additions & 0 deletions lib/gds_api/email_alert_api.rb
Expand Up @@ -267,6 +267,17 @@ def bulk_unsubscribe(slug:, govuk_request_id: nil, body: nil, sender_message_id:
)
end

# Update subscriber list details, such as title
# @param [Hash] params A hash of detail paramaters that can be updated. For example title.
# For allowed parameters see:
# https://github.com/alphagov/email-alert-api/blob/main/docs/api.md#patch-subscriber-listsxxx
huwd marked this conversation as resolved.
Show resolved Hide resolved
def update_subscriber_list_details(slug:, params: {})
patch_json(
"#{endpoint}/subscriber-lists/#{slug}",
params,
)
end

private

def nested_query_string(params)
Expand Down
21 changes: 21 additions & 0 deletions lib/gds_api/test_helpers/email_alert_api.rb
Expand Up @@ -472,6 +472,27 @@ def stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(slug:, govuk_
).to_return(status: 422)
end

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

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

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
barrucadu marked this conversation as resolved.
Show resolved Hide resolved

private

def get_subscriber_response(id, address, govuk_account_id)
Expand Down
33 changes: 33 additions & 0 deletions test/email_alert_api_test.rb
Expand Up @@ -909,4 +909,37 @@
end
end
end

describe "update_subscriber_list_details" do
let(:slug) { "i_am_a_subscriber_list_slug" }

it "returns 200 and subscriber list with updated title" do
params = { "title" => "New Title" }

stub_update_subscriber_list_details(slug: slug, params: params)
api_response = api_client.update_subscriber_list_details(slug: slug, params: params)

assert_equal(200, api_response.code)
assert_equal(params["title"], api_response.to_h.dig("subscriber_list", "title"))
end

it "returns 404 when subscriber list is not found" do
params = { "title" => "New Title" }

stub_update_subscriber_list_details_not_found(slug: slug, params: params)

assert_raises GdsApi::HTTPNotFound do
api_client.update_subscriber_list_details(slug: slug, params: params)
end
end

it "returns 422 when provided with invalid parameters" do
params = { "title" => nil }
stub_update_subscriber_list_details_unprocessible_entity(slug: slug, params: params)

assert_raises GdsApi::HTTPUnprocessableEntity do
api_client.update_subscriber_list_details(slug: slug, params: params)
end
end
end
end