From ad81810fa81933d0aef719a22596f0261ef84ebb Mon Sep 17 00:00:00 2001 From: Ross Oliver Date: Wed, 29 May 2024 08:45:19 +0100 Subject: [PATCH] Expose multi cohort in admin dashboard We want it to be clear in the admin dashboard participants view when a participant has migrated from a cohort due to the payments being frozen. --- app/helpers/admin_helper.rb | 3 +- app/presenters/admin/participant_presenter.rb | 13 ++++++++ .../admin/participant_presenter_spec.rb | 32 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index b4e5b32ac70..39361df5049 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -54,7 +54,6 @@ def admin_participant_header_and_title(presenter:, section:) full_name = profile.full_name role = admin_participant_role_name(profile.class.name) trn = profile.teacher_profile.trn - start_year = presenter.start_year visually_hidden = tag.span(" - #{section}", class: "govuk-visually-hidden") @@ -75,7 +74,7 @@ def admin_participant_header_and_title(presenter:, section:) safe_join( [ tag.span("Cohort: ", class: "govuk-body govuk-!-font-weight-bold"), - start_year, + presenter.detailed_cohort_information, ], ) end, diff --git a/app/presenters/admin/participant_presenter.rb b/app/presenters/admin/participant_presenter.rb index 6ce24b12616..25d1263cdf6 100644 --- a/app/presenters/admin/participant_presenter.rb +++ b/app/presenters/admin/participant_presenter.rb @@ -21,6 +21,19 @@ def cohort relevant_cohort_location.cohort end + def detailed_cohort_information + current_cohort = cohort.start_year + + return current_cohort unless participant_profile.cohort_changed_after_payments_frozen + + original_cohort = participant_profile.participant_declarations + .includes(:cohort) + .where.not(cohort: { start_year: current_cohort }) + .pick("cohort.start_year") + + "#{current_cohort} (migrated after #{original_cohort || 'unknown cohort'} payments were frozen)" + end + def declarations @declarations ||= @participant_profile .participant_declarations diff --git a/spec/presenters/admin/participant_presenter_spec.rb b/spec/presenters/admin/participant_presenter_spec.rb index 146ecd228e5..4e97d69e29d 100644 --- a/spec/presenters/admin/participant_presenter_spec.rb +++ b/spec/presenters/admin/participant_presenter_spec.rb @@ -136,6 +136,38 @@ end end + describe "#detailed_cohort_information" do + let(:participant_profile) { create(:ect) } + let(:cohort) { participant_profile.schedule.cohort } + let(:detailed_cohort_information) { subject.detailed_cohort_information } + + context "when the participant has not had cohort_changed_after_payments_frozen" do + before { participant_profile.update!(cohort_changed_after_payments_frozen: false) } + + it { expect(detailed_cohort_information).to eq(cohort.start_year) } + end + + context "when the participant has had cohort_changed_after_payments_frozen" do + before { participant_profile.update!(cohort_changed_after_payments_frozen: true) } + + context "when the previous cohort cannot be determined" do + it { expect(detailed_cohort_information).to eq("#{cohort.start_year} (migrated after unknown cohort payments were frozen)") } + end + + context "when the previous cohort can be determined" do + let(:previous_cohort) { Cohort.previous } + let(:cpd_lead_provider) { participant_profile.lead_provider.cpd_lead_provider } + let(:course_identifier) { "ecf-induction" } + + before do + create(:participant_declaration, participant_profile:, cohort: previous_cohort, state: :paid, cpd_lead_provider:, course_identifier:) + end + + it { expect(detailed_cohort_information).to eq("#{cohort.start_year} (migrated after #{previous_cohort.start_year} payments were frozen)") } + end + end + end + describe "#start_year" do it "returns the start_year via induction record, school cohort and cohort" do expect(subject.start_year).to eql(subject.relevant_induction_record.school_cohort.cohort.start_year)