Skip to content

Commit

Permalink
Merge pull request #3433 from DFE-Digital/otp-journey-name
Browse files Browse the repository at this point in the history
[CAPT-2013] OTP email now personalises with journey name
  • Loading branch information
asmega authored Nov 27, 2024
2 parents 5e7c6a2 + da6f9e1 commit e5ad214
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/forms/email_address_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def save

journey_session.save!

ClaimMailer.email_verification(answers, otp_code).deliver_now
ClaimMailer.email_verification(answers, otp_code, journey_session.journey_class.name).deliver_now
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/forms/reminders/personal_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def save!
reminder_otp_secret:
)

ReminderMailer.email_verification(reminder, otp_code).deliver_now
ReminderMailer.email_verification(reminder, otp_code, journey_session.journey_class.name).deliver_now

journey_session.save!
end
Expand Down
5 changes: 3 additions & 2 deletions app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def update_after_three_weeks(claim)
send_mail(template_ids(claim)[:CLAIM_UPDATE_AFTER_THREE_WEEKS_NOTIFY_TEMPLATE_ID], personalisation)
end

def email_verification(claim, one_time_password)
def email_verification(claim, one_time_password, journey_name)
unknown_policy_check(claim)
set_common_instance_variables(claim)
@subject = "#{@claim_subject} email verification"
Expand All @@ -86,7 +86,8 @@ def email_verification(claim, one_time_password)
first_name: @claim.first_name,
one_time_password: @one_time_password,
support_email_address: @support_email_address,
validity_duration: one_time_password_validity_duration
validity_duration: one_time_password_validity_duration,
journey_name:
}

send_mail(OTP_EMAIL_NOTIFY_TEMPLATE_ID, personalisation)
Expand Down
5 changes: 3 additions & 2 deletions app/mailers/reminder_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ReminderMailer < ApplicationMailer
helper :application
helper :additional_payments

def email_verification(reminder, one_time_password)
def email_verification(reminder, one_time_password, journey_name)
@reminder = reminder
@one_time_password = one_time_password
@display_name = reminder.full_name
Expand All @@ -15,7 +15,8 @@ def email_verification(reminder, one_time_password)
first_name: @display_name,
one_time_password: @one_time_password,
support_email_address: support_email_address,
validity_duration: one_time_password_validity_duration
validity_duration: one_time_password_validity_duration,
journey_name:
}

send_mail(OTP_EMAIL_NOTIFY_TEMPLATE_ID, personalisation)
Expand Down
4 changes: 4 additions & 0 deletions app/models/journeys/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ def start_with_magic_link?
def requires_student_loan_details?
false
end

def name
I18n.t(:journey_name, scope: self::I18N_NAMESPACE)
end
end
end
4 changes: 4 additions & 0 deletions app/models/journeys/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Session < ApplicationRecord
unsubmitted.where(journeys_sessions: {updated_at: ..24.hours.ago})
end

def journey_class
Journeys.for_routing_name(journey)
end

def submitted?
claim.present?
end
Expand Down
3 changes: 2 additions & 1 deletion spec/forms/email_address_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
email_subject: email_subject,
first_name: "Jo",
one_time_password: "111111",
support_email_address: support_email_address
support_email_address: support_email_address,
journey_name: journey_session.journey_class.name
)
end

Expand Down
20 changes: 16 additions & 4 deletions spec/mailers/claim_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class SomePolicy; end
describe "#email_verification" do
it "raises error" do
expect {
ClaimMailer.email_verification(claim, nil).deliver!
ClaimMailer.email_verification(claim, nil, "some journey").deliver!
}.to raise_error(ArgumentError, "Unknown claim policy: SomePolicy")
end
end
Expand All @@ -349,7 +349,7 @@ class SomePolicy; end
end

describe "#email_verification" do
let(:mail) { ClaimMailer.email_verification(claim, one_time_password) }
let(:mail) { ClaimMailer.email_verification(claim, one_time_password, "some journey") }
let(:one_time_password) { 123124 }
let(:claim) { build(:claim, policy: policy, first_name: "Ellie", email_address: "test@test.com") }

Expand All @@ -359,7 +359,13 @@ class SomePolicy; end
let(:policy) { Policies::EarlyCareerPayments }

it "has personalisation keys for: one time password, validity_duration,first_name and support_email_address" do
expect(mail[:personalisation].decoded).to eq("{:email_subject=>\"Early-career payment email verification\", :first_name=>\"Ellie\", :one_time_password=>123124, :support_email_address=>\"earlycareerteacherpayments@digital.education.gov.uk\", :validity_duration=>\"15 minutes\"}")
expect(mail.personalisation.keys.sort).to eql([:email_subject, :first_name, :journey_name, :one_time_password, :support_email_address, :validity_duration])
expect(mail.personalisation[:email_subject]).to eql("Early-career payment email verification")
expect(mail.personalisation[:first_name]).to eql("Ellie")
expect(mail.personalisation[:journey_name]).to eql("some journey")
expect(mail.personalisation[:one_time_password]).to eql(123124)
expect(mail.personalisation[:support_email_address]).to eql("earlycareerteacherpayments@digital.education.gov.uk")
expect(mail.personalisation[:validity_duration]).to eql("15 minutes")
expect(mail.body).to be_empty
end
end
Expand All @@ -368,7 +374,13 @@ class SomePolicy; end
let(:policy) { Policies::LevellingUpPremiumPayments }

it "has personalisation keys for: one time password, validity_duration,first_name and support_email_address" do
expect(mail[:personalisation].decoded).to eq("{:email_subject=>\"School targeted retention incentive email verification\", :first_name=>\"Ellie\", :one_time_password=>123124, :support_email_address=>\"schools-targeted.retention-incentive@education.gov.uk\", :validity_duration=>\"15 minutes\"}")
expect(mail.personalisation.keys.sort).to eql([:email_subject, :first_name, :journey_name, :one_time_password, :support_email_address, :validity_duration])
expect(mail.personalisation[:email_subject]).to eql("School targeted retention incentive email verification")
expect(mail.personalisation[:first_name]).to eql("Ellie")
expect(mail.personalisation[:journey_name]).to eql("some journey")
expect(mail.personalisation[:one_time_password]).to eql(123124)
expect(mail.personalisation[:support_email_address]).to eql("schools-targeted.retention-incentive@education.gov.uk")
expect(mail.personalisation[:validity_duration]).to eql("15 minutes")
expect(mail.body).to be_empty
end
end
Expand Down

0 comments on commit e5ad214

Please sign in to comment.