Skip to content

Commit c53a907

Browse files
committed
Use govuk_account_session header to toggle email signup route
Document collection email subscriptions are complicated[1] The expected behaviour is: If a document collection has a taxonomy topic email override in its links, render the signup link component, and subscribe the user to the taxonomy topic instead of to the document collection itself. In all other cases, render a single page notification button. The button is a gem component, and it uses the value of the attribute `skip_account` to determine the form action of this button[2] - If the user has an active govuk-account session, the button should post to email-alert-frontend's /email/subscriptions/single-page/new endpoint. This endpoint enforces the gov.uk account[3]. - If the user is not logged into their account (or they don't have an account) then the button should post to email-alert-api's magic link endpoint, /email-signup instead. This endpoint does not enforce the govuk account. Current behaviour: Prior to this commit, we were passing skip_account = "true" to the button component on all document collection pages, and therefore hardcoding the button to post to the account free endpoint regardless of whether or not they were logged into their account. New behaviour: What this commit does, is to only set the value of skip_account to "true" for users without an active govuk-account session. Why are we making this change? For users with an existing subscription returning to a document collection page, the single page notification button doesn't allow them to unsubscribe. The button text is "Stop getting emails about this page", but instead of posting to email/subscriptions/single-page/new, which supports both subscribing AND unsubscribing[4] it is hardcoded to post to /email-signup which supports sign up only. This means they must log into their govuk accounts in order to manage their subscriptions. [1] https://docs.publishing.service.gov.uk/manual/document-collection-emails-a-special-case.html [2] https://github.com/alphagov/govuk_publishing_components/blob/main/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb#L58-L64 [3] https://github.com/alphagov/email-alert-frontend/blob/main/app/controllers/govuk_account_signups_controller.rb#L15-L17 [4] https://github.com/alphagov/email-alert-frontend/blob/main/app/controllers/govuk_account_signups_controller.rb#L27-L34
1 parent dbb5892 commit c53a907

File tree

3 files changed

+86
-14
lines changed

3 files changed

+86
-14
lines changed

app/views/shared/_document_collections_email_signup.html.erb

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
} %>
1212
</div>
1313
<% else %>
14-
<%= render 'shared/single_page_notification_button', content_item: @content_item, skip_account: "true" %>
14+
<%= render 'shared/single_page_notification_button', {
15+
content_item: @content_item,
16+
skip_account: @has_govuk_account ? "false" : "true"
17+
} %>
1518
<% end %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
require "test_helper"
2+
3+
module DocumentCollection
4+
class EmailNotificationsTest < ActionDispatch::IntegrationTest
5+
include GovukPersonalisation::TestHelpers::Features
6+
7+
def schema_type
8+
"document_collection"
9+
end
10+
11+
def taxonomy_topic_base_path
12+
"/taxonomy_topic_base_path"
13+
end
14+
15+
def email_alert_frontend_signup_endpoint_no_account
16+
"/email-signup"
17+
end
18+
19+
def email_alert_frontend_signup_endpoint_enforce_account
20+
"/email/subscriptions/single-page/new"
21+
end
22+
23+
test "renders a signup link if the document collection has a taxonomy topic email override" do
24+
content_item = get_content_example("document_collection")
25+
content_item["links"]["taxonomy_topic_email_override"] = [{ "base_path" => taxonomy_topic_base_path.to_s }]
26+
stub_content_store_has_item(content_item["base_path"], content_item)
27+
visit_with_cachebust(content_item["base_path"])
28+
assert page.has_css?(".gem-c-signup-link")
29+
assert page.has_link?(href: "/email-signup/confirm?topic=#{taxonomy_topic_base_path}")
30+
assert_not page.has_css?(".gem-c-single-page-notification-button")
31+
end
32+
33+
test "renders the single page notification button with a form action of email-alert-frontend's non account signup endpoint" do
34+
setup_and_visit_content_item("document_collection")
35+
36+
form = page.find("form.gem-c-single-page-notification-button")
37+
assert_match(email_alert_frontend_signup_endpoint_no_account, form["action"])
38+
39+
button = page.find(:button, class: "gem-c-single-page-notification-button__submit")
40+
41+
expected_tracking = {
42+
"event_name" => "navigation",
43+
"type" => "subscribe",
44+
"index_link" => 1,
45+
"index_total" => 2,
46+
"section" => "Top",
47+
"url" => email_alert_frontend_signup_endpoint_no_account,
48+
}
49+
actual_tracking = JSON.parse(button["data-ga4-link"])
50+
51+
assert_equal expected_tracking, actual_tracking
52+
end
53+
54+
test "renders the single page notification button with a form action of EmailAlertAPI's account-only endpoint for users logged into their gov.uk account" do
55+
# Need to use Rack as Selenium, the default driver, doesn't provide header access, and we need to set a govuk_account_session header
56+
Capybara.current_driver = :rack_test
57+
mock_logged_in_session
58+
setup_and_visit_content_item("document_collection")
59+
60+
form = page.find("form.gem-c-single-page-notification-button")
61+
assert_match(email_alert_frontend_signup_endpoint_enforce_account, form["action"])
62+
63+
button = page.find(:button, class: "gem-c-single-page-notification-button__submit")
64+
65+
expected_tracking = {
66+
"event_name" => "navigation",
67+
"type" => "subscribe",
68+
"index_link" => 1,
69+
"index_total" => 2,
70+
"section" => "Top",
71+
"url" => "/email/subscriptions/single-page/new",
72+
}
73+
74+
actual_tracking = JSON.parse(button["data-ga4-link"])
75+
76+
assert_equal expected_tracking, actual_tracking
77+
78+
# reset back to default driver
79+
Capybara.use_default_driver
80+
end
81+
end
82+
end

test/integration/document_collection_test.rb

-13
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,4 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
132132
assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government")
133133
end
134134
end
135-
136-
test "renders with the single page notification button" do
137-
setup_and_visit_content_item("document_collection")
138-
assert page.has_css?(".gem-c-single-page-notification-button")
139-
assert_not page.has_css?(".gem-c-signup-link")
140-
end
141-
142-
test "renders with the taxonomy subscription button" do
143-
setup_and_visit_content_item_with_taxonomy_topic_email_override("document_collection")
144-
assert page.has_css?(".gem-c-signup-link")
145-
assert page.has_link?(href: "/email-signup/confirm?topic=/testpath")
146-
assert_not page.has_css?(".gem-c-single-page-notification-button")
147-
end
148135
end

0 commit comments

Comments
 (0)