diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e9d4bde..009ff33a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# Unreleased + +* BREAKING: Remove Account API `get_email_subscription` method and helpers +* BREAKING: Remove Account API `put_email_subscription` method and helpers +* BREAKING: Remove Account API `delete_email_subscription` method and helpers +* Note: These are no longer used by any apps, so should not be breaking in practice. + # 90.0.0 * BREAKING: Change source for `GdsApi.worldwide.organisations_for_world_location` method, remove pagination and remove `stub_worldwide_api_has_organisations_for_location` method. diff --git a/lib/gds_api/account_api.rb b/lib/gds_api/account_api.rb index 7820ae50..837dcf57 100644 --- a/lib/gds_api/account_api.rb +++ b/lib/gds_api/account_api.rb @@ -107,35 +107,6 @@ def set_attributes(attributes:, govuk_account_session:) patch_json("#{endpoint}/api/attributes", { attributes: attributes }, auth_headers(govuk_account_session)) end - # Get the details of an account-linked email subscription. - # - # @param [String] name Name of the subscription - # @param [String] govuk_account_session Value of the session header - # - # @return [Hash] Details of the subscription, if it exists. - def get_email_subscription(name:, govuk_account_session:) - get_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", auth_headers(govuk_account_session)) - end - - # Create or update an account-linked email subscription. - # - # @param [String] name Name of the subscription - # @param [String] topic_slug The email-alert-api topic slug to subscribe to - # @param [String] govuk_account_session Value of the session header - # - # @return [Hash] Details of the newly created subscription. - def put_email_subscription(name:, topic_slug:, govuk_account_session:) - put_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", { topic_slug: topic_slug }, auth_headers(govuk_account_session)) - end - - # Unsubscribe and delete an account-linked email subscription. - # - # @param [String] name Name of the subscription - # @param [String] govuk_account_session Value of the session header - def delete_email_subscription(name:, govuk_account_session:) - delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session)) - end - private def nested_query_string(params) diff --git a/lib/gds_api/test_helpers/account_api.rb b/lib/gds_api/test_helpers/account_api.rb index e383e843..95804efd 100644 --- a/lib/gds_api/test_helpers/account_api.rb +++ b/lib/gds_api/test_helpers/account_api.rb @@ -172,100 +172,6 @@ def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, emai ) end - #################################### - # GET /api/email-subscriptions/:name - #################################### - def stub_account_api_get_email_subscription(name:, topic_slug: "slug", email_alert_api_subscription_id: "12345", **options) - stub_account_api_request( - :get, - "/api/email-subscriptions/#{name}", - response_body: { - email_subscription: { - name: name, - topic_slug: topic_slug, - email_alert_api_subscription_id: email_alert_api_subscription_id, - }, - }, - **options, - ) - end - - def stub_account_api_get_email_subscription_does_not_exist(name:, **options) - stub_account_api_request( - :get, - "/api/email-subscriptions/#{name}", - response_status: 404, - **options, - ) - end - - def stub_account_api_unauthorized_get_email_subscription(name:, **options) - stub_account_api_request( - :get, - "/api/email-subscriptions/#{name}", - response_status: 401, - **options, - ) - end - - #################################### - # PUT /api/email-subscriptions/:name - #################################### - def stub_account_api_put_email_subscription(name:, topic_slug: nil, **options) - stub_account_api_request( - :put, - "/api/email-subscriptions/#{name}", - with: { body: hash_including({ topic_slug: topic_slug }.compact) }, - response_body: { - email_subscription: { - name: name, - topic_slug: topic_slug || "slug", - }, - }, - **options, - ) - end - - def stub_account_api_unauthorized_put_email_subscription(name:, topic_slug: nil, **options) - stub_account_api_request( - :put, - "/api/email-subscriptions/#{name}", - with: { body: hash_including({ topic_slug: topic_slug }.compact) }, - response_status: 401, - **options, - ) - end - - ####################################### - # DELETE /api/email-subscriptions/:name - ####################################### - def stub_account_api_delete_email_subscription(name:, **options) - stub_account_api_request( - :delete, - "/api/email-subscriptions/#{name}", - response_status: 204, - **options, - ) - end - - def stub_account_api_delete_email_subscription_does_not_exist(name:, **options) - stub_account_api_request( - :delete, - "/api/email-subscriptions/#{name}", - response_status: 404, - **options, - ) - end - - def stub_account_api_unauthorized_delete_email_subscription(name:, **options) - stub_account_api_request( - :delete, - "/api/email-subscriptions/#{name}", - response_status: 401, - **options, - ) - end - ##################### # GET /api/attributes ##################### diff --git a/test/account_api_test.rb b/test/account_api_test.rb index 59d56b8f..c38ae642 100644 --- a/test/account_api_test.rb +++ b/test/account_api_test.rb @@ -111,43 +111,6 @@ end end - describe "email subscriptions" do - describe "#get_email_subscription" do - it "returns the subscription details if it exists" do - stub_account_api_get_email_subscription(name: "foo") - assert(!api_client.get_email_subscription(name: "foo", govuk_account_session: session_id)["email_subscription"].nil?) - end - - it "throws a 404 if it does not exist" do - stub_account_api_get_email_subscription_does_not_exist(name: "foo") - assert_raises GdsApi::HTTPNotFound do - api_client.get_email_subscription(name: "foo", govuk_account_session: session_id) - end - end - end - - describe "#put_email_subscription" do - it "returns the new subscription details" do - stub_account_api_put_email_subscription(name: "foo", topic_slug: "slug") - assert(!api_client.put_email_subscription(name: "foo", topic_slug: "slug", govuk_account_session: session_id)["email_subscription"].nil?) - end - end - - describe "#delete_email_subscription" do - it "returns no content if it exists" do - stub_account_api_delete_email_subscription(name: "foo") - assert_equal(204, api_client.delete_email_subscription(name: "foo", govuk_account_session: session_id).code) - end - - it "throws a 404 if it does not exist" do - stub_account_api_delete_email_subscription_does_not_exist(name: "foo") - assert_raises GdsApi::HTTPNotFound do - api_client.delete_email_subscription(name: "foo", govuk_account_session: session_id) - end - end - end - end - describe "attributes" do describe "#get_attributes" do describe "attributes exist" do @@ -194,27 +157,6 @@ api_client.set_attributes(attributes: { foo: %w[bar baz] }, govuk_account_session: session_id) end end - - it "throws a 401 if the user gets an email subscription" do - stub_account_api_unauthorized_get_email_subscription(name: "foo") - assert_raises GdsApi::HTTPUnauthorized do - api_client.get_email_subscription(name: "foo", govuk_account_session: session_id) - end - end - - it "throws a 401 if the user updates an email subscription" do - stub_account_api_unauthorized_put_email_subscription(name: "foo") - assert_raises GdsApi::HTTPUnauthorized do - api_client.put_email_subscription(name: "foo", topic_slug: "slug", govuk_account_session: session_id) - end - end - - it "throws a 401 if the user deletes an email subscription" do - stub_account_api_unauthorized_delete_email_subscription(name: "foo") - assert_raises GdsApi::HTTPUnauthorized do - api_client.delete_email_subscription(name: "foo", govuk_account_session: session_id) - end - end end describe "the user is logged in without MFA when it's needed" do diff --git a/test/pacts/account_api_pact_test.rb b/test/pacts/account_api_pact_test.rb index b79bc12d..2bece1d9 100644 --- a/test/pacts/account_api_pact_test.rb +++ b/test/pacts/account_api_pact_test.rb @@ -188,93 +188,6 @@ end end - describe "email subscriptions" do - let(:subscription_name) { "wizard-news" } - let(:path) { "/api/email-subscriptions/#{subscription_name}" } - - describe "#get_email_subscription" do - it "responds with 200 OK if there is a subscription" do - subscription_json = { - name: subscription_name, - topic_slug: Pact.like("wizard-news-topic-slug"), - } - - account_api - .given("there is a valid user session, with a '#{subscription_name}' email subscription") - .upon_receiving("a show-subscription request for '#{subscription_name}'") - .with(method: :get, path: path, headers: headers) - .will_respond_with(status: 200, headers: json_response_headers, body: { email_subscription: subscription_json }) - - api_client.get_email_subscription(name: subscription_name, govuk_account_session: govuk_account_session) - end - - it "responds with 404 Not Found if there is not a subscription" do - account_api - .given("there is a valid user session") - .upon_receiving("a show-subscription request for '#{subscription_name}'") - .with(method: :get, path: path, headers: headers) - .will_respond_with(status: 404) - - assert_raises GdsApi::HTTPNotFound do - api_client.get_email_subscription(name: subscription_name, govuk_account_session: govuk_account_session) - end - end - end - - describe "#put_email_subscription" do - let(:topic_slug) { "wizard-news-topic-slug" } - let(:subscription_json) { { name: subscription_name, topic_slug: topic_slug } } - - it "responds with 200 OK" do - response_body = response_body_with_session_identifier.merge(email_subscription: subscription_json) - - account_api - .given("there is a valid user session") - .upon_receiving("a put-subscription request for '#{subscription_name}'") - .with(method: :put, path: path, headers: headers_with_json_body, body: { topic_slug: topic_slug }) - .will_respond_with(status: 200, headers: json_response_headers, body: response_body) - - api_client.put_email_subscription(name: subscription_name, topic_slug: topic_slug, govuk_account_session: govuk_account_session) - end - - it "responds with 200 OK and updates an existing subscription" do - response_body = response_body_with_session_identifier.merge(email_subscription: subscription_json) - - account_api - .given("there is a valid user session, with a '#{subscription_name}' email subscription") - .upon_receiving("a put-subscription request for '#{subscription_name}'") - .with(method: :put, path: path, headers: headers_with_json_body, body: { topic_slug: topic_slug }) - .will_respond_with(status: 200, headers: json_response_headers, body: response_body) - - api_client.put_email_subscription(name: subscription_name, topic_slug: topic_slug, govuk_account_session: govuk_account_session) - end - end - - describe "#delete_email_subscription" do - it "responds with 204 No Content if there is a subscription" do - account_api - .given("there is a valid user session, with a '#{subscription_name}' email subscription") - .upon_receiving("a delete-subscription request for '#{subscription_name}'") - .with(method: :delete, path: path, headers: headers) - .will_respond_with(status: 204) - - api_client.delete_email_subscription(name: subscription_name, govuk_account_session: govuk_account_session) - end - - it "responds with 404 Not Found if there is not a subscription" do - account_api - .given("there is a valid user session") - .upon_receiving("a delete-subscription request for '#{subscription_name}'") - .with(method: :delete, path: path, headers: headers) - .will_respond_with(status: 404) - - assert_raises GdsApi::HTTPNotFound do - api_client.delete_email_subscription(name: subscription_name, govuk_account_session: govuk_account_session) - end - end - end - end - describe "attributes" do let(:path) { "/api/attributes" }