From 27dfddcf049ea1df4f985b39559a3c44ef54b152 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Thu, 12 Sep 2024 10:13:17 +0100 Subject: [PATCH 1/5] touch readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1bd26d9f9e..823c31e741 100644 --- a/README.md +++ b/README.md @@ -346,3 +346,4 @@ the user IP address as part of the payload data sent to Application Insights in [`lib/application_insights`](lib/application_insights). See [`config/initializers/application_insights.rb`](config/initializers/application_insights.rb) for how to mixin this code to your Rails application. + From 18aea45177d784b2958d917bb0ad91b6abdca9c7 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Thu, 12 Sep 2024 10:13:17 +0100 Subject: [PATCH 2/5] touch readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1bd26d9f9e..823c31e741 100644 --- a/README.md +++ b/README.md @@ -346,3 +346,4 @@ the user IP address as part of the payload data sent to Application Insights in [`lib/application_insights`](lib/application_insights). See [`config/initializers/application_insights.rb`](config/initializers/application_insights.rb) for how to mixin this code to your Rails application. + From 99d3c6b3ab9129d0b6f3f3565f11fe8d29b61617 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Tue, 24 Sep 2024 10:52:43 +0100 Subject: [PATCH 3/5] Set started at on claims #1 Before the introduction of the journey session claims were created at the start of the claimant journey, however as claims are now created at the end of the claimant journey we can no longer use the claim's created at timestamp to infer when the journey was started. --- app/forms/claim_submission_base_form.rb | 2 ++ app/models/claim.rb | 3 ++- config/analytics.yml | 1 + db/migrate/20240924091408_add_started_at_to_claims.rb | 5 +++++ db/schema.rb | 3 ++- .../claim_submission_form_spec.rb | 8 +++++++- .../claim_submission_form_spec.rb | 1 + .../claim_submission_form_spec.rb | 2 ++ .../claim_submission_form_spec.rb | 4 +++- 9 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20240924091408_add_started_at_to_claims.rb diff --git a/app/forms/claim_submission_base_form.rb b/app/forms/claim_submission_base_form.rb index b3e69378ac..f57862ccb9 100644 --- a/app/forms/claim_submission_base_form.rb +++ b/app/forms/claim_submission_base_form.rb @@ -38,6 +38,8 @@ def build_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) diff --git a/app/models/claim.rb b/app/models/claim.rb index 14f8ad26d4..60341ff0f0 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -91,7 +91,8 @@ class Claim < ApplicationRecord onelogin_idv_date_of_birth: true, paye_reference: true, practitioner_email_address: true, - provider_contact_name: true + provider_contact_name: true, + started_at: false }.freeze DECISION_DEADLINE = 12.weeks DECISION_DEADLINE_WARNING_POINT = 2.weeks diff --git a/config/analytics.yml b/config/analytics.yml index d02699e757..4bbf3bdde0 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -78,6 +78,7 @@ shared: - logged_in_with_onelogin - onelogin_auth_at - onelogin_idv_at + - started_at :decisions: - id - result diff --git a/db/migrate/20240924091408_add_started_at_to_claims.rb b/db/migrate/20240924091408_add_started_at_to_claims.rb new file mode 100644 index 0000000000..c76aa91cf2 --- /dev/null +++ b/db/migrate/20240924091408_add_started_at_to_claims.rb @@ -0,0 +1,5 @@ +class AddStartedAtToClaims < ActiveRecord::Migration[7.0] + def change + add_column :claims, :started_at, :timestamp + end +end diff --git a/db/schema.rb b/db/schema.rb index 6908127828..e7efeab458 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_24_091408) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" @@ -111,6 +111,7 @@ t.text "onelogin_idv_first_name" t.text "onelogin_idv_last_name" t.date "onelogin_idv_date_of_birth" + t.datetime "started_at", precision: nil t.index ["academic_year"], name: "index_claims_on_academic_year" t.index ["created_at"], name: "index_claims_on_created_at" t.index ["eligibility_type", "eligibility_id"], name: "index_claims_on_eligibility_type_and_eligibility_id" diff --git a/spec/forms/journeys/additional_payments_for_teaching/claim_submission_form_spec.rb b/spec/forms/journeys/additional_payments_for_teaching/claim_submission_form_spec.rb index 9894459432..1fb557112b 100644 --- a/spec/forms/journeys/additional_payments_for_teaching/claim_submission_form_spec.rb +++ b/spec/forms/journeys/additional_payments_for_teaching/claim_submission_form_spec.rb @@ -79,7 +79,11 @@ end let(:journey_session) do - build(:additional_payments_session, journey: journey::ROUTING_NAME, answers: answers) + create( + :additional_payments_session, + journey: journey::ROUTING_NAME, + answers: answers + ) end let(:form) { described_class.new(journey_session: journey_session) } @@ -262,6 +266,8 @@ expect(journey_session.claim).to eq(claim) + expect(claim.started_at).to eq(journey_session.created_at) + expect(ClaimMailer).to have_received(:submitted).with(claim) expect(ClaimVerifierJob).to have_received(:perform_later).with(claim) 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..8deb8e56ad 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 @@ -40,6 +40,7 @@ expect(claim.logged_in_with_onelogin).to eq(answers.logged_in_with_onelogin) expect(claim.onelogin_credentials).to eq(answers.onelogin_credentials) expect(claim.onelogin_user_info).to eq(answers.onelogin_user_info) + expect(claim.started_at).to eql(journey_session.created_at) expect(claim.onelogin_uid).to eql(answers.onelogin_uid) expect(claim.onelogin_auth_at).to eql(answers.onelogin_auth_at) diff --git a/spec/forms/journeys/get_a_teacher_relocation_payment/claim_submission_form_spec.rb b/spec/forms/journeys/get_a_teacher_relocation_payment/claim_submission_form_spec.rb index 6d7c52ab0c..c2449969bc 100644 --- a/spec/forms/journeys/get_a_teacher_relocation_payment/claim_submission_form_spec.rb +++ b/spec/forms/journeys/get_a_teacher_relocation_payment/claim_submission_form_spec.rb @@ -85,6 +85,8 @@ expect(claim.reference).to be_present + expect(claim.started_at).to eq(journey_session.created_at) + eligibility_answers.each do |attribute, value| expect(eligibility.public_send(attribute)).to eq(value) end diff --git a/spec/forms/journeys/teacher_student_loan_reimbursement/claim_submission_form_spec.rb b/spec/forms/journeys/teacher_student_loan_reimbursement/claim_submission_form_spec.rb index 011f8992cf..0a8ccb00d2 100644 --- a/spec/forms/journeys/teacher_student_loan_reimbursement/claim_submission_form_spec.rb +++ b/spec/forms/journeys/teacher_student_loan_reimbursement/claim_submission_form_spec.rb @@ -72,7 +72,7 @@ } end - let(:journey_session) { build(:student_loans_session, answers: answers) } + let(:journey_session) { create(:student_loans_session, answers: answers) } let(:form) { described_class.new(journey_session: journey_session) } @@ -199,6 +199,8 @@ eq("Policies::StudentLoans::Eligibility") ) + expect(claim.started_at).to eq(journey_session.created_at) + expect(journey_session.claim).to eq(claim) expect(ClaimMailer).to have_received(:submitted).with(claim) From 88c172c083e9354773b05804116cc5ef3b523405 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Tue, 24 Sep 2024 11:23:42 +0100 Subject: [PATCH 4/5] Back fill started at If the claim has a journey session we try and set the `started_at` to that, if it doesn't have a journey session we'll just use the `created_at` timestamp, which for claims pre the introduction of journey sessions will be the started at time. --- ...40924095435_back_fill_claims_started_at.rb | 22 +++++++++++++++++++ db/schema.rb | 2 +- spec/factories/claims.rb | 2 ++ ...qt_in_academic_year_after_itt_form_spec.rb | 5 ++++- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240924095435_back_fill_claims_started_at.rb diff --git a/db/migrate/20240924095435_back_fill_claims_started_at.rb b/db/migrate/20240924095435_back_fill_claims_started_at.rb new file mode 100644 index 0000000000..ec06356841 --- /dev/null +++ b/db/migrate/20240924095435_back_fill_claims_started_at.rb @@ -0,0 +1,22 @@ +class BackFillClaimsStartedAt < ActiveRecord::Migration[7.0] + def up + execute <<-SQL + UPDATE claims + SET started_at = journeys_sessions.created_at + FROM journeys_sessions + WHERE claims.journeys_session_id = journeys_sessions.id + AND claims.started_at IS NULL + SQL + + execute <<-SQL + UPDATE claims + SET started_at = created_at + WHERE journeys_session_id IS NULL + AND claims.started_at IS NULL + SQL + end + + def down + Claim.update_all(started_at: nil) + end +end diff --git a/db/schema.rb b/db/schema.rb index e7efeab458..34f57b1871 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_24_091408) do +ActiveRecord::Schema[7.0].define(version: 2024_09_24_095435) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" diff --git a/spec/factories/claims.rb b/spec/factories/claims.rb index becd4f94d1..7e2f07646d 100644 --- a/spec/factories/claims.rb +++ b/spec/factories/claims.rb @@ -4,6 +4,8 @@ sequence(:national_insurance_number, 100000) { |n| "QQ#{n}C" } factory :claim do + started_at { Time.zone.now } + transient do policy { Policies::StudentLoans } eligibility_factory { :"#{policy.to_s.underscore}_eligibility" } diff --git a/spec/forms/journeys/additional_payments_for_teaching/nqt_in_academic_year_after_itt_form_spec.rb b/spec/forms/journeys/additional_payments_for_teaching/nqt_in_academic_year_after_itt_form_spec.rb index e5895dc716..f85c899f95 100644 --- a/spec/forms/journeys/additional_payments_for_teaching/nqt_in_academic_year_after_itt_form_spec.rb +++ b/spec/forms/journeys/additional_payments_for_teaching/nqt_in_academic_year_after_itt_form_spec.rb @@ -131,7 +131,10 @@ { details_check: true, logged_in_with_tid: true - }.merge(attributes_for(:claim, :with_dqt_teacher_status)) + }.merge( + attributes_for(:claim, :with_dqt_teacher_status) + .except(:started_at) + ) end it "sets the induction as complete" do From 35702cd095b554f132d62002ed363764f85beecc Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Tue, 24 Sep 2024 12:03:56 +0100 Subject: [PATCH 5/5] Show started at Update the admin ui to show the claim started_at time rather than claim created_at time --- app/helpers/admin/claims_helper.rb | 2 +- db/migrate/20240924113642_make_claims_started_at_not_null.rb | 5 +++++ db/schema.rb | 4 ++-- .../admin_view_full_claim_further_education_payments_spec.rb | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20240924113642_make_claims_started_at_not_null.rb diff --git a/app/helpers/admin/claims_helper.rb b/app/helpers/admin/claims_helper.rb index 8c099e60ce..d01366f027 100644 --- a/app/helpers/admin/claims_helper.rb +++ b/app/helpers/admin/claims_helper.rb @@ -54,7 +54,7 @@ def admin_student_loan_details(claim) def admin_submission_details(claim) [ - [translate("admin.started_at"), l(claim.created_at)], + [translate("admin.started_at"), l(claim.started_at)], [translate("admin.submitted_at"), l(claim.submitted_at)], [translate("admin.decision_deadline"), l(claim.decision_deadline_date)], [translate("admin.decision_overdue"), decision_deadline_warning(claim)] diff --git a/db/migrate/20240924113642_make_claims_started_at_not_null.rb b/db/migrate/20240924113642_make_claims_started_at_not_null.rb new file mode 100644 index 0000000000..11346759df --- /dev/null +++ b/db/migrate/20240924113642_make_claims_started_at_not_null.rb @@ -0,0 +1,5 @@ +class MakeClaimsStartedAtNotNull < ActiveRecord::Migration[7.0] + def change + change_column_null :claims, :started_at, false + end +end diff --git a/db/schema.rb b/db/schema.rb index 34f57b1871..ce6f14cd08 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_24_095435) do +ActiveRecord::Schema[7.0].define(version: 2024_09_24_113642) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" @@ -111,7 +111,7 @@ t.text "onelogin_idv_first_name" t.text "onelogin_idv_last_name" t.date "onelogin_idv_date_of_birth" - t.datetime "started_at", precision: nil + t.datetime "started_at", precision: nil, null: false t.index ["academic_year"], name: "index_claims_on_academic_year" t.index ["created_at"], name: "index_claims_on_created_at" t.index ["eligibility_type", "eligibility_id"], name: "index_claims_on_eligibility_type_and_eligibility_id" 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..2d50782575 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 @@ -26,7 +26,7 @@ address_line_4: "Oregon", postcode: "AB12 3CD", email_address: "edna.krabappel@springfield-elementary.edu", - created_at: DateTime.new(2024, 8, 1, 9, 0, 0), + started_at: DateTime.new(2024, 8, 1, 9, 0, 0), submitted_at: DateTime.new(2024, 8, 1, 11, 0, 0), academic_year: AcademicYear.new(2024) )