diff --git a/app/builders/subscriber_auth_email_builder.rb b/app/builders/subscriber_auth_email_builder.rb index f0de2c252..e9eb001ad 100644 --- a/app/builders/subscriber_auth_email_builder.rb +++ b/app/builders/subscriber_auth_email_builder.rb @@ -25,10 +25,39 @@ def call attr_reader :subscriber, :destination, :token def subject - "Confirm your email address" + return manage_your_subscriptions_subject if destination == "/manage/authenticate" + + confirm_your_email_address_subject end def body + return manage_your_subscriptions_body if destination == "/manage/authenticate" + + confirm_your_email_address_body + end + + def link + Plek.new.website_uri.tap do |uri| + destination_uri = URI.parse(destination) + uri.path = destination_uri.path + uri.query = if destination_uri.query.present? + "#{destination_uri.query}&token=#{token}" + else + "token=#{token}" + end + uri.fragment = destination_uri.fragment + end + end + + def confirm_your_email_address_subject + "Confirm your email address" + end + + def manage_your_subscriptions_subject + "Manage your GOV.UK email subscriptions" + end + + def confirm_your_email_address_body <<~BODY # Click the link to confirm your email address @@ -44,16 +73,23 @@ def body BODY end - def link - Plek.new.website_uri.tap do |uri| - destination_uri = URI.parse(destination) - uri.path = destination_uri.path - uri.query = if destination_uri.query.present? - "#{destination_uri.query}&token=#{token}" - else - "token=#{token}" - end - uri.fragment = destination_uri.fragment - end + def manage_your_subscriptions_body + <<~BODY + # Manage your GOV.UK email subscriptions + + You can manage which GOV.UK emails you receive at: + + #{link} + + You’ll need to confirm your email address before you can make any changes. + + The link will stop working in 7 days. + + # Didn’t request this email? + + Ignore or delete this email if you didn’t request it. Your subscriptions won’t be changed. + + [Contact GOV.UK](https://www.gov.uk/contact/govuk) if you have any problems with your email subscriptions. + BODY end end diff --git a/spec/builders/subscriber_auth_email_builder_spec.rb b/spec/builders/subscriber_auth_email_builder_spec.rb index 727b83cda..abb99bf2d 100644 --- a/spec/builders/subscriber_auth_email_builder_spec.rb +++ b/spec/builders/subscriber_auth_email_builder_spec.rb @@ -24,6 +24,28 @@ expect(email.body).to include(link) end + it "has a subject line prompting the user to confirm their email" do + subject = "Confirm your email address" + email = call + expect(email.subject).to include(subject) + end + + it "has body content prompting the user to confirm their email" do + line_one = "Click the link to confirm your email address" + line_two = "Confirm your email address" + line_three = "You need to do this to manage your GOV.UK email subscriptions. The link will stop working in 7 days." + line_four = "Didn’t request this email?" + line_five = "Ignore or delete this email if you didn’t request it. Your subscriptions won’t be changed." + line_six = "[Contact GOV.UK](https://www.gov.uk/contact/govuk) if you have any problems with your email subscriptions." + email = call + expect(email.body).to include(line_one) + expect(email.body).to include(line_two) + expect(email.body).to include(line_three) + expect(email.body).to include(line_four) + expect(email.body).to include(line_five) + expect(email.body).to include(line_six) + end + context "when destination has a query string and fragment" do let(:destination) { "/destination?query#fragment" } @@ -33,5 +55,35 @@ expect(email.body).to include(link) end end + + context "when destination is /manage" do + let(:destination) { "/manage/authenticate" } + + it "has a subject line prompting the user to confirm their email" do + subject = "Manage your GOV.UK email subscriptions" + email = call + expect(email.subject).to include(subject) + end + + it "has body content prompting unsubscription authentication" do + line_one = "Manage your GOV.UK email subscriptions" + line_two = "You can manage which GOV.UK emails you receive at" + line_three = "http://www.dev.gov.uk/manage/authenticate?token=secret" + line_four = "You’ll need to confirm your email address before you can make any changes." + line_five = "The link will stop working in 7 days." + line_six = "Didn’t request this email?" + line_seven = "Ignore or delete this email if you didn’t request it. Your subscriptions won’t be changed." + line_eight = "[Contact GOV.UK](https://www.gov.uk/contact/govuk) if you have any problems with your email subscriptions." + email = call + expect(email.body).to include(line_one) + expect(email.body).to include(line_two) + expect(email.body).to include(line_three) + expect(email.body).to include(line_four) + expect(email.body).to include(line_five) + expect(email.body).to include(line_six) + expect(email.body).to include(line_seven) + expect(email.body).to include(line_eight) + end + end end end