Skip to content

Commit

Permalink
Add new email content if user is authenticating to manage their subsc…
Browse files Browse the repository at this point in the history
…riptions

If the destination is /manage/authenticate, we can use a different subject line and body
  • Loading branch information
huwd committed Mar 19, 2020
1 parent b4d43a8 commit aa25335
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 12 deletions.
60 changes: 48 additions & 12 deletions app/builders/subscriber_auth_email_builder.rb
Expand Up @@ -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
Expand All @@ -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
52 changes: 52 additions & 0 deletions spec/builders/subscriber_auth_email_builder_spec.rb
Expand Up @@ -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" }

Expand All @@ -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

0 comments on commit aa25335

Please sign in to comment.