From 4f4a3fe5461b23e7cbc363623eee2a94df6137e9 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 14 Sep 2023 16:57:12 +0100 Subject: [PATCH] Update statuses This adds the ability for the status updater class to also update the statuses value, ensuring that it's kept up to date with the status. --- app/components/status_tag/component.rb | 6 + app/lib/application_form_status_updater.rb | 108 ++++++++++++------ config/locales/components.en.yml | 6 + .../application_form_status_updater_spec.rb | 51 ++++++++- 4 files changed, 129 insertions(+), 42 deletions(-) diff --git a/app/components/status_tag/component.rb b/app/components/status_tag/component.rb index 6c56e0129c..227f1aad23 100644 --- a/app/components/status_tag/component.rb +++ b/app/components/status_tag/component.rb @@ -23,6 +23,7 @@ def classes accepted: "green", assessment: "blue", assessment_in_progress: "blue", + assessment_not_started: "grey", awarded: "green", awarded_pending_checks: "turquoise", cannot_start: "grey", @@ -34,6 +35,7 @@ def classes not_started: "grey", overdue: "pink", overdue_further_information: "pink", + overdue_lops: "pink", overdue_professional_standing: "pink", overdue_qualification: "pink", overdue_reference: "pink", @@ -42,6 +44,7 @@ def classes preliminary_check: "pink", received: "purple", received_further_information: "purple", + received_lops: "purple", received_professional_standing: "purple", received_qualification: "purple", received_reference: "purple", @@ -51,8 +54,11 @@ def classes submitted: "grey", valid: "green", verification: "yellow", + verification_in_progress: "blue", + verification_not_started: "grey", waiting_on: "yellow", waiting_on_further_information: "yellow", + waiting_on_lops: "yellow", waiting_on_professional_standing: "yellow", waiting_on_qualification: "yellow", waiting_on_reference: "yellow", diff --git a/app/lib/application_form_status_updater.rb b/app/lib/application_form_status_updater.rb index 34466c9921..f96c2b5286 100644 --- a/app/lib/application_form_status_updater.rb +++ b/app/lib/application_form_status_updater.rb @@ -12,15 +12,15 @@ def call ActiveRecord::Base.transaction do application_form.update!( overdue_further_information:, - overdue_professional_standing:, + overdue_professional_standing: overdue_lops, overdue_qualification:, overdue_reference:, received_further_information:, - received_professional_standing:, + received_professional_standing: received_lops, received_qualification:, received_reference:, waiting_on_further_information:, - waiting_on_professional_standing:, + waiting_on_professional_standing: waiting_on_lops, waiting_on_qualification:, waiting_on_reference:, ) @@ -52,6 +52,8 @@ def call new_value: stage, ) end + + application_form.update!(statuses:) end end @@ -63,7 +65,7 @@ def overdue_further_information overdue?(requestables: further_information_requests) end - def overdue_professional_standing + def overdue_lops return false if teaching_authority_provides_written_statement overdue?(requestables: professional_standing_requests) end @@ -81,7 +83,7 @@ def received_further_information received?(requestables: further_information_requests) end - def received_professional_standing + def received_lops return false if teaching_authority_provides_written_statement professional_standing_requests @@ -125,7 +127,7 @@ def waiting_on_further_information waiting_on?(requestables: further_information_requests) end - def waiting_on_professional_standing + def waiting_on_lops waiting_on?(requestables: professional_standing_requests) end @@ -152,15 +154,14 @@ def status "awarded_pending_checks" elsif preliminary_check? "preliminary_check" - elsif overdue_further_information || overdue_professional_standing || + elsif overdue_further_information || overdue_lops || overdue_qualification || overdue_reference "overdue" - elsif received_further_information || received_professional_standing || + elsif received_further_information || received_lops || received_qualification || received_reference "received" - elsif waiting_on_further_information || - waiting_on_professional_standing || waiting_on_qualification || - waiting_on_reference + elsif waiting_on_further_information || waiting_on_lops || + waiting_on_qualification || waiting_on_reference "waiting_on" elsif assessment&.any_not_preliminary_section_finished? "assessment_in_progress" @@ -173,19 +174,22 @@ def status def action_required_by @action_required_by ||= - if status == "preliminary_check" + if application_form.withdrawn_at.present? || + application_form.declined_at.present? || + application_form.awarded_at.present? + "none" + elsif preliminary_check? "admin" - elsif %w[ - potential_duplicate_in_dqt - awarded_pending_checks - overdue - received - assessment_in_progress - submitted - ].include?(status) + elsif dqt_trn_request.present? || overdue_further_information || + overdue_lops || overdue_qualification || overdue_reference || + received_further_information || received_lops || + received_qualification || received_reference "assessor" - elsif status == "waiting_on" + elsif waiting_on_further_information || waiting_on_lops || + waiting_on_qualification || waiting_on_reference "external" + elsif application_form.submitted_at.present? + "assessor" else "none" end @@ -200,19 +204,11 @@ def stage elsif dqt_trn_request.present? "review" elsif preliminary_check? || - ( - teaching_authority_provides_written_statement && - waiting_on_professional_standing - ) + (teaching_authority_provides_written_statement && waiting_on_lops) "pre_assessment" - elsif overdue_professional_standing || overdue_qualification || - overdue_reference || - ( - !teaching_authority_provides_written_statement && - received_professional_standing - ) || received_qualification || received_reference || - waiting_on_professional_standing || waiting_on_qualification || - waiting_on_reference + elsif overdue_lops || overdue_qualification || overdue_reference || + received_lops || received_qualification || received_reference || + waiting_on_lops || waiting_on_qualification || waiting_on_reference "verification" elsif overdue_further_information || received_further_information || waiting_on_further_information || @@ -225,6 +221,35 @@ def stage end end + def statuses + @statuses ||= + if application_form.withdrawn_at.present? + %w[withdrawn] + elsif application_form.declined_at.present? + %w[declined] + elsif application_form.awarded_at.present? + %w[awarded] + elsif dqt_trn_request.present? + if dqt_trn_request.potential_duplicate? + %w[potential_duplicate_in_dqt] + else + %w[awarded_pending_checks] + end + elsif assessment.present? + if preliminary_check? + %w[preliminary_check] + requestable_statuses + elsif requestable_statuses.present? + requestable_statuses + elsif assessment.any_not_preliminary_section_finished? + %w[assessment_in_progress] + else + %w[assessment_not_started] + end + else + %w[draft] + end + end + delegate :assessment, :dqt_trn_request, :region, @@ -234,14 +259,23 @@ def stage delegate :references_verified, to: :assessment, allow_nil: true def preliminary_check? - application_form.submitted_at.present? && - application_form.requires_preliminary_check && + return false if assessment.nil? + + application_form.requires_preliminary_check && ( - assessment&.any_preliminary_section_failed? || - !assessment&.all_preliminary_sections_passed? + assessment.any_preliminary_section_failed? || + !assessment.all_preliminary_sections_passed? ) end + def requestable_statuses + @requestable_statuses ||= + %w[overdue received waiting_on] + .product(%w[further_information lops qualification reference]) + .map { |status, requestable| "#{status}_#{requestable}" } + .filter { |column| send(column) } + end + def further_information_requests @further_information_requests ||= assessment&.further_information_requests&.to_a || [] diff --git a/config/locales/components.en.yml b/config/locales/components.en.yml index adafbdb5e5..f6feb00781 100644 --- a/config/locales/components.en.yml +++ b/config/locales/components.en.yml @@ -4,6 +4,7 @@ en: accepted: Accepted assessment: Assessment assessment_in_progress: Assessment in progress + assessment_not_started: Assessment not started awarded: Awarded awarded_pending_checks: Award pending cannot_start: Cannot start @@ -16,6 +17,7 @@ en: not_started: Not started overdue: Overdue overdue_further_information: Overdue further information + overdue_lops: Overdue LOPS overdue_professional_standing: Overdue professional standing overdue_qualification: Overdue qualification overdue_reference: Overdue reference @@ -24,6 +26,7 @@ en: preliminary_check: Preliminary check received: Received received_further_information: Received further information + received_lops: Received LOPS received_professional_standing: Received professional standing received_qualification: Received qualification received_reference: Received reference @@ -33,8 +36,11 @@ en: submitted: Not started valid: Valid verification: Verification + verification_in_progress: Verification in progress + verification_not_started: Verification not started waiting_on: Waiting on waiting_on_further_information: Waiting on further information + waiting_on_lops: Waiting on LOPS waiting_on_professional_standing: Waiting on professional standing waiting_on_qualification: Waiting on qualification waiting_on_reference: Waiting on reference diff --git a/spec/lib/application_form_status_updater_spec.rb b/spec/lib/application_form_status_updater_spec.rb index 2d785a1a9b..5bf8ec1877 100644 --- a/spec/lib/application_form_status_updater_spec.rb +++ b/spec/lib/application_form_status_updater_spec.rb @@ -56,6 +56,12 @@ end end + shared_examples "changes statuses" do |new_statuses| + it "changes statuses to #{new_statuses}" do + expect { call }.to change(application_form, :statuses).to(new_statuses) + end + end + shared_examples "changes status" do |new_status| it "changes status to #{new_status}" do expect { call }.to change(application_form, :status).to(new_status) @@ -83,6 +89,7 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "review" + include_examples "changes statuses", %w[potential_duplicate_in_dqt] include_examples "changes status", "potential_duplicate_in_dqt" end @@ -96,6 +103,7 @@ include_examples "doesn't change action required by" include_examples "changes stage", "completed" + include_examples "changes statuses", %w[withdrawn] include_examples "changes status", "withdrawn" end @@ -109,6 +117,7 @@ include_examples "doesn't change action required by" include_examples "changes stage", "completed" + include_examples "changes statuses", %w[declined] include_examples "changes status", "declined" end @@ -122,6 +131,7 @@ include_examples "doesn't change action required by" include_examples "changes stage", "completed" + include_examples "changes statuses", %w[awarded] include_examples "changes status", "awarded" end @@ -133,10 +143,11 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "review" + include_examples "changes statuses", %w[awarded_pending_checks] include_examples "changes status", "awarded_pending_checks" end - context "with a received information request" do + context "with a received further information request" do let(:assessment) { create(:assessment, application_form:) } before do @@ -146,6 +157,7 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "assessment" + include_examples "changes statuses", %w[received_further_information] include_examples "changes status", "received" it "changes received_further_information" do @@ -166,6 +178,7 @@ include_examples "changes action required by", "external" include_examples "changes stage", "assessment" + include_examples "changes statuses", %w[waiting_on_further_information] include_examples "changes status", "waiting_on" it "changes waiting_on_further_information" do @@ -186,6 +199,7 @@ include_examples "changes action required by", "external" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[waiting_on_lops] include_examples "changes status", "waiting_on" it "changes waiting_on_professional_standing" do @@ -210,7 +224,7 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "not_started" - include_examples "changes status", "submitted" + include_examples "changes statuses", %w[assessment_not_started] it "doesn't change received_professional_standing" do expect { call }.to_not change( @@ -228,6 +242,7 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[received_lops] include_examples "changes status", "received" it "changes received_professional_standing" do @@ -249,6 +264,7 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[received_qualification] include_examples "changes status", "received" it "changes received_further_information" do @@ -269,6 +285,7 @@ include_examples "changes action required by", "external" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[waiting_on_qualification] include_examples "changes status", "waiting_on" it "changes waiting_on_qualification" do @@ -304,6 +321,7 @@ include_examples "changes action required by", "external" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[waiting_on_reference] include_examples "changes status", "waiting_on" it "doesn't change received_reference" do @@ -334,6 +352,7 @@ context "and it's the only reference request" do include_examples "changes action required by", "assessor" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[received_reference] include_examples "changes status", "received" it "changes received_reference" do @@ -349,6 +368,7 @@ include_examples "changes action required by", "external" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[waiting_on_reference] include_examples "changes status", "waiting_on" it "doesn't change received_reference" do @@ -379,6 +399,7 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[received_reference] include_examples "changes status", "received" it "changes received_reference" do @@ -399,6 +420,7 @@ include_examples "changes action required by", "external" include_examples "changes stage", "verification" + include_examples "changes statuses", %w[waiting_on_reference] include_examples "changes status", "waiting_on" it "changes waiting_on_reference" do @@ -416,14 +438,19 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "assessment" + include_examples "changes statuses", %w[assessment_in_progress] include_examples "changes status", "assessment_in_progress" end - context "with a submitted_at date" do - before { application_form.update!(submitted_at: Time.zone.now) } + context "with an unstarted assessment" do + before do + application_form.update!(submitted_at: Time.zone.now) + create(:assessment, application_form:) + end include_examples "changes action required by", "assessor" include_examples "changes stage", "not_started" + include_examples "changes statuses", %w[assessment_not_started] include_examples "changes status", "submitted" end @@ -435,6 +462,9 @@ it "doesn't record a timeline event" do expect { call }.to_not have_recorded_timeline_event(:state_changed) end + + include_examples "doesn't change action required by" + it "doesn't change the stage from draft" do expect { call }.to_not change(application_form, :stage).from("draft") end @@ -443,7 +473,11 @@ expect { call }.to_not have_recorded_timeline_event(:stage_changed) end - include_examples "doesn't change action required by" + it "doesn't change the statuses from draft" do + expect { call }.to_not change(application_form, :statuses).from( + %w[draft], + ) + end end context "when preliminary check is required" do @@ -462,6 +496,7 @@ include_examples "changes action required by", "admin" include_examples "changes stage", "pre_assessment" + include_examples "changes statuses", %w[preliminary_check] include_examples "changes status", "preliminary_check" context "when teaching authority provides written statement" do @@ -474,6 +509,8 @@ include_examples "changes action required by", "admin" include_examples "changes stage", "pre_assessment" + include_examples "changes statuses", + %w[preliminary_check waiting_on_lops] include_examples "changes status", "preliminary_check" context "when the preliminary check has passed" do @@ -481,6 +518,7 @@ include_examples "changes action required by", "external" include_examples "changes stage", "pre_assessment" + include_examples "changes statuses", %w[waiting_on_lops] include_examples "changes status", "waiting_on" end @@ -495,6 +533,8 @@ include_examples "changes action required by", "admin" include_examples "changes stage", "pre_assessment" + include_examples "changes statuses", + %w[preliminary_check waiting_on_lops] include_examples "changes status", "preliminary_check" context "and the application form is declined" do @@ -502,6 +542,7 @@ include_examples "doesn't change action required by" include_examples "changes stage", "completed" + include_examples "changes statuses", %w[declined] include_examples "changes status", "declined" end end