Skip to content

Commit

Permalink
[LUPEYALPHA-989] EY Practitioner check-your-answers page (#3319)
Browse files Browse the repository at this point in the history
* EY Practitioner check-your-answers page
* EY practitioner submitting claim should update existing claim
* set eligibility.practitioner_claim_submitted_at
* only populate claim.submitted_at when practitioner submits claim
* do not perform DQT check for EY
  • Loading branch information
alkesh authored Oct 22, 2024
1 parent 65c79a2 commit 7bb7dd0
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 62 deletions.
34 changes: 21 additions & 13 deletions app/forms/claim_submission_base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def save

ApplicationRecord.transaction do
set_attributes_for_claim_submission
main_eligibility.save!
claim.save!
end

Expand All @@ -35,20 +34,25 @@ def save

delegate :answers, to: :journey_session

def build_claim
claim = Claim.new

claim.eligibility = main_eligibility

claim.started_at = journey_session.created_at
def main_eligibility
@main_eligibility ||= eligibilities.first
end

answers.attributes.each do |name, value|
if claim.respond_to?(:"#{name}=")
claim.public_send(:"#{name}=", value)
def build_claim
new_or_find_claim.tap do |claim|
claim.eligibility ||= main_eligibility
claim.started_at = journey_session.created_at

answers.attributes.each do |name, value|
if claim.respond_to?(:"#{name}=")
claim.public_send(:"#{name}=", value)
end
end
end
end

claim
def new_or_find_claim
Claim.new
end

def eligibilities
Expand All @@ -71,7 +75,11 @@ def set_eligibility_attributes(eligibility)
def set_attributes_for_claim_submission
claim.journey_session = journey_session
claim.policy_options_provided = generate_policy_options_provided
claim.reference = generate_reference
claim.reference ||= generate_reference
set_submitted_at_attributes
end

def set_submitted_at_attributes
claim.submitted_at = Time.zone.now
end

Expand Down Expand Up @@ -121,7 +129,7 @@ def mobile_number_verified?
end

def claim_is_eligible
if main_eligibility.policy::PolicyEligibilityChecker.new(answers: answers).ineligible?
if claim.eligibility.policy::PolicyEligibilityChecker.new(answers: answers).ineligible?
errors.add(:base, i18n_errors_path(:ineligible))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ module Journeys
module EarlyYearsPayment
module Practitioner
class ClaimSubmissionForm < ::ClaimSubmissionBaseForm
def main_eligibility
@main_eligibility ||= eligibilities.detect { |e| e.policy == main_policy }
end

def calculate_award_amount(eligibility)
0
end

def main_policy
Policies::EarlyYearsPayments
end

private

def generate_policy_options_provided
[]
end

def new_or_find_claim
Claim.find_by(reference: journey_session.answers.reference_number) || Claim.new
end

def set_submitted_at_attributes
claim.eligibility.practitioner_claim_started_at = journey_session.created_at
claim.submitted_at = Time.zone.now
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def save
reference_number:,
start_email: email,
reference_number_found: existing_claim.present?,
claim_already_submitted: existing_claim&.eligibility&.practitioner_claim_submitted?,
claim_already_submitted: existing_claim&.submitted?,
nursery_name: existing_claim&.eligibility&.eligible_ey_provider&.nursery_name
)
journey_session.save!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def save

private

def main_eligibility
@main_eligibility ||= eligibilities.first
end

def calculate_award_amount(eligibility)
# NOOP
# This is just for compatibility with the AdditionalPaymentsForTeaching
Expand All @@ -26,6 +22,10 @@ def calculate_award_amount(eligibility)
def generate_policy_options_provided
[]
end

def set_submitted_at_attributes
claim.eligibility.provider_claim_submitted_at = Time.zone.now
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module Start
class ClaimSubmissionForm < ::ClaimSubmissionBaseForm
private

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

def calculate_award_amount(eligibility)
# NOOP
# This is just for compatibility with the AdditionalPaymentsForTeaching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ def save

private

def main_eligibility
@main_eligibility ||= eligibilities.first
end

def calculate_award_amount(eligibility)
# NOOP
# This is just for compatibility with the AdditionalPaymentsForTeaching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module GetATeacherRelocationPayment
class ClaimSubmissionForm < ::ClaimSubmissionBaseForm
private

def main_eligibility
@main_eligibility ||= eligibilities.first
end

def calculate_award_amount(eligibility)
eligibility.award_amount = Policies::InternationalRelocationPayments.award_amount
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module TeacherStudentLoanReimbursement
class ClaimSubmissionForm < ::ClaimSubmissionBaseForm
private

def main_eligibility
@main_eligibility ||= eligibilities.first
end

def calculate_award_amount(eligibility)
# NOOP
# This is just for compatibility with the AdditionalPaymentsForTeaching
Expand Down
18 changes: 10 additions & 8 deletions app/jobs/claim_verifier_job.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
class ClaimVerifierJob < ApplicationJob
def perform(claim)
AutomatedChecks::ClaimVerifier.new(
claim:,
dqt_teacher_status: claim.has_dqt_record? ? Dqt::Teacher.new(claim.dqt_teacher_status) : Dqt::Client.new.teacher.find(
claim.eligibility.teacher_reference_number,
birthdate: claim.date_of_birth.to_s,
nino: claim.national_insurance_number
)
).perform
if claim.eligibility.respond_to?(:teacher_reference_number)
AutomatedChecks::ClaimVerifier.new(
claim:,
dqt_teacher_status: claim.has_dqt_record? ? Dqt::Teacher.new(claim.dqt_teacher_status) : Dqt::Client.new.teacher.find(
claim.eligibility.teacher_reference_number,
birthdate: claim.date_of_birth.to_s,
nino: claim.national_insurance_number
)
).perform
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Journeys
module EarlyYearsPayment
module Practitioner
class AnswersPresenter < BaseAnswersPresenter
include ActionView::Helpers::TranslationHelper

def identity_answers
[].tap do |a|
a << ["Full name", answers.full_name, "personal-details"]
a << ["Date of birth", date_of_birth_string, "personal-details"]
a << ["National Insurance number", answers.national_insurance_number, "personal-details"]
a << ["Home address", answers.address, "enter-home-address"]
a << ["Preferred email address", answers.email_address, "email-address"]
a << ["Provide mobile number?", answers.provide_mobile_number? ? "Yes" : "No", "provide-mobile-number"]
a << ["Preferred mobile number", answers.mobile_number, "mobile-number"] if answers.provide_mobile_number?
end
end

def payment_answers
[].tap do |a|
a << ["Name on the account", answers.banking_name, "personal-bank-account"]
a << ["Sort code", answers.bank_sort_code, "personal-bank-account"]
a << ["Account number", answers.bank_account_number, "personal-bank-account"]
a << ["Payroll gender", answers.payroll_gender, "gender"]
end
end
end
end
end
end
4 changes: 2 additions & 2 deletions app/models/policies/early_years_payments/eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def eligible_ey_provider
EligibleEyProvider.find_by_urn(nursery_urn)
end

def practitioner_claim_submitted?
practitioner_claim_submitted_at.present?
def provider_claim_submitted?
provider_claim_submitted_at.present?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
placeholder
<% content_for(
:page_title,
page_title(
t("early_years_payment_practitioner.check_your_answers.title"),
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%# Errors are from the SubmissionsController %>
<% if @form.errors.any? %>
<%= render("shared/error_summary", instance: @form) %>
<% end %>

<h1 class="govuk-heading-xl">
<%= t("early_years_payment_practitioner.check_your_answers.title") %>
</h1>

<%= render partial: "claims/check_your_answers_section", locals: {heading: "Personal details", answers: journey.answers_for_claim(@form.journey_session).identity_answers} %>

<%= render partial: "claims/check_your_answers_section", locals: {heading: "Bank account information", answers: journey.answers_for_claim(@form.journey_session).payment_answers} %>

<%= form_with url: claim_submission_path, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_submit t("early_years_payment_practitioner.check_your_answers.btn_text") %>
<% end %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placeholder
3 changes: 2 additions & 1 deletion config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,5 @@ shared:
- returning_within_6_months
- created_at
- updated_at
- practitioner_claim_submitted_at
- provider_claim_submitted_at
- practitioner_claim_started_at
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,9 @@ en:
label: Your email address
hint1: We’ll use this to update you with progress on your claim.
hint2: We recommend you use a non-work email address in case your circumstances change while we process your claim.
check_your_answers:
title: Check your answers before submitting this claim
btn_text: Accept and send
activerecord:
errors:
models:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddProviderClaimSubmittedAtToEarlyYearsPaymentEligibilities < ActiveRecord::Migration[7.0]
def change
add_column :early_years_payment_eligibilities, :provider_claim_submitted_at, :datetime
add_column :early_years_payment_eligibilities, :practitioner_claim_started_at, :datetime
remove_column :early_years_payment_eligibilities, :practitioner_claim_submitted_at, :datetime
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_10_15_121145) do
ActiveRecord::Schema[7.0].define(version: 2024_10_17_113701) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "pg_trgm"
Expand Down Expand Up @@ -197,7 +197,8 @@
t.date "start_date"
t.boolean "child_facing_confirmation_given"
t.boolean "returning_within_6_months"
t.datetime "practitioner_claim_submitted_at"
t.datetime "provider_claim_submitted_at"
t.datetime "practitioner_claim_started_at"
end

create_table "eligible_ey_providers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
reference { Reference.new.to_s }
end

trait :early_years_provider_submitted do
reference { Reference.new.to_s }
end

trait :policy_options_provided_with_both do
policy_options_provided {
[
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/early_years_payments/eligibilities.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :early_years_payments_eligibility, class: "Policies::EarlyYearsPayments::Eligibility" do
trait :practitioner_claim_submitted do
practitioner_claim_submitted_at { Time.zone.now }
trait :provider_claim_submitted do
provider_claim_submitted_at { Time.zone.now }
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FactoryBot.define do
factory :early_years_payment_practitioner_answers, class: "Journeys::EarlyYearsPayment::Practitioner::SessionAnswers" do
trait :eligible do
academic_year { AcademicYear.current }
email_address { "practitioner@example.com" }
email_verified { true }
first_name { "John" }
surname { "Doe" }
provide_mobile_number { false }
national_insurance_number { generate(:national_insurance_number) }
date_of_birth { 20.years.ago.to_date }
banking_name { "John Doe" }
bank_sort_code { rand(100000..999999) }
bank_account_number { rand(10000000..99999999) }
end

trait :submittable do
eligible
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
:claim,
policy: Policies::EarlyYearsPayments,
reference: "foo",
practitioner_email_address: "user@example.com",
submitted_at: Time.zone.now
practitioner_email_address: "user@example.com"
)
end

Expand Down Expand Up @@ -68,7 +67,7 @@
:claim,
:submitted,
policy: Policies::EarlyYearsPayments,
eligibility: build(:early_years_payments_eligibility, :practitioner_claim_submitted, nursery_urn: eligible_ey_provider.urn),
eligibility: build(:early_years_payments_eligibility, nursery_urn: eligible_ey_provider.urn),
reference: "foo",
practitioner_email_address: "user@example.com"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@

expect(page).to have_text(I18n.t("forms.gender.questions.payroll_gender"))
choose "Female"
# click_on "Continue"
click_on "Continue"

expect(page).to have_content("Check your answers before submitting this claim")
expect do
perform_enqueued_jobs { click_on "Accept and send" }
end.to not_change { Claim.count }
.and not_change { Policies::EarlyYearsPayments::Eligibility.count }
.and not_change { claim.reload.reference }

expect(claim.eligibility.practitioner_claim_started_at).to be_present
expect(claim.reload.submitted_at).to be_present

# check answers were saved on the claim
expect(claim.reload.national_insurance_number).to eq "PX321499A"
end
end
Loading

0 comments on commit 7bb7dd0

Please sign in to comment.