diff --git a/app/controllers/personas_controller.rb b/app/controllers/personas_controller.rb index 1eb67958ea..2d5a16b5a6 100644 --- a/app/controllers/personas_controller.rb +++ b/app/controllers/personas_controller.rb @@ -117,7 +117,14 @@ def load_eligible_personas %w[online written none] .product( %w[online written none], - %w[draft not_started verification awarded declined], + %w[ + draft + not_started + waiting_on_consent + waiting_on_further_information + awarded + declined + ], ) .map do |status_check, sanction_check, stage_or_status| { status_check:, sanction_check:, stage_or_status: } @@ -148,13 +155,8 @@ def load_teacher_personas stage_or_status = persona[:stage_or_status] - if stage_or_status == "awarded" - application_form.awarded_at.present? - elsif stage_or_status == "declined" - application_form.declined_at.present? - else - application_form.stage == stage_or_status - end + application_form.stage == stage_or_status || + application_form.statuses.include?(stage_or_status) end if (application_form = found_application_form) diff --git a/lib/tasks/example_data.rake b/lib/tasks/example_data.rake index b7defa4890..1d145fb08f 100644 --- a/lib/tasks/example_data.rake +++ b/lib/tasks/example_data.rake @@ -156,12 +156,6 @@ def application_form_traits_for(region) end def create_requestables(application_form, assessment, state) - status_prefix = { - expired: "overdue", - received: "received", - requested: "waiting_on", - }.fetch(state) - unless application_form.teaching_authority_provides_written_statement assessment.sections.update_all(passed: true) end @@ -173,18 +167,6 @@ def create_requestables(application_form, assessment, state) ) FactoryBot.create(:professional_standing_request, state, assessment:) - application_form.update!( - statuses: ["#{status_prefix}_lops"], - stage: - ( - if application_form.teaching_authority_provides_written_statement - "pre_assessment" - else - "verification" - end - ), - ) - unless application_form.teaching_authority_provides_written_statement assessment.verify! end @@ -194,26 +176,18 @@ def create_requestables(application_form, assessment, state) FactoryBot.create(:reference_request, state, assessment:, work_history:) end - application_form.update!( - statuses: ["#{status_prefix}_reference"], - stage: "verification", - ) assessment.verify! elsif (qualifications = application_form.qualifications).present? && rand(2).zero? qualifications.each do |qualification| FactoryBot.create( :qualification_request, - state, + [state, "consent_#{state}"].sample, assessment:, qualification:, ) end - application_form.update!( - statuses: ["#{status_prefix}_qualification"], - stage: "verification", - ) assessment.verify! elsif state != :expired FactoryBot.create( @@ -222,12 +196,13 @@ def create_requestables(application_form, assessment, state) :with_items, assessment:, ) - application_form.update!( - statuses: ["#{status_prefix}_further_information"], - stage: "assessment", - ) assessment.request_further_information! end + + ApplicationFormStatusUpdater.call( + application_form:, + user: "Example data generator", + ) end def create_application_forms diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index 43cbd1ee91..a3c86b3031 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -50,6 +50,18 @@ end end + trait :consent_received do + consent_requested + consent_received_at do + Faker::Time.between(from: 1.month.ago, to: Time.zone.now) + end + end + + trait :consent_expired do + consent_requested + expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + trait :requested do requested_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end