Skip to content

Commit

Permalink
EY - enter email address, send email with code
Browse files Browse the repository at this point in the history
  • Loading branch information
alkesh committed Aug 2, 2024
1 parent 404b1ff commit fe1ee8e
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ClaimSubmissionForm < ::ClaimSubmissionBaseForm
private

def main_eligibility
@main_eligibility ||= Policies::EarlyYearsPayment::Eligibility.new
@main_eligibility ||= Policies::EarlyYearsPayments::Eligibility.new
end

def calculate_award_amount(eligibility)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Journeys
module EarlyYearsPayment
module Provider
class EmailAddressForm < Form
attribute :email_address, :string

def save
journey_session.answers.assign_attributes(
email_address: email_address
)
journey_session.save!

ClaimMailer.early_years_payment_provider_email(answers, otp_code).deliver_now
end

private

def otp_code
@otp_code ||= OneTimePassword::Generator.new.code
end
end
end
end
end
3 changes: 3 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ class ApplicationMailer < Mail::Notify::Mailer
CLAIM_UPDATE_AFTER_THREE_WEEKS_NOTIFY_TEMPLATE_ID: "967cc72f-e2e4-4c42-a07f-dd8b8375716e".freeze,
CLAIM_REJECTED_NOTIFY_TEMPLATE_ID: "1edc468c-a1bf-4bea-bb79-042740cd8547".freeze
}
EARLY_YEARS_PAYMENTS = {
CLAIM_PROVIDER_EMAIL_TEMPLATE_ID: "e0b78a08-601b-40ba-a97f-61fb00a7c951".freeze
}
end
16 changes: 15 additions & 1 deletion app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def email_verification(claim, one_time_password)
send_mail(OTP_EMAIL_NOTIFY_TEMPLATE_ID, personalisation)
end

def early_years_payment_provider_email(claim, one_time_password)
unknown_policy_check(claim)
set_common_instance_variables(claim)
@subject = @claim_subject
@one_time_password = one_time_password
personalisation = {
email_subject: @subject,
one_time_password: @one_time_password
}

send_mail(template_ids(claim)[:CLAIM_PROVIDER_EMAIL_TEMPLATE_ID], personalisation)
end

private

def set_common_instance_variables(claim)
Expand Down Expand Up @@ -102,7 +115,8 @@ def unknown_policy_check(claim)
Policies::EarlyCareerPayments,
Policies::LevellingUpPremiumPayments,
Policies::InternationalRelocationPayments,
Policies::FurtherEducationPayments
Policies::FurtherEducationPayments,
Policies::EarlyYearsPayments
].include?(claim.policy)
raise ArgumentError, "Unknown claim policy: #{claim.policy}"
end
Expand Down
5 changes: 3 additions & 2 deletions app/models/journeys/early_years_payment/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ module Provider
ROUTING_NAME = "early-years-payment-provider"
VIEW_PATH = "early_years_payment/provider"
I18N_NAMESPACE = "early_years_payment_provider"
POLICIES = [Policies::EarlyYearsPayment]
POLICIES = [Policies::EarlyYearsPayments]
FORMS = {
"claims" => {
"consent" => ConsentForm
"consent" => ConsentForm,
"email-address" => EmailAddressForm
}
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SessionAnswers < Journeys::SessionAnswers
attribute :consent_given, :boolean

def policy
Policies::EarlyYearsPayment
Policies::EarlyYearsPayments
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module EarlyYearsPayment
module Provider
class SlugSequence
SLUGS = %w[
email-address
check-your-email
consent
current-nursery
].freeze
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Policies
module EarlyYearsPayment
module EarlyYearsPayments
include BasePolicy
extend self

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Policies
module EarlyYearsPayment
module EarlyYearsPayments
class Eligibility < ApplicationRecord
self.table_name = "early_years_payment_eligibilities"

has_one :claim, as: :eligibility, inverse_of: :eligibility

def policy
Policies::EarlyYearsPayment
Policies::EarlyYearsPayments
end

def ineligible?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Policies
module EarlyYearsPayment
module EarlyYearsPayments
class PolicyEligibilityChecker
attr_reader :answers

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<% content_for(:page_title, page_title(t("early_years_payment_provider.check_your_email_page.title"), journey: current_journey_routing_name)) %>

<% @backlink_path = landing_page_path %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
Check your email
</h1>

<p class="govuk-body">
We have sent an email to <%= journey_session.answers.email_address %>
</p>

<p class="govuk-body">
Select the link in the email to log in or sign up. The link will expire in 15 minutes.
</p>

<p class="govuk-body">
If you do not receive the email, check your spam or junk folder.
If you cannot find the email, <%= govuk_link_to "send another link", "" %> or <%= govuk_link_to "enter another email address", "" %>.
</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<% content_for(:page_title, page_title(@form.t(:question), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>

<% @backlink_path = landing_page_path %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, url: claim_path(current_journey_routing_name), method: :patch, builder: GOVUKDesignSystemFormBuilder::FormBuilder, html: { novalidate: false } do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-l">
Enter your email address
</h1>

<p class="govuk-body">
You must use the email address previously provided to your local authority to access this service.
</p>

<%= f.govuk_text_field :email_address,
autocomplete: "email",
spellcheck: "false",
label: { text: t("questions.email_address"), hidden: true } # label still read by screen readers
%>

<%= f.govuk_submit "Submit" %>
<% end %>
</div>
</div>
10 changes: 9 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ en:
By submitting this you are confirming that, to the best of your knowledge, the details you are providing are
correct.
btn_text: Accept and send
early_years_payment_provider:
early_years_payment_provider: &early_years_payment_provider
claim_description: for an early years financial incentive payment
journey_name: Claim an early years financial incentive payment - provider
landing_page:
Expand All @@ -1080,6 +1080,14 @@ en:
notice.
errors:
presence: You must be able to confirm this information to continue
email_address:
question: "Enter your email address"
check_your_email_page:
title: Check your email
early_years_payments:
<<: *early_years_payment_provider
claim_subject: "Early Years Payment"
support_email_address: "[email protected]"
activerecord:
errors:
models:
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
journey = Journeys.for_policy(evaluator.policy)

begin
Journeys.for_policy(evaluator.policy)&.configuration.present?
raise ActiveRecord::RecordNotFound unless Journeys.for_policy(evaluator.policy)&.configuration.present?
rescue ActiveRecord::RecordNotFound
create(:journey_configuration, journey::I18N_NAMESPACE)
end
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/early_years_payments/eligibilities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FactoryBot.define do
factory :early_years_payments_eligibility, class: "Policies::EarlyYearsPayments::Eligibility" do
end
end
24 changes: 21 additions & 3 deletions spec/features/early_years_payment/provider/happy_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,26 @@
visit landing_page_path(Journeys::EarlyYearsPayment::Provider::ROUTING_NAME)
click_link "Start now"

expect(page).to have_content("Declaration of Employee Consent")
check "I confirm that I have obtained consent from my employee and have provided them with the relevant privacy notice."
click_button "Continue"
expect(page.title).to have_text(I18n.t("early_years_payment_provider.forms.email_address.question"))
expect(page).to have_content("Enter your email address")
fill_in "Email address", with: "[email protected]"
click_on "Submit"

expect(page.title).to have_text(I18n.t("early_years_payment_provider.check_your_email_page.title"))
expect(page).to have_content("Check your email")
expect(page).to have_content("We have sent an email to [email protected]")

mail = ActionMailer::Base.deliveries.last
mail_personalisation = mail[:personalisation].unparsed_value
expect(mail_personalisation[:one_time_password]).to match(/\A\d{6}\Z/)

# TODO - uncomment below when magic link functionality in place
# expect(page).to have_content("Declaration of Employee Consent")
# check "I confirm that I have obtained consent from my employee and have provided them with the relevant privacy notice."
# click_button "Continue"
end

scenario "send another link"

scenario "enter another email address"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "rails_helper"

RSpec.describe Journeys::EarlyYearsPayment::Provider::EmailAddressForm do
subject(:form) { described_class.new(journey:, journey_session:, params:) }

let(:journey) { Journeys::EarlyYearsPayment::Provider }
let(:journey_session) { build(:early_years_payment_provider_session) }
# let(:params) { ActionController::Parameters.new({journey: "test-journey", slug: "test_slug", claim: claim_params}) }

let(:params) do
ActionController::Parameters.new(claim: {email_address: email_address})
end

let(:email_address) { "[email protected]" }

it { should have_attributes(email_address: email_address) }

describe "#save" do
subject { form.save }

it { should be_truthy }

it "sets the email address" do
subject
expect(journey_session.reload.answers.email_address).to(
eq(email_address)
)
end
end
end
23 changes: 23 additions & 0 deletions spec/mailers/claim_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ class SomePolicy; end
}.to raise_error(ArgumentError, "Unknown claim policy: SomePolicy")
end
end

describe "#early_years_payment_provider_email" do
it "raises error" do
expect {
ClaimMailer.early_years_payment_provider_email(claim, nil).deliver!
}.to raise_error(ArgumentError, "Unknown claim policy: SomePolicy")
end
end
end

describe "#email_verification" do
Expand Down Expand Up @@ -335,4 +343,19 @@ class SomePolicy; end
end
end
end

describe "#early_years_payment_provider_email" do
let(:mail) { ClaimMailer.early_years_payment_provider_email(claim, one_time_password) }
let(:one_time_password) { 123124 }
let(:claim) { build(:claim, policy: policy, email_address: "[email protected]") }
let(:policy) { Policies::EarlyYearsPayments }

before { create(:journey_configuration, :early_years_payment_provider) }

it "has personalisation keys for: one time password" do
# TODO find correct email subject. Is subject used? or overriden on notify template?
expect(mail[:personalisation].decoded).to eq("{:email_subject=>\"Early Years Payment\", :one_time_password=>123124}")
expect(mail.body).to be_empty
end
end
end

0 comments on commit fe1ee8e

Please sign in to comment.