From 29a1045dc1da79914fd0c7ad6935b12e68e401c0 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Tue, 17 Sep 2024 11:56:53 +0100 Subject: [PATCH 01/11] LUPEYALPHA-1035 - store when the last provider email was sent --- .../provider_verification_emails_controller.rb | 3 ++- .../claim_submission_form.rb | 3 ++- .../provider_verification_emails.rb | 14 ++++++++++++++ ..._to_further_education_payments_eligibilities.rb | 5 +++++ db/schema.rb | 3 ++- .../admin_claim_further_education_payments_spec.rb | 14 ++++++++++++-- .../claim_submission_form_spec.rb | 5 +++++ 7 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 app/models/policies/further_education_payments/provider_verification_emails.rb create mode 100644 db/migrate/20240916173031_add_provider_verification_email_last_sent_at_to_further_education_payments_eligibilities.rb diff --git a/app/controllers/admin/further_education_payments/provider_verification_emails_controller.rb b/app/controllers/admin/further_education_payments/provider_verification_emails_controller.rb index d82194ff20..b16f374d19 100644 --- a/app/controllers/admin/further_education_payments/provider_verification_emails_controller.rb +++ b/app/controllers/admin/further_education_payments/provider_verification_emails_controller.rb @@ -12,7 +12,8 @@ def create body: "Verification email sent to #{claim.school.name}" ) - ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later + Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim) + .send_further_education_payment_provider_verification_email flash[:notice] = "Verification email sent to #{claim.school.name}" diff --git a/app/forms/journeys/further_education_payments/claim_submission_form.rb b/app/forms/journeys/further_education_payments/claim_submission_form.rb index b549e124a6..8959ee87f8 100644 --- a/app/forms/journeys/further_education_payments/claim_submission_form.rb +++ b/app/forms/journeys/further_education_payments/claim_submission_form.rb @@ -10,7 +10,8 @@ def save # noop # do not send provider verification email else - ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later + Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim) + .send_further_education_payment_provider_verification_email end true diff --git a/app/models/policies/further_education_payments/provider_verification_emails.rb b/app/models/policies/further_education_payments/provider_verification_emails.rb new file mode 100644 index 0000000000..347bacf98f --- /dev/null +++ b/app/models/policies/further_education_payments/provider_verification_emails.rb @@ -0,0 +1,14 @@ +module Policies + module FurtherEducationPayments + class ProviderVerificationEmails + def initialize(claim) + @claim = claim + end + + def send_further_education_payment_provider_verification_email + @claim.eligibility.update!(provider_verification_email_last_sent_at: Time.now) + ClaimMailer.further_education_payment_provider_verification_email(@claim).deliver_later + end + end + end +end diff --git a/db/migrate/20240916173031_add_provider_verification_email_last_sent_at_to_further_education_payments_eligibilities.rb b/db/migrate/20240916173031_add_provider_verification_email_last_sent_at_to_further_education_payments_eligibilities.rb new file mode 100644 index 0000000000..f874370d4e --- /dev/null +++ b/db/migrate/20240916173031_add_provider_verification_email_last_sent_at_to_further_education_payments_eligibilities.rb @@ -0,0 +1,5 @@ +class AddProviderVerificationEmailLastSentAtToFurtherEducationPaymentsEligibilities < ActiveRecord::Migration[7.0] + def change + add_column :further_education_payments_eligibilities, :provider_verification_email_last_sent_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 6908127828..2237f77b7d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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_09_04_150711) do +ActiveRecord::Schema[7.0].define(version: 2024_09_16_173031) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" @@ -261,6 +261,7 @@ t.boolean "half_teaching_hours" t.jsonb "verification", default: {} t.boolean "flagged_as_duplicate", default: false + t.datetime "provider_verification_email_last_sent_at" t.index ["possible_school_id"], name: "index_fe_payments_eligibilities_on_possible_school_id" t.index ["school_id"], name: "index_fe_payments_eligibilities_on_school_id" end diff --git a/spec/features/admin/admin_claim_further_education_payments_spec.rb b/spec/features/admin/admin_claim_further_education_payments_spec.rb index 6febdd9921..5e16116146 100644 --- a/spec/features/admin/admin_claim_further_education_payments_spec.rb +++ b/spec/features/admin/admin_claim_further_education_payments_spec.rb @@ -52,6 +52,8 @@ "information" ) + expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to be_nil + expect(page).to have_content( "This task has not been sent to the provider yet." ) @@ -78,6 +80,8 @@ verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim) ) ) + + expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now end end @@ -106,7 +110,8 @@ contract_type: "fixed_term", claim: claim, school: fe_provider, - award_amount: 1500 + award_amount: 1500, + provider_verification_email_last_sent_at: DateTime.new(2024, 8, 1, 9, 0, 0) ) create( @@ -155,6 +160,8 @@ verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim) ) ) + + expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now end end @@ -182,7 +189,8 @@ contract_type: "fixed_term", claim: claim, school: fe_provider, - award_amount: 1500 + award_amount: 1500, + provider_verification_email_last_sent_at: DateTime.new(2024, 8, 1, 9, 0, 0) ) visit admin_claim_path(claim) @@ -225,6 +233,8 @@ verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim) ) ) + + expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now end end end diff --git a/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb b/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb index f9386dcf9a..be5d6c70be 100644 --- a/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb +++ b/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb @@ -95,6 +95,8 @@ verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim) ) ) + + expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq DateTime.new(2024, 10, 1, 0, 0, 0) end it "doesn't email the provider if the claim is a duplicate" do @@ -119,7 +121,10 @@ duplicate_claim = second_claim_form.claim expect(original_claim.eligibility.flagged_as_duplicate).to eq(false) + expect(original_claim.eligibility.provider_verification_email_last_sent_at).not_to be_nil + expect(duplicate_claim.eligibility.flagged_as_duplicate).to eq(true) + expect(duplicate_claim.eligibility.provider_verification_email_last_sent_at).to be_nil end context "when one login IDV mismatch" do From 863d676326fd994c1afbc995d252d2a041b242e5 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Tue, 17 Sep 2024 16:49:27 +0100 Subject: [PATCH 02/11] LUPEYALPHA-1035 - daily job to send chaser provider emails --- .../provider_verification_chase_email_job.rb | 27 ++++++ app/mailers/application_mailer.rb | 1 + app/mailers/claim_mailer.rb | 21 +++++ .../further_education_payments/eligibility.rb | 2 + .../provider_verification_emails.rb | 7 ++ .../provider_verification_chase_email_spec.rb | 92 +++++++++++++++++++ 6 files changed, 150 insertions(+) create mode 100644 app/jobs/further_education_payments/provider_verification_chase_email_job.rb create mode 100644 spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb diff --git a/app/jobs/further_education_payments/provider_verification_chase_email_job.rb b/app/jobs/further_education_payments/provider_verification_chase_email_job.rb new file mode 100644 index 0000000000..7ccc750a9d --- /dev/null +++ b/app/jobs/further_education_payments/provider_verification_chase_email_job.rb @@ -0,0 +1,27 @@ +module FurtherEducationPayments + class ProviderVerificationChaseEmailJob < CronJob + # Daily 8am + self.cron_expression = "0 8 * * *" + + queue_as :user_data + + def perform + Rails.logger.info "ProviderVerificationChaseEmailJob sending chase emails..." + + unverified_claims_with_provider_email_sent_over_3_weeks_ago.each do |claim| + Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim) + .send_further_education_payment_provider_verification_chase_email + end + end + + private + + def unverified_claims_with_provider_email_sent_over_3_weeks_ago + Policies::FurtherEducationPayments::Eligibility + .includes(:claim) + .unverified + .where("provider_verification_email_last_sent_at < ?", 3.weeks.ago) + .map(&:claim) + end + end +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 7d432cc3f9..a4cfa32cce 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -42,6 +42,7 @@ class ApplicationMailer < Mail::Notify::Mailer CLAIM_REJECTED_NOTIFY_TEMPLATE_ID: "a1bb5f64-585f-4b03-b9db-0b20ad801b34".freeze, CLAIM_PROVIDER_VERIFICATION_EMAIL_TEMPLATE_ID: "9a25fe46-2ee4-4a5c-8d47-0f04f058a87d".freeze, + CLAIM_PROVIDER_VERIFICATION_CHASE_EMAIL_TEMPLATE_ID: "9c84a684-b751-449a-bce0-ebe4aa5b187a".freeze, CLAIM_PROVIDER_VERIFICATION_CONFIRMATION_EMAIL_TEMPLATE_ID: "70942fe1-5838-4d37-904c-9d070f2582f0".freeze } diff --git a/app/mailers/claim_mailer.rb b/app/mailers/claim_mailer.rb index 7f87ff04e1..984ac6ca30 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -103,6 +103,27 @@ def further_education_payment_provider_verification_email(claim) ) end + def further_education_payment_provider_verification_chase_email(claim) + policy_check!(claim, Policies::FurtherEducationPayments) + + personalisation = { + recipient_name: claim.school.name, + claimant_name: claim.full_name, + claim_reference: claim.reference, + claim_submission_date: l(claim.created_at.to_date), + verification_due_date: l(Policies::FurtherEducationPayments.verification_due_date_for_claim(claim)), + verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim) + } + + template_id = template_ids(claim)[:CLAIM_PROVIDER_VERIFICATION_CHASE_EMAIL_TEMPLATE_ID] + + template_mail( + template_id, + to: claim.school.eligible_fe_provider.primary_key_contact_email_address, + personalisation: personalisation + ) + end + def further_education_payment_provider_confirmation_email(claim) policy_check!(claim, Policies::FurtherEducationPayments) diff --git a/app/models/policies/further_education_payments/eligibility.rb b/app/models/policies/further_education_payments/eligibility.rb index 5ea2719296..f8025e46d8 100644 --- a/app/models/policies/further_education_payments/eligibility.rb +++ b/app/models/policies/further_education_payments/eligibility.rb @@ -25,6 +25,8 @@ def description belongs_to :possible_school, optional: true, class_name: "School" belongs_to :school, optional: true + scope :unverified, -> { where(verification: {}) } + # Claim#school expects this alias_method :current_school, :school diff --git a/app/models/policies/further_education_payments/provider_verification_emails.rb b/app/models/policies/further_education_payments/provider_verification_emails.rb index 347bacf98f..85f49160cb 100644 --- a/app/models/policies/further_education_payments/provider_verification_emails.rb +++ b/app/models/policies/further_education_payments/provider_verification_emails.rb @@ -5,10 +5,17 @@ def initialize(claim) @claim = claim end + # First provider email def send_further_education_payment_provider_verification_email @claim.eligibility.update!(provider_verification_email_last_sent_at: Time.now) ClaimMailer.further_education_payment_provider_verification_email(@claim).deliver_later end + + # Subsequent chase email + def send_further_education_payment_provider_verification_chase_email + @claim.eligibility.update!(provider_verification_email_last_sent_at: Time.now) + ClaimMailer.further_education_payment_provider_verification_chase_email(@claim).deliver_later + end end end end diff --git a/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb b/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb new file mode 100644 index 0000000000..821dcaabbe --- /dev/null +++ b/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb @@ -0,0 +1,92 @@ +require "rails_helper" + +RSpec.describe FurtherEducationPayments::ProviderVerificationChaseEmailJob do + around do |example| + travel_to DateTime.new(2024, 10, 22, 8, 0, 0) do + example.run + end + end + + describe "#perform" do + let!(:claim_with_no_provider_email_sent) { + create(:claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility: build( + :further_education_payments_eligibility, + :eligible, + provider_verification_email_last_sent_at: nil + )) + } + + let!(:claim_with_provider_email_sent_over_3_weeks_ago) { + create(:claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility: build( + :further_education_payments_eligibility, + :eligible, + provider_verification_email_last_sent_at: DateTime.new(2024, 10, 1, 7, 0, 0) + )) + } + + let!(:claim_with_provider_email_sent_less_than_3_weeks_ago) { + create(:claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility: build( + :further_education_payments_eligibility, + :eligible, + provider_verification_email_last_sent_at: DateTime.new(2024, 10, 15, 7, 0, 0) + )) + } + + let!(:claim_with_provider_email_sent_over_3_weeks_ago_verified) { + create(:claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility: build( + :further_education_payments_eligibility, + :eligible, + :verified, + provider_verification_email_last_sent_at: DateTime.new(2024, 10, 1, 7, 0, 0) + )) + } + + before do + allow(ClaimMailer).to( + receive(:further_education_payment_provider_verification_chase_email) + ).and_return(double(deliver_later: nil)) + + FurtherEducationPayments::ProviderVerificationChaseEmailJob.new.perform + end + + it "sends an email only to unverified claims with a provider email last sent over 3 weeks ago " do + expect(claim_with_provider_email_sent_over_3_weeks_ago.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now + + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_chase_email) + .with(claim_with_provider_email_sent_over_3_weeks_ago) + .exactly(1).times + ) + + # Make sure no other claims got through + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_chase_email) + .exactly(1).times + ) + end + + it "does not send a chaser if a provider email was not previously sent" do + expect(claim_with_no_provider_email_sent.eligibility.reload.provider_verification_email_last_sent_at).to be_nil + end + + it "does not send a chaser if it has not been 3 weeks since a provider email was sent" do + expect(claim_with_provider_email_sent_less_than_3_weeks_ago.eligibility.reload.provider_verification_email_last_sent_at).to eq DateTime.new(2024, 10, 15, 7, 0, 0) + end + + it "does not sent a chaser for any claims that are verified" do + expect(claim_with_provider_email_sent_over_3_weeks_ago_verified.eligibility.reload.provider_verification_email_last_sent_at).to eq DateTime.new(2024, 10, 1, 7, 0, 0) + end + end +end From 8e35d7f074ad43653c04aec3869a6650aefcc085 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Tue, 17 Sep 2024 17:13:10 +0100 Subject: [PATCH 03/11] LUPEYALPHA-1035 - creates a note on the provider verfication task a chaser email sent --- .../provider_verification_chase_email_job.rb | 5 ++++ .../provider_verification_chase_email_spec.rb | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/app/jobs/further_education_payments/provider_verification_chase_email_job.rb b/app/jobs/further_education_payments/provider_verification_chase_email_job.rb index 7ccc750a9d..02154116a7 100644 --- a/app/jobs/further_education_payments/provider_verification_chase_email_job.rb +++ b/app/jobs/further_education_payments/provider_verification_chase_email_job.rb @@ -9,6 +9,11 @@ def perform Rails.logger.info "ProviderVerificationChaseEmailJob sending chase emails..." unverified_claims_with_provider_email_sent_over_3_weeks_ago.each do |claim| + claim.notes.create!( + label: "provider_verification", + body: "Verification chaser email sent to #{claim.school.name}" + ) + Policies::FurtherEducationPayments::ProviderVerificationEmails.new(claim) .send_further_education_payment_provider_verification_chase_email end diff --git a/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb b/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb index 821dcaabbe..0d683ebc31 100644 --- a/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb +++ b/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb @@ -77,16 +77,43 @@ ) end + it "creates a note that chaser email was sent" do + note = claim_with_provider_email_sent_over_3_weeks_ago.reload.notes.order(created_at: :desc).first + school = claim_with_provider_email_sent_over_3_weeks_ago.school + + expect(note.body).to eq "Verification chaser email sent to #{school.name}" + expect(note.label).to eq "provider_verification" + expect(note.created_by_id).to be_nil + end + it "does not send a chaser if a provider email was not previously sent" do expect(claim_with_no_provider_email_sent.eligibility.reload.provider_verification_email_last_sent_at).to be_nil + + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_chase_email) + .with(claim_with_no_provider_email_sent) + .exactly(0).times + ) end it "does not send a chaser if it has not been 3 weeks since a provider email was sent" do expect(claim_with_provider_email_sent_less_than_3_weeks_ago.eligibility.reload.provider_verification_email_last_sent_at).to eq DateTime.new(2024, 10, 15, 7, 0, 0) + + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_chase_email) + .with(claim_with_provider_email_sent_less_than_3_weeks_ago) + .exactly(0).times + ) end it "does not sent a chaser for any claims that are verified" do expect(claim_with_provider_email_sent_over_3_weeks_ago_verified.eligibility.reload.provider_verification_email_last_sent_at).to eq DateTime.new(2024, 10, 1, 7, 0, 0) + + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_chase_email) + .with(claim_with_provider_email_sent_over_3_weeks_ago_verified) + .exactly(0).times + ) end end end From 2d137e78483ef288d50be090d48e998256594cf2 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Tue, 17 Sep 2024 19:23:47 +0100 Subject: [PATCH 04/11] LUPEYALPHA-1035 - Change the verification_due_date to 3 weeks from sending chase email --- app/mailers/claim_mailer.rb | 2 +- .../policies/further_education_payments.rb | 4 ++ .../provider_verfication_emails_spec.rb | 50 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 spec/models/policies/further_education_payments/provider_verfication_emails_spec.rb diff --git a/app/mailers/claim_mailer.rb b/app/mailers/claim_mailer.rb index 984ac6ca30..ee00fc7970 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -111,7 +111,7 @@ def further_education_payment_provider_verification_chase_email(claim) claimant_name: claim.full_name, claim_reference: claim.reference, claim_submission_date: l(claim.created_at.to_date), - verification_due_date: l(Policies::FurtherEducationPayments.verification_due_date_for_claim(claim)), + verification_due_date: l(Policies::FurtherEducationPayments.verification_chase_due_date_for_claim(claim)), verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim) } diff --git a/app/models/policies/further_education_payments.rb b/app/models/policies/further_education_payments.rb index 7eb5a939c8..e3796c4fc7 100644 --- a/app/models/policies/further_education_payments.rb +++ b/app/models/policies/further_education_payments.rb @@ -68,6 +68,10 @@ def verification_due_date_for_claim(claim) (claim.created_at + 2.weeks).to_date end + def verification_chase_due_date_for_claim(claim) + (claim.eligibility.provider_verification_email_last_sent_at + 3.weeks).to_date + end + def duplicate_claim?(claim) Claim::MatchingAttributeFinder.new(claim).matching_claims.exists? end diff --git a/spec/models/policies/further_education_payments/provider_verfication_emails_spec.rb b/spec/models/policies/further_education_payments/provider_verfication_emails_spec.rb new file mode 100644 index 0000000000..4faeba68a0 --- /dev/null +++ b/spec/models/policies/further_education_payments/provider_verfication_emails_spec.rb @@ -0,0 +1,50 @@ +require "rails_helper" + +describe Policies::FurtherEducationPayments::ProviderVerificationEmails do + describe "#send_further_education_payment_provider_verification_chase_email" do + let(:fe_provider) { + create( + :school, + :further_education, + :fe_eligible, + name: "Springfield A and M" + ) + } + + let!(:claim) { + create(:claim, + :submitted, + policy: Policies::FurtherEducationPayments, + created_at: DateTime.new(2024, 10, 1, 7, 0, 0), + submitted_at: DateTime.new(2024, 10, 1, 7, 0, 0), + eligibility: build( + :further_education_payments_eligibility, + :eligible, + school: fe_provider, + provider_verification_email_last_sent_at: DateTime.new(2024, 10, 1, 7, 0, 0) + )) + } + + it "emails the claim provider" do + travel_to DateTime.new(2024, 10, 1, 7, 0, 0) + 3.weeks do + perform_enqueued_jobs do + described_class.new(claim).send_further_education_payment_provider_verification_chase_email + end + + expect(claim.school.eligible_fe_provider.primary_key_contact_email_address).to( + have_received_email( + "9c84a684-b751-449a-bce0-ebe4aa5b187a", + recipient_name: claim.school.name, + claimant_name: claim.full_name, + claim_reference: claim.reference, + claim_submission_date: "1 October 2024", + verification_due_date: "12 November 2024", + verification_url: Journeys::FurtherEducationPayments::Provider::SlugSequence.verify_claim_url(claim) + ) + ) + + expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now + end + end + end +end From 48d360e3f6c9740af70b893e4a78a889f2d501c7 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Wed, 18 Sep 2024 11:43:44 +0100 Subject: [PATCH 05/11] dfe-analytics add new field --- config/analytics.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/analytics.yml b/config/analytics.yml index d02699e757..708762f75e 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -299,6 +299,7 @@ shared: - subject_to_disciplinary_action - half_teaching_hours - flagged_as_duplicate + - provider_verification_email_last_sent_at :eligible_fe_providers: - id - ukprn From e5fa900674bd1c8212b8f2e9ceac96a462105b96 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Wed, 18 Sep 2024 13:02:45 +0100 Subject: [PATCH 06/11] Display the note in the task a chaser email was sent --- ...provider_verification_unsubmitted.html.erb | 9 +++- ...n_claim_further_education_payments_spec.rb | 46 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/views/admin/tasks/_provider_verification_unsubmitted.html.erb b/app/views/admin/tasks/_provider_verification_unsubmitted.html.erb index 631b40e967..7aa5e64089 100644 --- a/app/views/admin/tasks/_provider_verification_unsubmitted.html.erb +++ b/app/views/admin/tasks/_provider_verification_unsubmitted.html.erb @@ -1,10 +1,15 @@ <% if @tasks_presenter.provider_verification.verification_email_sent? %> <% if @tasks_presenter.provider_verification.verification_email_sent_by_admin_team? %>
- <% @tasks_presenter.provider_verification.admin_sent_emails.each do |verification_email| %> + <% @tasks_presenter.provider_verification.admin_sent_emails.each do |verification_email|%>

The verification request was sent to the provider by - <%= user_details(verification_email.created_by) %> on <%= l(verification_email.created_at) %> + <% if verification_email.created_by %> + <%= user_details(verification_email.created_by) %> + <% else %> + an automated process + <% end %> + on <%= l(verification_email.created_at) %>

<% end %>
diff --git a/spec/features/admin/admin_claim_further_education_payments_spec.rb b/spec/features/admin/admin_claim_further_education_payments_spec.rb index 5e16116146..288b77f5e3 100644 --- a/spec/features/admin/admin_claim_further_education_payments_spec.rb +++ b/spec/features/admin/admin_claim_further_education_payments_spec.rb @@ -236,6 +236,52 @@ expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now end + + it "shows the chaser verification email was sent if one was sent after 3 weeks" do + fe_provider = create( + :school, + :further_education, + :fe_eligible, + name: "Springfield A and M" + ) + + claim = create( + :claim, + first_name: "Edna", + surname: "Krabappel", + date_of_birth: Date.new(1945, 7, 3), + reference: "AB123456", + created_at: DateTime.new(2024, 8, 1, 9, 0, 0), + submitted_at: DateTime.new(2024, 8, 1, 9, 0, 0) + ) + + create( + :further_education_payments_eligibility, + contract_type: "fixed_term", + claim: claim, + school: fe_provider, + award_amount: 1500, + provider_verification_email_last_sent_at: DateTime.new(2024, 8, 1, 9, 0, 0) + ) + + perform_enqueued_jobs do + FurtherEducationPayments::ProviderVerificationChaseEmailJob.perform_now + end + + visit admin_claim_path(claim) + + click_on "View tasks" + + click_on( + "Confirm the provider has responded and verified the claimant's " \ + "information" + ) + + expect(page).to have_content( + "The verification request was sent to the provider by " \ + "an automated process on 9 September 2024 11:00am" + ) + end end end end From d7b01a0fe0d769c4ce54c14b513021735c18f26e Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Mon, 23 Sep 2024 18:21:55 +0100 Subject: [PATCH 07/11] LUPEYALPHA-1035 - Only send chase email once, rejected/held claims are ignored --- .../provider_verification_chase_email_job.rb | 4 +- .../policies/further_education_payments.rb | 2 +- .../further_education_payments/eligibility.rb | 2 + .../provider_verification_emails.rb | 4 +- config/analytics.yml | 1 + ...urther_education_payments_eligibilities.rb | 5 ++ db/schema.rb | 3 +- .../provider_verification_chase_email_spec.rb | 76 +++++++++++++++++-- .../provider_verfication_emails_spec.rb | 2 +- 9 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20240923130010_add_provider_verification_chase_email_last_sent_at_to_further_education_payments_eligibilities.rb diff --git a/app/jobs/further_education_payments/provider_verification_chase_email_job.rb b/app/jobs/further_education_payments/provider_verification_chase_email_job.rb index 02154116a7..f96bb977d6 100644 --- a/app/jobs/further_education_payments/provider_verification_chase_email_job.rb +++ b/app/jobs/further_education_payments/provider_verification_chase_email_job.rb @@ -25,8 +25,10 @@ def unverified_claims_with_provider_email_sent_over_3_weeks_ago Policies::FurtherEducationPayments::Eligibility .includes(:claim) .unverified - .where("provider_verification_email_last_sent_at < ?", 3.weeks.ago) + .provider_verification_email_last_sent_over(3.weeks.ago) + .provider_verification_chase_email_not_sent .map(&:claim) + .reject { |claim| claim.held? || claim.latest_decision&.rejected? } end end end diff --git a/app/models/policies/further_education_payments.rb b/app/models/policies/further_education_payments.rb index e3796c4fc7..60c3695ef2 100644 --- a/app/models/policies/further_education_payments.rb +++ b/app/models/policies/further_education_payments.rb @@ -69,7 +69,7 @@ def verification_due_date_for_claim(claim) end def verification_chase_due_date_for_claim(claim) - (claim.eligibility.provider_verification_email_last_sent_at + 3.weeks).to_date + (claim.eligibility.provider_verification_chase_email_last_sent_at + 3.weeks).to_date end def duplicate_claim?(claim) diff --git a/app/models/policies/further_education_payments/eligibility.rb b/app/models/policies/further_education_payments/eligibility.rb index f8025e46d8..90be4cc547 100644 --- a/app/models/policies/further_education_payments/eligibility.rb +++ b/app/models/policies/further_education_payments/eligibility.rb @@ -26,6 +26,8 @@ def description belongs_to :school, optional: true scope :unverified, -> { where(verification: {}) } + scope :provider_verification_email_last_sent_over, ->(older_than) { where("provider_verification_email_last_sent_at < ?", older_than) } + scope :provider_verification_chase_email_not_sent, -> { where(provider_verification_chase_email_last_sent_at: nil) } # Claim#school expects this alias_method :current_school, :school diff --git a/app/models/policies/further_education_payments/provider_verification_emails.rb b/app/models/policies/further_education_payments/provider_verification_emails.rb index 85f49160cb..957adbf9db 100644 --- a/app/models/policies/further_education_payments/provider_verification_emails.rb +++ b/app/models/policies/further_education_payments/provider_verification_emails.rb @@ -11,9 +11,9 @@ def send_further_education_payment_provider_verification_email ClaimMailer.further_education_payment_provider_verification_email(@claim).deliver_later end - # Subsequent chase email + # Second automated provider chase email def send_further_education_payment_provider_verification_chase_email - @claim.eligibility.update!(provider_verification_email_last_sent_at: Time.now) + @claim.eligibility.update!(provider_verification_chase_email_last_sent_at: Time.now) ClaimMailer.further_education_payment_provider_verification_chase_email(@claim).deliver_later end end diff --git a/config/analytics.yml b/config/analytics.yml index 708762f75e..2b35342025 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -300,6 +300,7 @@ shared: - half_teaching_hours - flagged_as_duplicate - provider_verification_email_last_sent_at + - provider_verification_chase_email_last_sent_at :eligible_fe_providers: - id - ukprn diff --git a/db/migrate/20240923130010_add_provider_verification_chase_email_last_sent_at_to_further_education_payments_eligibilities.rb b/db/migrate/20240923130010_add_provider_verification_chase_email_last_sent_at_to_further_education_payments_eligibilities.rb new file mode 100644 index 0000000000..442085905f --- /dev/null +++ b/db/migrate/20240923130010_add_provider_verification_chase_email_last_sent_at_to_further_education_payments_eligibilities.rb @@ -0,0 +1,5 @@ +class AddProviderVerificationChaseEmailLastSentAtToFurtherEducationPaymentsEligibilities < ActiveRecord::Migration[7.0] + def change + add_column :further_education_payments_eligibilities, :provider_verification_chase_email_last_sent_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 2237f77b7d..d7d495ccc3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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_09_16_173031) do +ActiveRecord::Schema[7.0].define(version: 2024_09_23_130010) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" @@ -262,6 +262,7 @@ t.jsonb "verification", default: {} t.boolean "flagged_as_duplicate", default: false t.datetime "provider_verification_email_last_sent_at" + t.datetime "provider_verification_chase_email_last_sent_at" t.index ["possible_school_id"], name: "index_fe_payments_eligibilities_on_possible_school_id" t.index ["school_id"], name: "index_fe_payments_eligibilities_on_school_id" end diff --git a/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb b/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb index 0d683ebc31..1e6d580952 100644 --- a/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb +++ b/spec/jobs/further_education_payments/provider_verification_chase_email_spec.rb @@ -14,8 +14,7 @@ policy: Policies::FurtherEducationPayments, eligibility: build( :further_education_payments_eligibility, - :eligible, - provider_verification_email_last_sent_at: nil + :eligible )) } @@ -53,6 +52,42 @@ )) } + let!(:claim_with_provider_chase_email_already_sent) { + create(:claim, + :submitted, + policy: Policies::FurtherEducationPayments, + eligibility: build( + :further_education_payments_eligibility, + :eligible, + :verified, + provider_verification_email_last_sent_at: DateTime.new(2024, 9, 1, 8, 0, 0), + provider_verification_chase_email_last_sent_at: DateTime.new(2024, 9, 22, 8, 0, 0) + )) + } + + let!(:claim_rejected_after_provider_verification_was_sent) { + create(:claim, + :rejected, + policy: Policies::FurtherEducationPayments, + eligibility: build( + :further_education_payments_eligibility, + :eligible, + provider_verification_email_last_sent_at: DateTime.new(2024, 10, 1, 7, 0, 0) + )) + } + + let!(:claim_held_after_provider_verification_was_sent) { + create(:claim, + :submitted, + :held, + policy: Policies::FurtherEducationPayments, + eligibility: build( + :further_education_payments_eligibility, + :eligible, + provider_verification_email_last_sent_at: DateTime.new(2024, 10, 1, 7, 0, 0) + )) + } + before do allow(ClaimMailer).to( receive(:further_education_payment_provider_verification_chase_email) @@ -62,7 +97,7 @@ end it "sends an email only to unverified claims with a provider email last sent over 3 weeks ago " do - expect(claim_with_provider_email_sent_over_3_weeks_ago.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now + expect(claim_with_provider_email_sent_over_3_weeks_ago.eligibility.reload.provider_verification_chase_email_last_sent_at).to eq Time.now expect(ClaimMailer).to( have_received(:further_education_payment_provider_verification_chase_email) @@ -88,6 +123,7 @@ it "does not send a chaser if a provider email was not previously sent" do expect(claim_with_no_provider_email_sent.eligibility.reload.provider_verification_email_last_sent_at).to be_nil + expect(claim_with_no_provider_email_sent.eligibility.reload.provider_verification_chase_email_last_sent_at).to be_nil expect(ClaimMailer).to( have_received(:further_education_payment_provider_verification_chase_email) @@ -97,7 +133,7 @@ end it "does not send a chaser if it has not been 3 weeks since a provider email was sent" do - expect(claim_with_provider_email_sent_less_than_3_weeks_ago.eligibility.reload.provider_verification_email_last_sent_at).to eq DateTime.new(2024, 10, 15, 7, 0, 0) + expect(claim_with_provider_email_sent_less_than_3_weeks_ago.eligibility.reload.provider_verification_chase_email_last_sent_at).to be_nil expect(ClaimMailer).to( have_received(:further_education_payment_provider_verification_chase_email) @@ -107,7 +143,7 @@ end it "does not sent a chaser for any claims that are verified" do - expect(claim_with_provider_email_sent_over_3_weeks_ago_verified.eligibility.reload.provider_verification_email_last_sent_at).to eq DateTime.new(2024, 10, 1, 7, 0, 0) + expect(claim_with_provider_email_sent_over_3_weeks_ago_verified.eligibility.reload.provider_verification_chase_email_last_sent_at).to be_nil expect(ClaimMailer).to( have_received(:further_education_payment_provider_verification_chase_email) @@ -115,5 +151,35 @@ .exactly(0).times ) end + + it "does not send a chaser email if one has been sent before" do + expect(claim_with_provider_chase_email_already_sent.eligibility.reload.provider_verification_chase_email_last_sent_at).to eq DateTime.new(2024, 9, 22, 8, 0, 0) + + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_chase_email) + .with(claim_with_provider_chase_email_already_sent) + .exactly(0).times + ) + end + + it "does not send a chaser email if the claim has been rejected" do + expect(claim_rejected_after_provider_verification_was_sent.eligibility.reload.provider_verification_chase_email_last_sent_at).to be_nil + + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_chase_email) + .with(claim_rejected_after_provider_verification_was_sent) + .exactly(0).times + ) + end + + it "does not send a chaser email if the claimis on hold" do + expect(claim_held_after_provider_verification_was_sent.eligibility.reload.provider_verification_chase_email_last_sent_at).to be_nil + + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_chase_email) + .with(claim_held_after_provider_verification_was_sent) + .exactly(0).times + ) + end end end diff --git a/spec/models/policies/further_education_payments/provider_verfication_emails_spec.rb b/spec/models/policies/further_education_payments/provider_verfication_emails_spec.rb index 4faeba68a0..134717fa6e 100644 --- a/spec/models/policies/further_education_payments/provider_verfication_emails_spec.rb +++ b/spec/models/policies/further_education_payments/provider_verfication_emails_spec.rb @@ -43,7 +43,7 @@ ) ) - expect(claim.eligibility.reload.provider_verification_email_last_sent_at).to eq Time.now + expect(claim.eligibility.reload.provider_verification_chase_email_last_sent_at).to eq Time.now end end end From 850e3ee5a5a6a1088b861d289855a47e50653337 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Mon, 23 Sep 2024 14:53:05 +0100 Subject: [PATCH 08/11] Add link to view tasks Adds a link to the task index page as per the figma designs --- app/views/admin/tasks/_claim_summary.html.erb | 1 + .../tasks/_claim_summary_further_education_payments.html.erb | 1 + .../_claim_summary_international_relocation_payments.html.erb | 1 + 3 files changed, 3 insertions(+) diff --git a/app/views/admin/tasks/_claim_summary.html.erb b/app/views/admin/tasks/_claim_summary.html.erb index 6197d0c2b5..f99af0d224 100644 --- a/app/views/admin/tasks/_claim_summary.html.erb +++ b/app/views/admin/tasks/_claim_summary.html.erb @@ -5,6 +5,7 @@ <%= claim_summary_heading(claim) %> + <%= link_to "View tasks", admin_claim_tasks_path(claim), class: "govuk-link" unless current_page? admin_claim_tasks_path(@claim) %> <%= link_to "View full claim", admin_claim_path(claim), class: "govuk-link" %> <%= link_to "Amend claim", new_admin_claim_amendment_path(claim), class: "govuk-link" if claim.amendable? %> <%= link_to "Top up claim", new_admin_claim_topup_path(@claim), class: "govuk-link" if @claim.topupable? %> diff --git a/app/views/admin/tasks/_claim_summary_further_education_payments.html.erb b/app/views/admin/tasks/_claim_summary_further_education_payments.html.erb index 39b790187f..4f88ba0ad7 100644 --- a/app/views/admin/tasks/_claim_summary_further_education_payments.html.erb +++ b/app/views/admin/tasks/_claim_summary_further_education_payments.html.erb @@ -5,6 +5,7 @@ <%= claim_summary_heading(claim) %> + <%= link_to "View tasks", admin_claim_tasks_path(claim), class: "govuk-link" %> <%= link_to "View full claim", admin_claim_path(claim), class: "govuk-link" %> <%= link_to "Amend claim", new_admin_claim_amendment_path(claim), class: "govuk-link" if claim.amendable? %> <%= link_to "Top up claim", new_admin_claim_topup_path(@claim), class: "govuk-link" if @claim.topupable? %> diff --git a/app/views/admin/tasks/_claim_summary_international_relocation_payments.html.erb b/app/views/admin/tasks/_claim_summary_international_relocation_payments.html.erb index d62e8afb41..1c165b75a0 100644 --- a/app/views/admin/tasks/_claim_summary_international_relocation_payments.html.erb +++ b/app/views/admin/tasks/_claim_summary_international_relocation_payments.html.erb @@ -5,6 +5,7 @@ <%= claim_summary_heading(claim) %> + <%= link_to "View tasks", admin_claim_tasks_path(claim), class: "govuk-link" %> <%= link_to "View full claim", admin_claim_path(claim), class: "govuk-link" %> <%= link_to "Amend claim", new_admin_claim_amendment_path(claim), class: "govuk-link" if claim.amendable? %> <%= link_to "Top up claim", new_admin_claim_topup_path(@claim), class: "govuk-link" if @claim.topupable? %> From 8a208fc593198c84cee8aafdde2510c4efedfdc3 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Mon, 23 Sep 2024 15:31:59 +0100 Subject: [PATCH 09/11] Amend sla timeframes --- app/views/additional_payments/landing_page.html.erb | 2 +- app/views/submissions/_confirmation.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/additional_payments/landing_page.html.erb b/app/views/additional_payments/landing_page.html.erb index b49e8f64fd..1dad8b7474 100644 --- a/app/views/additional_payments/landing_page.html.erb +++ b/app/views/additional_payments/landing_page.html.erb @@ -64,7 +64,7 @@

- Payments are given up to 16 weeks from applying. You will receive an approval email with further information on your application. + Payments are given up to 26 weeks from applying. You will receive an approval email with further information on your application.

<%= govuk_details(summary_text: "The different additional payments") do %> diff --git a/app/views/submissions/_confirmation.html.erb b/app/views/submissions/_confirmation.html.erb index ddac160bc8..d961059416 100644 --- a/app/views/submissions/_confirmation.html.erb +++ b/app/views/submissions/_confirmation.html.erb @@ -3,7 +3,7 @@

- Payments are given up to 16 weeks from applying. We will email you updates on the progress of your application. + Payments are given up to 26 weeks from applying. We will email you updates on the progress of your application.

@@ -12,7 +12,7 @@

  • - whether your application is accepted or rejected, usually within 12 weeks + whether your application is accepted or rejected, usually within 20 weeks
  • when your payment has been made, with a full breakdown of how much you have received From e4badd60c17f66c470b1378c0ceb303480cc8ccf Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Fri, 20 Sep 2024 16:30:56 +0100 Subject: [PATCH 10/11] Update the copy for the teaching hours question We want to make sure the question clearly reflects the policy intent. --- config/locales/en.yml | 8 ++++---- ...n_claim_further_education_payments_spec.rb | 4 ++-- ...l_claim_further_education_payments_spec.rb | 2 +- .../happy_js_path_spec.rb | 2 +- .../happy_path_spec.rb | 2 +- .../ineligible_paths_spec.rb | 20 +++++++++---------- .../provider_verifying_claims_spec.rb | 12 +++++------ .../provider/verify_claim_form_spec.rb | 4 ++-- .../answers_presenter_spec.rb | 2 +- ...ligibility_admin_answers_presenter_spec.rb | 6 +++--- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 57f882fdbb..30875ddd66 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -895,8 +895,8 @@ en: teaching_hours_per_week: label: "Timetabled teaching hours" claimant_answers: - more_than_12: "More than 12 hours per week" - between_2_5_and_12: "Between 2.5 and 12 hours per week" + more_than_12: "12 hours or more per week" + between_2_5_and_12: "2.5 hours or more but less than 12 hours per week" less_than_2_5: "Less than 2.5 hours per week" half_teaching_hours: label: "Age range taught" @@ -988,8 +988,8 @@ en: On average, how many hours per week are you timetabled to teach at %{school_name} during the current term? hint: ‘Timetabled teaching hours’ refers to the time you spend teaching lessons to students of all ages. options: - more_than_12: More than 12 hours per week - between_2_5_and_12: Between 2.5 and 12 hours per week + more_than_12: 12 hours or more per week + between_2_5_and_12: 2.5 hours or more but less than 12 hours per week less_than_2_5: Less than 2.5 hours per week errors: inclusion: Select the number of hours you are timetabled to teach per week at %{school_name} during the current term diff --git a/spec/features/admin/admin_claim_further_education_payments_spec.rb b/spec/features/admin/admin_claim_further_education_payments_spec.rb index 288b77f5e3..8c1220a5ec 100644 --- a/spec/features/admin/admin_claim_further_education_payments_spec.rb +++ b/spec/features/admin/admin_claim_further_education_payments_spec.rb @@ -339,7 +339,7 @@ end within_table_row("Timetabled teaching hours") do |claimant, provider| - expect(claimant).to have_text("More than 12 hours per week") + expect(claimant).to have_text("12 hours or more per week") expect(provider).to have_text("Yes") end @@ -435,7 +435,7 @@ end within_table_row("Timetabled teaching hours") do |claimant, provider| - expect(claimant).to have_text("More than 12 hours per week") + expect(claimant).to have_text("12 hours or more per week") expect(provider).to have_text("Yes") end diff --git a/spec/features/admin/admin_view_full_claim_further_education_payments_spec.rb b/spec/features/admin/admin_view_full_claim_further_education_payments_spec.rb index 54b0227368..69a2f869a3 100644 --- a/spec/features/admin/admin_view_full_claim_further_education_payments_spec.rb +++ b/spec/features/admin/admin_view_full_claim_further_education_payments_spec.rb @@ -102,7 +102,7 @@ "On average, how many hours per week are you timetabled to teach at " \ "Springfield Elementary during the current term?" ) - ).to have_content("More than 12 hours per week") + ).to have_content("12 hours or more per week") expect( summary_row( diff --git a/spec/features/further_education_payments/happy_js_path_spec.rb b/spec/features/further_education_payments/happy_js_path_spec.rb index 80c8dce091..fa6092c687 100644 --- a/spec/features/further_education_payments/happy_js_path_spec.rb +++ b/spec/features/further_education_payments/happy_js_path_spec.rb @@ -33,7 +33,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{college.name} during the current term?") - choose("More than 12 hours per week") + choose("12 hours or more per week") click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") diff --git a/spec/features/further_education_payments/happy_path_spec.rb b/spec/features/further_education_payments/happy_path_spec.rb index 49404deb8c..32392e7c2c 100644 --- a/spec/features/further_education_payments/happy_path_spec.rb +++ b/spec/features/further_education_payments/happy_path_spec.rb @@ -32,7 +32,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{college.name} during the current term?") - choose("More than 12 hours per week") + choose("12 hours or more per week") click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") diff --git a/spec/features/further_education_payments/ineligible_paths_spec.rb b/spec/features/further_education_payments/ineligible_paths_spec.rb index 7b0f1c8ddd..5ad6a2cef2 100644 --- a/spec/features/further_education_payments/ineligible_paths_spec.rb +++ b/spec/features/further_education_payments/ineligible_paths_spec.rb @@ -196,7 +196,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week") - choose "More than 12 hours per week" + choose "12 hours or more per week" click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") @@ -267,7 +267,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week") - choose "More than 12 hours per week" + choose "12 hours or more per week" click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") @@ -311,7 +311,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week") - choose "More than 12 hours per week" + choose "12 hours or more per week" click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") @@ -359,7 +359,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{eligible_college.name} during the current term?") - choose("More than 12 hours per week") + choose("12 hours or more per week") click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") @@ -395,7 +395,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{eligible_college.name} during the current term?") - choose "More than 12 hours per week" + choose "12 hours or more per week" click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") @@ -461,7 +461,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{eligible_college.name} during the current term?") - choose "More than 12 hours per week" + choose "12 hours or more per week" click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") @@ -527,7 +527,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{eligible_college.name} during the current term?") - choose "More than 12 hours per week" + choose "12 hours or more per week" click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") @@ -619,7 +619,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{eligible_college.name} during the current term?") - choose "More than 12 hours per week" + choose "12 hours or more per week" click_button "Continue" expect(page).to have_content("Are you timetabled to teach at least 2.5 hours per week at #{eligible_college.name} next term?") @@ -659,7 +659,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{eligible_college.name} during the current term?") - choose("More than 12 hours per week") + choose("12 hours or more per week") click_button "Continue" expect(page).to have_content("Are you timetabled to teach at least 2.5 hours per week at #{eligible_college.name} next term?") @@ -695,7 +695,7 @@ click_button "Continue" expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{eligible_college.name} during the current term?") - choose("More than 12 hours per week") + choose("12 hours or more per week") click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") diff --git a/spec/features/further_education_payments/provider/provider_verifying_claims_spec.rb b/spec/features/further_education_payments/provider/provider_verifying_claims_spec.rb index 49ef570ad4..082e27a21a 100644 --- a/spec/features/further_education_payments/provider/provider_verifying_claims_spec.rb +++ b/spec/features/further_education_payments/provider/provider_verifying_claims_spec.rb @@ -469,8 +469,8 @@ end within_fieldset( - "Is Edna Krabappel timetabled to teach an average of more than 12 " \ - "hours per week during the current term?" + "Is Edna Krabappel timetabled to teach an average of 12 hours or more " \ + "per week during the current term?" ) do choose "Yes" end @@ -600,8 +600,8 @@ end within_fieldset( - "Is Edna Krabappel timetabled to teach an average of between 2.5 and " \ - "12 hours per week during the current term?" + "Is Edna Krabappel timetabled to teach an average of 2.5 hours or " \ + "more but less than 12 hours per week" ) do choose "Yes" end @@ -740,8 +740,8 @@ end within_fieldset( - "Is Edna Krabappel timetabled to teach an average of between 2.5 and " \ - "12 hours per week during the current term?" + "Is Edna Krabappel timetabled to teach an average of 2.5 hours or " \ + "more but less than 12 hours per week during the current term?" ) do choose "Yes" end diff --git a/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb b/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb index 0f1422b821..688724d4f3 100644 --- a/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb +++ b/spec/forms/journeys/further_education_payments/provider/verify_claim_form_spec.rb @@ -206,7 +206,7 @@ context "when more that 12" do it do is_expected.not_to(allow_value(nil).for(:outcome).with_message( - "Select yes if Edna is timetabled to teach an average of more than 12 hours per week during the current term" + "Select yes if Edna is timetabled to teach an average of 12 hours or more per week during the current term" )) end end @@ -216,7 +216,7 @@ it do is_expected.not_to(allow_value(nil).for(:outcome).with_message( - "Select yes if Edna is timetabled to teach an average of between 2.5 and 12 hours per week during the current term" + "Select yes if Edna is timetabled to teach an average of 2.5 hours or more but less than 12 hours per week during the current term" )) end end diff --git a/spec/models/journeys/further_education_payments/answers_presenter_spec.rb b/spec/models/journeys/further_education_payments/answers_presenter_spec.rb index c0464e7e90..a68fb788be 100644 --- a/spec/models/journeys/further_education_payments/answers_presenter_spec.rb +++ b/spec/models/journeys/further_education_payments/answers_presenter_spec.rb @@ -119,7 +119,7 @@ ["Are you a member of staff with teaching responsibilities?", "Yes", "teaching-responsibilities"], ["Which FE provider are you employed by?", college.name, "further-education-provision-search"], ["What type of contract do you have with #{college.name}?", "Permanent contract", "contract-type"], - ["On average, how many hours per week are you timetabled to teach at #{college.name} during the current term?", "More than 12 hours per week", "teaching-hours-per-week"], + ["On average, how many hours per week are you timetabled to teach at #{college.name} during the current term?", "12 hours or more per week", "teaching-hours-per-week"], ["Which academic year did you start teaching in further education (FE) in England?", "September 2023 to August 2024", "further-education-teaching-start-year"], ["Which subject areas do you teach?", "

    Chemistry

    Maths

    ", "subjects-taught"], ["Building and construction courses", "

    Qualifications approved for funding at level 3 and below in the building and construction sector subject area

    T Level in building services engineering for construction

    T Level in onsite construction

    T Level in design, surveying and planning for construction

    Level 2 or level 3 apprenticeships in the construction and the built environment occupational route

    ", "building-construction-courses"], diff --git a/spec/models/policies/further_education_payments/eligibility_admin_answers_presenter_spec.rb b/spec/models/policies/further_education_payments/eligibility_admin_answers_presenter_spec.rb index 4e619bd30e..5330c697c6 100644 --- a/spec/models/policies/further_education_payments/eligibility_admin_answers_presenter_spec.rb +++ b/spec/models/policies/further_education_payments/eligibility_admin_answers_presenter_spec.rb @@ -83,7 +83,7 @@ ], [ "On average, how many hours per week are you timetabled to teach at Springfield Elementary during the current term?", - "More than 12 hours per week" + "12 hours or more per week" ] ] ) @@ -141,7 +141,7 @@ ], [ "On average, how many hours per week are you timetabled to teach at Springfield Elementary during the current term?", - "Between 2.5 and 12 hours per week" + "2.5 hours or more but less than 12 hours per week" ], [ "Are you timetabled to teach at least 2.5 hours per week at Springfield Elementary next term?", @@ -174,7 +174,7 @@ ], [ "On average, how many hours per week are you timetabled to teach at Springfield Elementary during the current term?", - "Between 2.5 and 12 hours per week" + "2.5 hours or more but less than 12 hours per week" ], [ "Are you timetabled to teach at least 2.5 hours per week at Springfield Elementary next term?", From b5f0f721bdf0e8597c75d09e37edc4d3c415a5b7 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Fri, 20 Sep 2024 16:30:36 +0100 Subject: [PATCH 11/11] CAPT-1818 - IRP add rejection reason for claimed last year --- app/helpers/claim_mailer_helper.rb | 6 ++++ app/mailers/claim_mailer.rb | 1 + .../international_relocation_payments.rb | 3 +- config/locales/en.yml | 1 + spec/factories/claims.rb | 9 ++++-- spec/mailers/claim_mailer_spec.rb | 32 +++++++++++++++++-- 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app/helpers/claim_mailer_helper.rb b/app/helpers/claim_mailer_helper.rb index 3cd6dab39c..ad297b4f19 100644 --- a/app/helpers/claim_mailer_helper.rb +++ b/app/helpers/claim_mailer_helper.rb @@ -5,6 +5,12 @@ def rejected_reasons_personalisation(reasons) rejected_reasons_with_answers(reasons) end + def rejected_reason_claimed_last_year? + return false unless @claim.policy == Policies::InternationalRelocationPayments + + @claim.latest_decision&.rejected_reasons_hash&.[](:reason_claimed_last_year) == "1" + end + private def rejected_reasons_with_answers(reasons) diff --git a/app/mailers/claim_mailer.rb b/app/mailers/claim_mailer.rb index ee00fc7970..dc234f8e1c 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -35,6 +35,7 @@ def rejected(claim) ref_number: @claim.reference, support_email_address: @support_email_address, current_financial_year: (claim.policy == Policies::StudentLoans) ? Policies::StudentLoans.current_financial_year : "", + last_academic_year: rejected_reason_claimed_last_year? ? (AcademicYear.current - 1).to_s : "", **rejected_reasons_personalisation(@claim.latest_decision&.rejected_reasons_hash) } diff --git a/app/models/policies/international_relocation_payments.rb b/app/models/policies/international_relocation_payments.rb index 1fab9ff267..71b6bc465b 100644 --- a/app/models/policies/international_relocation_payments.rb +++ b/app/models/policies/international_relocation_payments.rb @@ -19,7 +19,8 @@ module InternationalRelocationPayments :no_response_from_school, :suspected_fraud, :information_mismatch_new_details_needed, - :ineligible_previous_residency + :ineligible_previous_residency, + :claimed_last_year ] # Attributes to delete from claims submitted before the current academic diff --git a/config/locales/en.yml b/config/locales/en.yml index 30875ddd66..c0e041b482 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -810,6 +810,7 @@ en: suspected_fraud: Suspected fraud information_mismatch_new_details_needed: "Information mismatch - new details needed" ineligible_previous_residency: Ineligible previous residency + claimed_last_year: "Claimed last year" eligibility_answers: nationality: "Nationality" passport_number: "Passport number" diff --git a/spec/factories/claims.rb b/spec/factories/claims.rb index becd4f94d1..9fb5c21bab 100644 --- a/spec/factories/claims.rb +++ b/spec/factories/claims.rb @@ -10,6 +10,7 @@ eligibility_trait { nil } eligibility_attributes { nil } decision_creator { nil } + rejected_reasons { nil } using_mobile_number_from_tid { false } end @@ -153,9 +154,13 @@ trait :rejected do submitted - after(:build) do |claim| + after(:build) do |claim, evaluator| claim.save - create(:decision, :rejected, claim: claim) + if evaluator.rejected_reasons + create(:decision, :rejected, claim: claim, rejected_reasons: evaluator.rejected_reasons) + else + create(:decision, :rejected, claim: claim) + end end end diff --git a/spec/mailers/claim_mailer_spec.rb b/spec/mailers/claim_mailer_spec.rb index e5a7064d3e..56f577f893 100644 --- a/spec/mailers/claim_mailer_spec.rb +++ b/spec/mailers/claim_mailer_spec.rb @@ -126,6 +126,7 @@ class SomePolicy; end describe "#rejected" do let(:claim) { build(:claim, :rejected, policy: policy) } let(:mail) { ClaimMailer.rejected(claim) } + let(:expected_last_academic_year) { "" } it_behaves_like "an email related to a claim using GOVUK Notify templates", policy @@ -135,7 +136,8 @@ class SomePolicy; end first_name: claim.first_name, ref_number: claim.reference, support_email_address: I18n.t("#{claim.policy.locale_key}.support_email_address"), - current_financial_year: (policy == Policies::StudentLoans) ? Policies::StudentLoans.current_financial_year : "" + current_financial_year: (policy == Policies::StudentLoans) ? Policies::StudentLoans.current_financial_year : "", + last_academic_year: expected_last_academic_year } end let(:all_expected_keys) { expected_common_keys.merge(expected_rejected_reasons_keys) } @@ -228,7 +230,33 @@ class SomePolicy; end reason_no_response_from_school: "no", reason_suspected_fraud: "no", reason_information_mismatch_new_details_needed: "no", - reason_ineligible_previous_residency: "no" + reason_ineligible_previous_residency: "no", + reason_claimed_last_year: "no" + } + end + + include_examples "template id and personalisation keys" + end + + context "when InternationalRelocationPayments, rejected with claimed_last_year", if: policy == Policies::InternationalRelocationPayments do + let(:claim) { build(:claim, :rejected, policy: policy, rejected_reasons: {claimed_last_year: "1"}) } + + let(:expected_last_academic_year) { (journey_configuration.current_academic_year - 1).to_s } + + let(:expected_template_id) { "1edc468c-a1bf-4bea-bb79-042740cd8547" } + + let(:expected_rejected_reasons_keys) do + { + reason_duplicate: "no", + reason_ineligible_school: "no", + reason_invalid_bank_details: "no", + reason_ineligible_visa_or_entry_date: "no", + reason_ineligible_employment_terms: "no", + reason_no_response_from_school: "no", + reason_suspected_fraud: "no", + reason_information_mismatch_new_details_needed: "no", + reason_ineligible_previous_residency: "no", + reason_claimed_last_year: "yes" } end