Skip to content

Commit

Permalink
Expose multi cohort in admin dashboard
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ethax-ross committed May 29, 2024
1 parent c344441 commit ad81810
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions app/presenters/admin/participant_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions spec/presenters/admin/participant_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ad81810

Please sign in to comment.