Skip to content

Commit

Permalink
Remove button html from API response
Browse files Browse the repository at this point in the history
This API endpoint is only used by the single page notification button component
in the gem [1]. The gem has been updated to expect a different response [2].

1 https://github.com/search?q=org%3Aalphagov+check-email-subscription&type=code
2 alphagov/govuk_publishing_components#3071
  • Loading branch information
hannako committed Jan 6, 2023
1 parent 1acb54a commit cb8bd86
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Personalisation::CheckEmailSubscriptionController < PersonalisationControl
before_action do
@base_path = params[:base_path]
@topic_slug = params[:topic_slug]
@button_location = params[:button_location]

head :unprocessable_entity if @base_path && @topic_slug
head :unprocessable_entity unless @base_path || @topic_slug
Expand Down Expand Up @@ -32,16 +31,7 @@ def response_json(active: false)
{
base_path: @base_path,
topic_slug: @topic_slug,
button_location: @button_location,
active:,
button_html: render_button_component(active),
}.compact
end

def render_button_component(active)
ActionController::Base.render(
partial: "govuk_publishing_components/components/single_page_notification_button",
locals: { base_path: @base_path, button_location: @button_location, already_subscribed: active },
).presence
end
end
6 changes: 0 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,6 @@ See [Progressive enhancement ADR for more details](adr/002-progressive-enhanceme
- the base path of the page (to match against the "url" of an email-alert-api subscriber list)
- `topic_slug` *(optional)*
- the email-alert-api topic slug
- `button_location` *(optional)*
- the location of the button on the page (`top` or `bottom`). This is passed to the button component to add tracking parameters for Google Analytics

Exactly one of `base_path` and `topic_slug` must be specified.

Expand All @@ -675,10 +673,6 @@ Exactly one of `base_path` and `topic_slug` must be specified.
- the topic_slug parameter, if there is one (a string)
- `active`
- whether the subscription is active (a boolean)
- `button_html`
- the rendered single-page notification button component HTML, if a `base_path` was given (a string)
- `button_location`
- the button_location parameter, if there is one (a string)

#### Response codes

Expand Down
47 changes: 1 addition & 46 deletions spec/requests/check_email_subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
describe "GET /api/personalisation/check-email-subscription" do
let(:base_path) { nil }
let(:topic_slug) { nil }
let(:button_location) { nil }
let(:params) { { base_path:, topic_slug:, button_location: }.compact }
let(:params) { { base_path:, topic_slug: }.compact }

let(:active) { false }

Expand Down Expand Up @@ -91,11 +90,6 @@
expect(JSON.parse(response.body)).to include(subscription_details)
end

it "includes the inactive-state button HTML" do
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)["button_html"]).to include("Get emails about this page")
end

context "when an active subscription has a matching url" do
let(:list_url) { base_path }
let(:active) { true }
Expand All @@ -104,11 +98,6 @@
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)).to include(subscription_details)
end

it "includes the active-state button HTML" do
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)["button_html"]).to include("Stop getting emails about this page")
end
end
end

Expand All @@ -119,20 +108,6 @@
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)).to include(subscription_details)
end

it "includes the inactive-state button HTML" do
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)["button_html"]).to include("Get emails about this page")
end

context "when a button location is passed" do
let(:button_location) { "top-of-page" }

it "returns the location in the response" do
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)["button_location"]).to eq(button_location)
end
end
end
end

Expand All @@ -143,11 +118,6 @@
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)).to include(subscription_details)
end

it "includes the inactive-state button HTML" do
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)["button_html"]).to include("Get emails about this page")
end
end
end

Expand All @@ -164,11 +134,6 @@
expect(JSON.parse(response.body)).to include(subscription_details)
end

it "does not include button HTML" do
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(response.body).not_to include("button_html")
end

context "when an active subscription has a matching slug" do
let(:list_slug) { topic_slug }
let(:active) { true }
Expand All @@ -177,11 +142,6 @@
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)).to include(subscription_details)
end

it "does not include button HTML" do
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(response.body).not_to include("button_html")
end
end
end

Expand All @@ -192,11 +152,6 @@
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(JSON.parse(response.body)).to include(subscription_details)
end

it "does not include button HTML" do
get personalisation_check_email_subscription_path, params: params, headers: headers
expect(response.body).not_to include("button_html")
end
end
end
end
Expand Down

0 comments on commit cb8bd86

Please sign in to comment.