From 337425ed6c5178de1931956a4990afa22b8ff6c8 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 9 Nov 2023 07:36:37 +0000 Subject: [PATCH 1/4] Reorder ApplicationFormStatusUpdater methods This reorders the methods to make it clearer where they're used. --- app/lib/application_form_status_updater.rb | 154 ++++++++++----------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/app/lib/application_form_status_updater.rb b/app/lib/application_form_status_updater.rb index 3bfac2b5d6..efb97e11a0 100644 --- a/app/lib/application_form_status_updater.rb +++ b/app/lib/application_form_status_updater.rb @@ -58,83 +58,6 @@ def call attr_reader :application_form, :user - def overdue_further_information - overdue?(requestables: further_information_requests) - end - - def overdue_lops - return false if teaching_authority_provides_written_statement - overdue?(requestables: professional_standing_requests) - end - - def overdue_qualification - overdue?(requestables: qualification_requests) - end - - def overdue_reference - return false if references_verified - overdue?(requestables: reference_requests) - end - - def received_further_information - received?(requestables: further_information_requests) - end - - def received_lops - return false if teaching_authority_provides_written_statement - received?(requestables: professional_standing_requests) - end - - def received_qualification - received?(requestables: qualification_requests) - end - - def received_reference - return false unless received?(requestables: reference_requests) - - received_requests = reference_requests.filter(&:received?) - - months_count = - WorkHistoryDuration.for_ids( - received_requests.map(&:work_history_id), - application_form:, - ).count_months - - most_recent_reference_request = - reference_requests.max_by { |request| request.work_history.start_date } - - if months_count < 9 - false - elsif months_count >= 20 && - (region.checks_available? || most_recent_reference_request&.received?) - true - else - reference_requests.all? { |r| r.received? || r.expired? } - end - end - - def waiting_on_further_information - waiting_on?(requestables: further_information_requests) - end - - def waiting_on_lops - waiting_on?(requestables: professional_standing_requests) - end - - def waiting_on_qualification - waiting_on?(requestables: qualification_requests) - end - - def waiting_on_reference - return false if references_verified - waiting_on?(requestables: reference_requests) - end - - def needs_references_verified? - reference_requests.present? && !waiting_on_reference && - references_verified != true - end - def status @status ||= if dqt_trn_request&.potential_duplicate? @@ -295,6 +218,83 @@ def requestable_statuses .filter { |column| send(column) } end + def overdue_further_information + overdue?(requestables: further_information_requests) + end + + def overdue_lops + return false if teaching_authority_provides_written_statement + overdue?(requestables: professional_standing_requests) + end + + def overdue_qualification + overdue?(requestables: qualification_requests) + end + + def overdue_reference + return false if references_verified + overdue?(requestables: reference_requests) + end + + def received_further_information + received?(requestables: further_information_requests) + end + + def received_lops + return false if teaching_authority_provides_written_statement + received?(requestables: professional_standing_requests) + end + + def received_qualification + received?(requestables: qualification_requests) + end + + def received_reference + return false unless received?(requestables: reference_requests) + + received_requests = reference_requests.filter(&:received?) + + months_count = + WorkHistoryDuration.for_ids( + received_requests.map(&:work_history_id), + application_form:, + ).count_months + + most_recent_reference_request = + reference_requests.max_by { |request| request.work_history.start_date } + + if months_count < 9 + false + elsif months_count >= 20 && + (region.checks_available? || most_recent_reference_request&.received?) + true + else + reference_requests.all? { |r| r.received? || r.expired? } + end + end + + def waiting_on_further_information + waiting_on?(requestables: further_information_requests) + end + + def waiting_on_lops + waiting_on?(requestables: professional_standing_requests) + end + + def waiting_on_qualification + waiting_on?(requestables: qualification_requests) + end + + def waiting_on_reference + return false if references_verified + waiting_on?(requestables: reference_requests) + end + + def needs_references_verified? + reference_requests.present? && !waiting_on_reference && + references_verified != true + end + def further_information_requests @further_information_requests ||= assessment&.further_information_requests&.to_a || [] From ea2f00826a89ecd669119aba2f8521200171132f Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 14 Sep 2023 17:00:58 +0100 Subject: [PATCH 2/4] Stop updating statuses This updates the ApplicationFormStatusUpdater service to stop updating the status (and related fields) as we're going to stop using them and instead rely on the replacements. --- app/lib/application_form_status_updater.rb | 49 -------- .../application_form_status_updater_spec.rb | 111 ------------------ 2 files changed, 160 deletions(-) diff --git a/app/lib/application_form_status_updater.rb b/app/lib/application_form_status_updater.rb index efb97e11a0..c0354e3039 100644 --- a/app/lib/application_form_status_updater.rb +++ b/app/lib/application_form_status_updater.rb @@ -10,23 +10,6 @@ def initialize(application_form:, user:) def call ActiveRecord::Base.transaction do - application_form.update!( - overdue_further_information:, - overdue_professional_standing: overdue_lops, - overdue_qualification:, - overdue_reference:, - received_further_information:, - received_professional_standing: received_lops, - received_qualification:, - received_reference:, - waiting_on_further_information:, - waiting_on_professional_standing: waiting_on_lops, - waiting_on_qualification:, - waiting_on_reference:, - ) - - application_form.status = status if application_form.status != status - if (old_action_required_by = application_form.action_required_by) != action_required_by application_form.action_required_by = action_required_by @@ -58,38 +41,6 @@ def call attr_reader :application_form, :user - def status - @status ||= - if dqt_trn_request&.potential_duplicate? - "potential_duplicate_in_dqt" - elsif application_form.withdrawn_at.present? - "withdrawn" - elsif application_form.declined_at.present? - "declined" - elsif application_form.awarded_at.present? - "awarded" - elsif dqt_trn_request.present? - "awarded_pending_checks" - elsif preliminary_check? - "preliminary_check" - elsif overdue_further_information || overdue_lops || - overdue_qualification || overdue_reference - "overdue" - elsif received_further_information || received_lops || - received_qualification || received_reference - "received" - 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" - elsif application_form.submitted_at.present? - "submitted" - else - "draft" - end - end - def action_required_by @action_required_by ||= if application_form.withdrawn_at.present? || diff --git a/spec/lib/application_form_status_updater_spec.rb b/spec/lib/application_form_status_updater_spec.rb index f39ad7a2b8..4c24893330 100644 --- a/spec/lib/application_form_status_updater_spec.rb +++ b/spec/lib/application_form_status_updater_spec.rb @@ -62,12 +62,6 @@ 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) - end - end - describe "#call" do subject(:call) { described_class.call(application_form:, user:) } @@ -80,7 +74,6 @@ 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 context "with a withdrawn_at date" do @@ -94,7 +87,6 @@ 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 context "with a declined_at date" do @@ -108,7 +100,6 @@ 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 context "with an awarded_at date" do @@ -122,7 +113,6 @@ 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 context "with a DQT TRN request" do @@ -134,7 +124,6 @@ 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 further information request" do @@ -148,14 +137,6 @@ 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 - expect { call }.to change( - application_form, - :received_further_information, - ).from(false).to(true) - end end context "with a requested further information request" do @@ -169,14 +150,6 @@ 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 - expect { call }.to change( - application_form, - :waiting_on_further_information, - ).from(false).to(true) - end end context "with a requested profession standing request" do @@ -190,14 +163,6 @@ 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 - expect { call }.to change( - application_form, - :waiting_on_professional_standing, - ).from(false).to(true) - end end context "with a received profession standing request" do @@ -215,13 +180,6 @@ include_examples "changes action required by", "assessor" include_examples "changes stage", "not_started" include_examples "changes statuses", %w[assessment_not_started] - - it "doesn't change received_professional_standing" do - expect { call }.to_not change( - application_form, - :received_professional_standing, - ).from(false) - end end context "when the teaching authority doesn't provide the written statement" do @@ -233,14 +191,6 @@ include_examples "changes action required by", "admin" include_examples "changes stage", "verification" include_examples "changes statuses", %w[received_lops] - include_examples "changes status", "received" - - it "changes received_professional_standing" do - expect { call }.to change( - application_form, - :received_professional_standing, - ).from(false).to(true) - end end end @@ -255,14 +205,6 @@ 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 - expect { call }.to change( - application_form, - :received_qualification, - ).from(false).to(true) - end end context "with a requested qualification request" do @@ -276,14 +218,6 @@ 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 - expect { call }.to change( - application_form, - :waiting_on_qualification, - ).from(false).to(true) - end end context "with a received reference request" do @@ -312,14 +246,6 @@ 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 - expect { call }.to_not change( - application_form, - :received_reference, - ).from(false) - end end context "with less than 20 months" do @@ -343,14 +269,6 @@ 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 - expect { call }.to change( - application_form, - :received_reference, - ).from(false).to(true) - end end context "and there are other reference requests" do @@ -359,14 +277,6 @@ 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 - expect { call }.to_not change( - application_form, - :received_reference, - ).from(false) - end end end @@ -390,13 +300,6 @@ 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 - expect { call }.to change(application_form, :received_reference).from( - false, - ).to(true) - end end end @@ -411,13 +314,6 @@ 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 - expect { call }.to change(application_form, :waiting_on_reference).from( - false, - ).to(true) - end end context "when a reviewed assessment" do @@ -451,7 +347,6 @@ 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 an unstarted assessment" do @@ -463,7 +358,6 @@ 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 context "when status is unchanged" do @@ -505,7 +399,6 @@ 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 before do @@ -519,7 +412,6 @@ 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 before { preliminary_assessment_section.update!(passed: true) } @@ -527,7 +419,6 @@ 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 context "when the preliminary check has failed" do @@ -543,7 +434,6 @@ 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 before { application_form.update!(declined_at: Time.zone.now) } @@ -551,7 +441,6 @@ 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 end From 263e9c4bc6c15b6ee80ea185599090d8a0cfad1a Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 14 Sep 2023 17:18:47 +0100 Subject: [PATCH 3/4] Stop using statuses This updates various parts of the system to stop using the status (and related) fields, as they've been replaced by others. --- app/controllers/personas_controller.rb | 8 +-- .../teacher_interface/base_controller.rb | 2 +- app/lib/filters/status.rb | 46 -------------- app/models/application_form.rb | 53 +++++----------- app/models/further_information_request.rb | 4 +- app/models/professional_standing_request.rb | 4 +- app/models/teacher.rb | 2 +- app/services/award_qts.rb | 7 +-- app/services/backfill_preliminary_checks.rb | 12 ++-- app/services/decline_qts.rb | 2 +- app/services/rollback_assessment.rb | 13 ++-- app/services/withdraw_application_form.rb | 2 +- .../application_forms_show_view_object.rb | 10 ++- .../assessment_section_view_object.rb | 4 +- .../application_forms/status.html.erb | 16 ++--- .../application_forms/show.html.erb | 10 +-- lib/tasks/example_data.rake | 11 +--- spec/components/timeline_entry_spec.rb | 7 +-- spec/factories/application_forms.rb | 12 ---- spec/jobs/update_dqt_trn_request_job_spec.rb | 20 +++--- .../application_form_status_updater_spec.rb | 4 -- spec/lib/filters/status_spec.rb | 63 ------------------- spec/models/application_form_spec.rb | 15 ----- spec/services/award_qts_spec.rb | 14 +++-- .../backfill_preliminary_checks_spec.rb | 22 ++++--- spec/services/create_dqt_trn_request_spec.rb | 4 +- ...create_further_information_request_spec.rb | 14 ++--- spec/services/decline_qts_spec.rb | 12 ++-- spec/services/expire_requestable_spec.rb | 2 +- spec/services/receive_requestable_spec.rb | 12 +--- .../update_assessment_section_spec.rb | 14 +++-- spec/services/verify_assessment_spec.rb | 12 +--- .../withdraw_application_form_spec.rb | 12 ---- spec/support/shared_examples.rb | 4 +- .../verifying_professional_standing_spec.rb | 3 +- .../verifying_qualifications_spec.rb | 6 +- .../verifying_references_spec.rb | 3 +- ...pplication_forms_index_view_object_spec.rb | 2 +- 38 files changed, 141 insertions(+), 322 deletions(-) delete mode 100644 app/lib/filters/status.rb delete mode 100644 spec/lib/filters/status_spec.rb diff --git a/app/controllers/personas_controller.rb b/app/controllers/personas_controller.rb index d01aaaecde..5722cbff5a 100644 --- a/app/controllers/personas_controller.rb +++ b/app/controllers/personas_controller.rb @@ -103,10 +103,10 @@ def load_eligible_personas %w[online written none] .product( %w[online written none], - %w[draft submitted waiting_on awarded declined], + %w[draft not_started verification completed], ) - .map do |status_check, sanction_check, status| - { status_check:, sanction_check:, status: } + .map do |status_check, sanction_check, stage| + { status_check:, sanction_check:, stage: } end def load_teacher_personas @@ -129,7 +129,7 @@ def load_teacher_personas region.status_check == persona[:status_check] && region.sanction_check == persona[:sanction_check] && - application_form.status == persona[:status] + application_form.stage == persona[:stage] end if (application_form = found_application_form) diff --git a/app/controllers/teacher_interface/base_controller.rb b/app/controllers/teacher_interface/base_controller.rb index 06892b8536..7410b3c5e6 100644 --- a/app/controllers/teacher_interface/base_controller.rb +++ b/app/controllers/teacher_interface/base_controller.rb @@ -34,7 +34,7 @@ def document end def redirect_unless_application_form_is_draft - if application_form.nil? || !application_form.draft? + if application_form.nil? || application_form.submitted? redirect_to %i[teacher_interface application_form] end end diff --git a/app/lib/filters/status.rb b/app/lib/filters/status.rb deleted file mode 100644 index 6300bc79b4..0000000000 --- a/app/lib/filters/status.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -class Filters::Status < Filters::Base - def apply - return scope if statuses.empty? - - exact_statuses = statuses - BOOLEAN_TO_EXACT_STATUSES.keys - boolean_statuses = statuses - exact_statuses - - scope.merge( - boolean_statuses.reduce( - ApplicationForm.where(status: exact_statuses), - ) do |accumulator, boolean_status| - accumulator.or( - ApplicationForm.where( - { - boolean_status => true, - :status => BOOLEAN_TO_EXACT_STATUSES.fetch(boolean_status), - }, - ), - ) - end, - ) - end - - private - - BOOLEAN_TO_EXACT_STATUSES = { - "overdue_further_information" => "overdue", - "overdue_professional_standing" => "overdue", - "overdue_qualification" => "overdue", - "overdue_reference" => "overdue", - "received_further_information" => "received", - "received_professional_standing" => "received", - "received_qualification" => "received", - "received_reference" => "received", - "waiting_on_further_information" => "waiting_on", - "waiting_on_professional_standing" => "waiting_on", - "waiting_on_qualification" => "waiting_on", - "waiting_on_reference" => "waiting_on", - }.freeze - - def statuses - Array(params[:statuses]).reject(&:blank?) - end -end diff --git a/app/models/application_form.rb b/app/models/application_form.rb index 2c571f5e23..c3a343df9d 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -147,21 +147,6 @@ class ApplicationForm < ApplicationRecord }, _suffix: true - enum status: { - draft: "draft", - submitted: "submitted", - preliminary_check: "preliminary_check", - assessment_in_progress: "assessment_in_progress", - waiting_on: "waiting_on", - received: "received", - overdue: "overdue", - awarded_pending_checks: "awarded_pending_checks", - awarded: "awarded", - declined: "declined", - potential_duplicate_in_dqt: "potential_duplicate_in_dqt", - withdrawn: "withdrawn", - } - delegate :country, to: :region, allow_nil: true STATUS_COLUMNS = %i[ @@ -184,48 +169,38 @@ class ApplicationForm < ApplicationRecord STATUS_COLUMNS.each { |column| enum column, STATUS_VALUES, prefix: column } - scope :assessable, - -> do - where( - status: %i[ - preliminary_check - submitted - assessment_in_progress - waiting_on - received - overdue - ], - ) - end + scope :assessable, -> { where.not(stage: %i[draft completed]) } scope :active, -> do where(hidden_from_assessment: false).merge( assessable - .or(awarded_pending_checks) - .or(potential_duplicate_in_dqt) - .or(awarded.where("awarded_at >= ?", 90.days.ago)) - .or(declined.where("declined_at >= ?", 90.days.ago)) - .or(withdrawn.where("withdrawn_at >= ?", 90.days.ago)), + .or(where("awarded_at >= ?", 90.days.ago)) + .or(where("declined_at >= ?", 90.days.ago)) + .or(where("withdrawn_at >= ?", 90.days.ago)), ) end scope :destroyable, -> do - draft + where(submitted_at: nil) .where("created_at < ?", 6.months.ago) - .or(awarded.where("awarded_at < ?", 5.years.ago)) - .or(declined.where("declined_at < ?", 5.years.ago)) - .or(withdrawn.where("withdrawn_at < ?", 5.years.ago)) + .or(where("awarded_at < ?", 5.years.ago)) + .or(where("declined_at < ?", 5.years.ago)) + .or(where("withdrawn_at < ?", 5.years.ago)) end scope :remindable, -> do verification_stage.or( - draft_stage.where("created_at < ?", 5.months.ago), + where(submitted_at: nil).where("created_at < ?", 5.months.ago), ) end + def submitted? + submitted_at.present? + end + def to_param reference end @@ -310,7 +285,7 @@ def send_reminder_email(name, number_of_reminders_sent) end def expires_after - draft? ? 6.months : nil + submitted? ? nil : 6.months end def requested_at diff --git a/app/models/further_information_request.rb b/app/models/further_information_request.rb index 9fdfb18b2e..146980a5e9 100644 --- a/app/models/further_information_request.rb +++ b/app/models/further_information_request.rb @@ -67,7 +67,9 @@ def after_received(*) end def after_expired(user:) - DeclineQTS.call(application_form:, user:) unless application_form.withdrawn? + if application_form.withdrawn_at.nil? + DeclineQTS.call(application_form:, user:) + end end def after_reviewed(user:) diff --git a/app/models/professional_standing_request.rb b/app/models/professional_standing_request.rb index 70e1210191..641263ee04 100644 --- a/app/models/professional_standing_request.rb +++ b/app/models/professional_standing_request.rb @@ -46,7 +46,7 @@ def after_received(*) def after_expired(user:) if application_form.teaching_authority_provides_written_statement && - !application_form.withdrawn? + application_form.withdrawn_at.nil? DeclineQTS.call(application_form:, user:) end end @@ -56,7 +56,7 @@ def after_expired(user:) private def should_send_received_email? - !application_form.declined? && + application_form.declined_at.nil? && application_form.teaching_authority_provides_written_statement end end diff --git a/app/models/teacher.rb b/app/models/teacher.rb index b996aaf68a..b8a0162dde 100644 --- a/app/models/teacher.rb +++ b/app/models/teacher.rb @@ -35,7 +35,7 @@ class Teacher < ApplicationRecord def application_form @application_form ||= - application_forms.not_withdrawn.order(created_at: :desc).first + application_forms.where(withdrawn_at: nil).order(created_at: :desc).first end def send_magic_link(*) diff --git a/app/services/award_qts.rb b/app/services/award_qts.rb index 57cb59b18e..95d784a765 100644 --- a/app/services/award_qts.rb +++ b/app/services/award_qts.rb @@ -17,12 +17,9 @@ def initialize( end def call - return if application_form.awarded? + return if application_form.awarded_at.present? - unless application_form.awarded_pending_checks? || - application_form.potential_duplicate_in_dqt? - raise InvalidState - end + raise InvalidState if application_form.dqt_trn_request.nil? raise MissingTRN if trn.blank? diff --git a/app/services/backfill_preliminary_checks.rb b/app/services/backfill_preliminary_checks.rb index ed10eae848..bd12c1315c 100644 --- a/app/services/backfill_preliminary_checks.rb +++ b/app/services/backfill_preliminary_checks.rb @@ -43,12 +43,14 @@ def applications_forms requires_preliminary_check: false, ) .merge( - ApplicationForm.submitted.or( - ApplicationForm.waiting_on.where( - teaching_authority_provides_written_statement: true, - waiting_on_professional_standing: true, + ApplicationForm + .where.not(submitted_at: nil) + .or( + ApplicationForm.pre_assessment_stage.where( + "'waiting_on_lops' = ANY (statuses)", + teaching_authority_provides_written_statement: true, + ), ), - ), ) end end diff --git a/app/services/decline_qts.rb b/app/services/decline_qts.rb index c12a406a63..c204029427 100644 --- a/app/services/decline_qts.rb +++ b/app/services/decline_qts.rb @@ -9,7 +9,7 @@ def initialize(application_form:, user:) end def call - return if application_form.declined? + return if application_form.declined_at.present? ActiveRecord::Base.transaction do application_form.update!(declined_at: Time.zone.now) diff --git a/app/services/rollback_assessment.rb b/app/services/rollback_assessment.rb index d04549e02c..e6092eb764 100644 --- a/app/services/rollback_assessment.rb +++ b/app/services/rollback_assessment.rb @@ -33,12 +33,12 @@ def validate_state def has_submitted_another_application_form? teacher.application_form != application_form && - !teacher.application_form.draft? + teacher.application_form.submitted? end def valid_assessment_state? assessment.award? || assessment.decline? || - (assessment.unknown? && application_form.declined?) + (assessment.unknown? && application_form.declined_at.present?) end def update_assessment @@ -63,9 +63,11 @@ def previously_further_information_requested? delegate :teacher, to: :application_form def update_application_form - if application_form.awarded? + if application_form.awarded_at.present? application_form.update!(awarded_at: nil) - elsif application_form.declined? + end + + if application_form.declined_at.present? application_form.update!(declined_at: nil) end @@ -74,8 +76,7 @@ def update_application_form def delete_draft_application_forms ApplicationForm - .draft - .where(teacher:) + .where(submitted_at: nil, teacher:) .find_each do |application_form| DestroyApplicationForm.call(application_form:) end diff --git a/app/services/withdraw_application_form.rb b/app/services/withdraw_application_form.rb index dbe6c26589..6202a74002 100644 --- a/app/services/withdraw_application_form.rb +++ b/app/services/withdraw_application_form.rb @@ -9,7 +9,7 @@ def initialize(application_form:, user:) end def call - return if application_form.withdrawn? + return if application_form.withdrawn_at.present? ActiveRecord::Base.transaction do application_form.update!(withdrawn_at: Time.zone.now) diff --git a/app/view_objects/assessor_interface/application_forms_show_view_object.rb b/app/view_objects/assessor_interface/application_forms_show_view_object.rb index e5ce74f1c5..afc0cf1239 100644 --- a/app/view_objects/assessor_interface/application_forms_show_view_object.rb +++ b/app/view_objects/assessor_interface/application_forms_show_view_object.rb @@ -10,7 +10,7 @@ def application_form @application_form ||= ApplicationForm .includes(assessment: :sections) - .not_draft + .where.not(submitted_at: nil) .find_by!(reference: params[:reference]) end @@ -29,7 +29,7 @@ def task_list_sections end def status - application_form.status.humanize + application_form.statuses.map(&:humanize).to_sentence end def email_used_as_reference_in_this_application_form? @@ -43,7 +43,7 @@ def other_application_forms_where_email_used_as_reference .includes(:application_form) .where(canonical_contact_email: canonical_email) .where.not(application_form:) - .where.not(application_form: { status: "draft" }) + .where.not(application_form: { submitted_at: nil }) .map(&:application_form) end @@ -75,6 +75,10 @@ def management_tasks ].compact end + def waiting_on_references? + assessment.reference_requests.reject(&:reviewed?).any?(&:requested?) + end + private attr_reader :params, :current_staff diff --git a/app/view_objects/assessor_interface/assessment_section_view_object.rb b/app/view_objects/assessor_interface/assessment_section_view_object.rb index 2ff125f9e7..9ed0c31dc6 100644 --- a/app/view_objects/assessor_interface/assessment_section_view_object.rb +++ b/app/view_objects/assessor_interface/assessment_section_view_object.rb @@ -99,7 +99,7 @@ def work_history_application_forms_contact_email_used_as_teacher ApplicationForm .includes(:teacher) - .not_draft + .where.not(submitted_at: nil) .where( teacher: { canonical_email: work_history_canonical_contact_emails, @@ -123,7 +123,7 @@ def work_history_application_forms_contact_email_used_as_reference canonical_contact_email: work_history_canonical_contact_emails, ) .where.not(application_form:) - .where.not(application_form: { status: "draft" }) + .where.not(application_form: { submitted_at: nil }) .group_by(&:canonical_contact_email) .transform_values do |work_histories| work_histories.map(&:application_form) diff --git a/app/views/assessor_interface/application_forms/status.html.erb b/app/views/assessor_interface/application_forms/status.html.erb index a660ad5cfa..8cd61d9ed1 100644 --- a/app/views/assessor_interface/application_forms/status.html.erb +++ b/app/views/assessor_interface/application_forms/status.html.erb @@ -1,9 +1,9 @@ -<% title = if @view_object.assessment.review? +<% title = if @view_object.application_form.awarded_at.present? + "QTS application #{@view_object.application_form.reference} has been awarded" + elsif @view_object.assessment.review? "Application sent for review" - elsif @view_object.application_form.waiting_on? + elsif @view_object.waiting_on_references? "Reference requests sent successfully" - elsif @view_object.application_form.awarded? - "QTS application #{@view_object.application_form.reference} has been awarded" else "QTS application #{@view_object.application_form.reference} has been #{@view_object.status.downcase}" end %> @@ -11,7 +11,7 @@ <% content_for :page_title, title %> <% content_for :back_link_url, assessor_interface_application_form_path(@view_object.application_form) %> -<% if @view_object.application_form.awarded? %> +<% if @view_object.application_form.awarded_at.present? %> <%= govuk_panel(text: title) %> <% else %>

<%= title %>

@@ -19,12 +19,12 @@ <% if @view_object.assessment.review? %>

An assessor will now review the application and make a decision on awarding or declining QTS.

-<% elsif @view_object.application_form.declined? %> +<% elsif @view_object.application_form.declined_at.present? %>

The application will be deleted after 90 days unless the applicant chooses to appeal.

-<% elsif @view_object.application_form.awarded_pending_checks? %> +<% elsif @view_object.application_form.dqt_trn_request.present? %>

This status will appear while the award is reconciled with the information in the Database of Qualified Teachers (DQT).

Once these checks are complete, the status will change to ‘Awarded’ and the applicant will receive the email telling them they’ve been awarded QTS.

-<% elsif @view_object.application_form.waiting_on? %> +<% elsif @view_object.waiting_on_references? %>

You’ve successfully sent requests to each of the references that the applicant provided.

The applicant will also receive an email to tell them you’ve contacted their references.

When the references respond, you’ll see the status of the application change to ‘Received’.

diff --git a/app/views/teacher_interface/application_forms/show.html.erb b/app/views/teacher_interface/application_forms/show.html.erb index 94898777ee..27502a7d25 100644 --- a/app/views/teacher_interface/application_forms/show.html.erb +++ b/app/views/teacher_interface/application_forms/show.html.erb @@ -2,16 +2,16 @@

Apply for qualified teacher status (QTS)

-<% if @view_object.application_form.draft? %> - <%= render "teacher_interface/application_forms/show/draft", view_object: @view_object %> -<% elsif @view_object.application_form.declined? %> +<% if @view_object.application_form.declined_at.present? %> <%= render "teacher_interface/application_forms/show/declined", view_object: @view_object %> -<% elsif @view_object.application_form.awarded? %> +<% elsif @view_object.application_form.awarded_at.present? %> <%= render "teacher_interface/application_forms/show/awarded", view_object: @view_object %> <% elsif @view_object.request_further_information? %> <%= render "teacher_interface/application_forms/show/further_information_requested", view_object: @view_object %> <% elsif @view_object.request_professional_standing_certificate? %> <%= render "teacher_interface/application_forms/show/request_professional_standing_certificate", view_object: @view_object %> -<% else %> +<% elsif @view_object.application_form.submitted? %> <%= render "teacher_interface/application_forms/show/complete", view_object: @view_object %> +<% else %> + <%= render "teacher_interface/application_forms/show/draft", view_object: @view_object %> <% end %> diff --git a/lib/tasks/example_data.rake b/lib/tasks/example_data.rake index ff1ebc496d..da5fe3ac62 100644 --- a/lib/tasks/example_data.rake +++ b/lib/tasks/example_data.rake @@ -159,11 +159,11 @@ def create_application_forms application_form_traits_for(region).each do |traits| application_form = FactoryBot.create(:application_form, *traits, region:) - next if application_form.draft? + next unless application_form.submitted? assessment = AssessmentFactory.call(application_form:) - if application_form.declined? + if application_form.declined_at.present? FactoryBot.create( :selected_failure_reason, :fi_requestable, @@ -174,7 +174,7 @@ def create_application_forms :declinable, assessment_section: assessment.sections.second, ) - elsif application_form.waiting_on? + elsif application_form.action_required_by_external? if application_form.teaching_authority_provides_written_statement FactoryBot.create( :professional_standing_request, @@ -184,7 +184,6 @@ def create_application_forms application_form.update!( statuses: %w[waiting_on_lops], stage: "pre_assessment", - waiting_on_professional_standing: true, ) elsif application_form.needs_written_statement && rand(4).zero? FactoryBot.create( @@ -195,7 +194,6 @@ def create_application_forms application_form.update!( statuses: %w[waiting_on_lops], stage: "verification", - waiting_on_professional_standing: true, ) elsif (work_history = application_form.work_histories.first) && rand(3).zero? @@ -208,7 +206,6 @@ def create_application_forms application_form.update!( statuses: %w[waiting_on_reference], stage: "verification", - waiting_on_reference: true, ) elsif (qualification = application_form.qualifications.first) && rand(2).zero? @@ -221,7 +218,6 @@ def create_application_forms application_form.update!( statuses: %w[waiting_on_qualification], stage: "verification", - waiting_on_qualification: true, ) else FactoryBot.create( @@ -233,7 +229,6 @@ def create_application_forms application_form.update!( statuses: %w[waiting_on_further_information], stage: "assessment", - waiting_on_further_information: true, ) end end diff --git a/spec/components/timeline_entry_spec.rb b/spec/components/timeline_entry_spec.rb index 0c86fbce86..348df0719f 100644 --- a/spec/components/timeline_entry_spec.rb +++ b/spec/components/timeline_entry_spec.rb @@ -8,12 +8,7 @@ context "with a creator name" do let(:timeline_event) do - create( - :timeline_event, - :status_changed, - creator_name: "DQT", - creator: nil, - ) + create(:timeline_event, :stage_changed, creator_name: "DQT", creator: nil) end it "describes the event" do diff --git a/spec/factories/application_forms.rb b/spec/factories/application_forms.rb index 2f011356db..12147f7237 100644 --- a/spec/factories/application_forms.rb +++ b/spec/factories/application_forms.rb @@ -94,7 +94,6 @@ FactoryBot.define do factory :application_form do sequence(:reference) { |n| n.to_s.rjust(7, "0") } - status { "draft" } association :teacher association :region @@ -180,7 +179,6 @@ trait :submitted do not_started_stage - status { "submitted" } statuses { %w[assessment_not_started] } submitted_at { Time.zone.now } working_days_since_submission { 0 } @@ -201,14 +199,12 @@ submitted pre_assessment_stage requires_preliminary_check { true } - status { "preliminary_check" } statuses { %w[preliminary_check] } end trait :assessment_in_progress do submitted assessment_stage - status { "assessment_in_progress" } statuses { %w[assessment_in_progress] } end @@ -216,7 +212,6 @@ submitted action_required_by_external verification_stage - status { "waiting_on" } statuses do %w[ waiting_on_further_information @@ -230,7 +225,6 @@ trait :received do submitted verification_stage - status { "received" } statuses do %w[ received_further_information @@ -244,7 +238,6 @@ trait :overdue do submitted verification_stage - status { "overdue" } statuses do %w[ overdue_further_information @@ -258,21 +251,18 @@ trait :awarded_pending_checks do submitted review_stage - status { "awarded_pending_checks" } statuses { %w[awarded_pending_checks] } end trait :potential_duplicate_in_dqt do submitted review_stage - status { "potential_duplicate_in_dqt" } statuses { %w[potential_duplicate_in_dqt] } end trait :awarded do submitted completed_stage - status { "awarded" } statuses { %w[awarded] } awarded_at { Time.zone.now } end @@ -280,7 +270,6 @@ trait :declined do submitted completed_stage - status { "declined" } statuses { %w[declined] } declined_at { Time.zone.now } end @@ -288,7 +277,6 @@ trait :withdrawn do submitted completed_stage - status { "withdrawn" } statuses { %w[withdrawn] } withdrawn_at { Time.zone.now } end diff --git a/spec/jobs/update_dqt_trn_request_job_spec.rb b/spec/jobs/update_dqt_trn_request_job_spec.rb index 9041c7be05..88fc5022d8 100644 --- a/spec/jobs/update_dqt_trn_request_job_spec.rb +++ b/spec/jobs/update_dqt_trn_request_job_spec.rb @@ -80,10 +80,10 @@ perform_rescue_exception end - it "doesn't change the state" do + it "doesn't change the stage" do expect { perform_rescue_exception }.to_not change( application_form, - :status, + :stage, ) end @@ -116,8 +116,8 @@ end it "changes the state" do - expect { perform }.to change(application_form, :status).to( - "potential_duplicate_in_dqt", + expect { perform }.to change(application_form, :statuses).to( + %w[potential_duplicate_in_dqt], ) end @@ -193,10 +193,10 @@ perform_rescue_exception end - it "doesn't change the state" do + it "doesn't change the stage" do expect { perform_rescue_exception }.to_not change( application_form, - :status, + :stage, ) end @@ -232,8 +232,8 @@ end it "changes the state" do - expect { perform }.to change(application_form, :status).to( - "potential_duplicate_in_dqt", + expect { perform }.to change(application_form, :statuses).to( + %w[potential_duplicate_in_dqt], ) end @@ -265,8 +265,8 @@ perform end - it "doesn't change the state" do - expect { perform }.to_not change(application_form, :status) + it "doesn't change the stage" do + expect { perform }.to_not change(application_form, :stage) end it "doesn't queue another job" do diff --git a/spec/lib/application_form_status_updater_spec.rb b/spec/lib/application_form_status_updater_spec.rb index 4c24893330..4cb59fd71f 100644 --- a/spec/lib/application_form_status_updater_spec.rb +++ b/spec/lib/application_form_status_updater_spec.rb @@ -361,10 +361,6 @@ end context "when status is unchanged" do - it "doesn't change the status from draft" do - expect { call }.to_not change(application_form, :status).from("draft") - end - include_examples "doesn't change action required by" it "doesn't change the stage from draft" do diff --git a/spec/lib/filters/status_spec.rb b/spec/lib/filters/status_spec.rb deleted file mode 100644 index ef4fd80820..0000000000 --- a/spec/lib/filters/status_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe Filters::Status do - subject { described_class.apply(scope:, params:) } - - context "with states param and a single state" do - let(:params) { { statuses: :draft } } - let(:scope) { ApplicationForm.all } - - let!(:included) { create(:application_form, :draft) } - - let!(:filtered) { create(:application_form, :submitted) } - - it "returns a filtered scope" do - expect(subject).to contain_exactly(included) - end - end - - context "wth states param and multiple states" do - let(:params) do - { statuses: %w[draft submitted waiting_on_further_information] } - end - let(:scope) { ApplicationForm.all } - - before do - create(:application_form, :awarded) - create(:application_form, :declined) - create(:application_form, :declined, waiting_on_further_information: true) - end - - let!(:included) do - [ - create(:application_form, :draft), - create(:application_form, :submitted), - create(:application_form, waiting_on_further_information: true), - ] - end - - it "returns a filtered scope" do - expect(subject).to match_array(included) - end - end - - context "with states param and a blank string" do - let(:params) { { statuses: [""] } } - let(:scope) { double } - - it "returns the original scope" do - expect(subject).to eq(scope) - end - end - - context "without states param" do - let(:params) { {} } - let(:scope) { double } - - it "returns the original scope" do - expect(subject).to eq(scope) - end - end -end diff --git a/spec/models/application_form_spec.rb b/spec/models/application_form_spec.rb index 76de498cf6..0f9f417840 100644 --- a/spec/models/application_form_spec.rb +++ b/spec/models/application_form_spec.rb @@ -130,21 +130,6 @@ ) .with_suffix .backed_by_column_of_type(:string) - - is_expected.to define_enum_for(:status).with_values( - draft: "draft", - submitted: "submitted", - preliminary_check: "preliminary_check", - assessment_in_progress: "assessment_in_progress", - waiting_on: "waiting_on", - received: "received", - overdue: "overdue", - awarded: "awarded", - awarded_pending_checks: "awarded_pending_checks", - declined: "declined", - potential_duplicate_in_dqt: "potential_duplicate_in_dqt", - withdrawn: "withdrawn", - ).backed_by_column_of_type(:string) end it do diff --git a/spec/services/award_qts_spec.rb b/spec/services/award_qts_spec.rb index d57a685c0d..ccbdebddb1 100644 --- a/spec/services/award_qts_spec.rb +++ b/spec/services/award_qts_spec.rb @@ -30,6 +30,8 @@ create(:application_form, :awarded_pending_checks, teacher:) end + before { create(:dqt_trn_request, application_form:) } + it "sets the TRN" do expect { call }.to change(teacher, :trn).to("abcdef") end @@ -49,7 +51,7 @@ end it "changes the status" do - expect { call }.to change(application_form, :status).to("awarded") + expect { call }.to change(application_form, :stage).to("completed") end it "sets the awarded at date" do @@ -74,6 +76,8 @@ create(:application_form, :potential_duplicate_in_dqt, teacher:) end + before { create(:dqt_trn_request, application_form:) } + it "sets the TRN" do expect { call }.to change(teacher, :trn).to("abcdef") end @@ -93,7 +97,7 @@ end it "changes the status" do - expect { call }.to change(application_form, :status).to("awarded") + expect { call }.to change(application_form, :stage).to("completed") end it "sets the awarded at date" do @@ -116,6 +120,8 @@ context "with an awarded application form" do let(:application_form) { create(:application_form, :awarded, teacher:) } + before { create(:dqt_trn_request, application_form:) } + it "doesn't change the TRN" do expect { call }.to_not change(teacher, :trn) end @@ -134,8 +140,8 @@ ) end - it "doesn't change the status" do - expect { call }.to_not change(application_form, :status) + it "doesn't change the stage" do + expect { call }.to_not change(application_form, :stage) end it "doesn't change the awarded at date" do diff --git a/spec/services/backfill_preliminary_checks_spec.rb b/spec/services/backfill_preliminary_checks_spec.rb index 61fd22478e..4c32083abc 100644 --- a/spec/services/backfill_preliminary_checks_spec.rb +++ b/spec/services/backfill_preliminary_checks_spec.rb @@ -29,7 +29,7 @@ :waiting_on, :with_assessment, region:, - waiting_on_professional_standing: true, + statuses: %w[waiting_on_lops], teaching_authority_provides_written_statement: true, requires_preliminary_check: false, ) @@ -46,25 +46,25 @@ it "doesn't backfill the submitted application form" do expect { call }.to_not( - change { submitted_application_form.reload.status }, + change { submitted_application_form.reload.stage }, ) end it "doesn't backfill the waiting on application form" do expect { call }.to_not( - change { waiting_on_application_form.reload.status }, + change { waiting_on_application_form.reload.stage }, ) end it "doesn't backfill the preliminary checked application form" do expect { call }.to_not( - change { preliminary_check_application_form.reload.status }, + change { preliminary_check_application_form.reload.stage }, ) end it "doesn't backfill the awarded application form" do expect { call }.to_not( - change { awarded_check_application_form.reload.status }, + change { awarded_check_application_form.reload.stage }, ) end end @@ -77,7 +77,8 @@ submitted_application_form.reload - expect(submitted_application_form.status).to eq("preliminary_check") + expect(submitted_application_form.stage).to eq("pre_assessment") + expect(submitted_application_form.statuses).to eq(%w[preliminary_check]) expect(submitted_application_form.requires_preliminary_check).to be true expect( submitted_application_form.assessment.sections.preliminary, @@ -89,7 +90,10 @@ waiting_on_application_form.reload - expect(waiting_on_application_form.status).to eq("preliminary_check") + expect(waiting_on_application_form.stage).to eq("pre_assessment") + expect(waiting_on_application_form.statuses).to eq( + %w[preliminary_check], + ) expect( waiting_on_application_form.requires_preliminary_check, ).to be true @@ -100,13 +104,13 @@ it "doesn't backfill the preliminary checked application form" do expect { call }.to_not( - change { preliminary_check_application_form.reload.status }, + change { preliminary_check_application_form.reload.stage }, ) end it "doesn't backfill the awarded application form" do expect { call }.to_not( - change { awarded_check_application_form.reload.status }, + change { awarded_check_application_form.reload.stage }, ) end end diff --git a/spec/services/create_dqt_trn_request_spec.rb b/spec/services/create_dqt_trn_request_spec.rb index 956074614f..616525eb9b 100644 --- a/spec/services/create_dqt_trn_request_spec.rb +++ b/spec/services/create_dqt_trn_request_spec.rb @@ -13,8 +13,8 @@ end it "changes the status" do - expect { call }.to change(application_form, :status).to( - "awarded_pending_checks", + expect { call }.to change(application_form, :statuses).to( + %w[awarded_pending_checks], ) end diff --git a/spec/services/create_further_information_request_spec.rb b/spec/services/create_further_information_request_spec.rb index 3a15e97ec4..9aed43e1e7 100644 --- a/spec/services/create_further_information_request_spec.rb +++ b/spec/services/create_further_information_request_spec.rb @@ -27,16 +27,10 @@ end end - describe "updating application form state" do - subject(:status) { application_form.status } - - it { is_expected.to eq("submitted") } - - context "after calling the service" do - before { call } - - it { is_expected.to eq("waiting_on") } - end + it "changes the application form statuses" do + expect { call }.to change(application_form, :statuses).to( + %w[waiting_on_further_information], + ) end describe "sending application received email" do diff --git a/spec/services/decline_qts_spec.rb b/spec/services/decline_qts_spec.rb index 2bc3d07cf8..dc9efae5e5 100644 --- a/spec/services/decline_qts_spec.rb +++ b/spec/services/decline_qts_spec.rb @@ -18,8 +18,12 @@ ).with(params: { teacher: }, args: []) end - it "changes the status" do - expect { call }.to change(application_form, :status).to("declined") + it "changes the stage" do + expect { call }.to change(application_form, :stage).to("completed") + end + + it "changes the statuses" do + expect { call }.to change(application_form, :statuses).to(%w[declined]) end it "sets the declined at date" do @@ -41,8 +45,8 @@ ) end - it "doesn't change the status" do - expect { call }.to_not change(application_form, :status) + it "doesn't change the stage" do + expect { call }.to_not change(application_form, :stage) end it "doesn't change the declined at date" do diff --git a/spec/services/expire_requestable_spec.rb b/spec/services/expire_requestable_spec.rb index 1ed05ca6bd..b6676e5d23 100644 --- a/spec/services/expire_requestable_spec.rb +++ b/spec/services/expire_requestable_spec.rb @@ -36,7 +36,7 @@ shared_examples_for "declining the application" do it "declines the application" do - expect(subject.application_form).to be_declined + expect(subject.application_form.declined_at).to_not be_nil end end diff --git a/spec/services/receive_requestable_spec.rb b/spec/services/receive_requestable_spec.rb index 72f41a760b..5f473292df 100644 --- a/spec/services/receive_requestable_spec.rb +++ b/spec/services/receive_requestable_spec.rb @@ -29,15 +29,9 @@ end it "changes the application form status" do - expect { call }.to change { application_form.reload.received? }.from( - false, - ).to(true) - end - - it "changes the application form qualification received" do - expect { call }.to change { - application_form.reload.received_qualification - }.from(false).to(true) + expect { call }.to change { application_form.reload.statuses }.to( + %w[received_qualification], + ) end it "changes the requestable received at" do diff --git a/spec/services/update_assessment_section_spec.rb b/spec/services/update_assessment_section_spec.rb index 63c890bd1e..7cbc323415 100644 --- a/spec/services/update_assessment_section_spec.rb +++ b/spec/services/update_assessment_section_spec.rb @@ -109,9 +109,9 @@ end it "changes the application form state" do - expect { subject }.to change { application_form.status }.from( - "submitted", - ).to("assessment_in_progress") + expect { subject }.to change { application_form.statuses }.from( + %w[assessment_not_started], + ).to(%w[assessment_in_progress]) end it "changes the assessment started at" do @@ -142,8 +142,12 @@ expect { subject }.to_not change(application_form, :assessor) end - it "doesn't change the application form state" do - expect { subject }.to_not change(application_form, :status) + it "doesn't change the application form stage" do + expect { subject }.to_not change(application_form, :stage) + end + + it "doesn't change the application form statuses" do + expect { subject }.to_not change(application_form, :statuses) end it "doesn't change the assessment started at" do diff --git a/spec/services/verify_assessment_spec.rb b/spec/services/verify_assessment_spec.rb index 3ac03dc8ca..68ab2f311b 100644 --- a/spec/services/verify_assessment_spec.rb +++ b/spec/services/verify_assessment_spec.rb @@ -101,16 +101,8 @@ end end - describe "updating application form state" do - subject(:status) { application_form.status } - - it { is_expected.to eq("submitted") } - - context "after calling the service" do - before { call } - - it { is_expected.to eq("waiting_on") } - end + it "changes the application form stage" do + expect { call }.to change(application_form, :stage).to("verification") end describe "sending referee email" do diff --git a/spec/services/withdraw_application_form_spec.rb b/spec/services/withdraw_application_form_spec.rb index 32ead4a527..29158fa010 100644 --- a/spec/services/withdraw_application_form_spec.rb +++ b/spec/services/withdraw_application_form_spec.rb @@ -8,18 +8,6 @@ subject(:call) { described_class.call(application_form:, user:) } - describe "application form status" do - subject(:withdrawn?) { application_form.withdrawn? } - - it { is_expected.to be false } - - context "when calling the service" do - before { call } - - it { is_expected.to be true } - end - end - describe "application form withdrawn_at" do subject(:withdrawn_at) { application_form.withdrawn_at } diff --git a/spec/support/shared_examples.rb b/spec/support/shared_examples.rb index ce9a97c9cc..107656de4d 100644 --- a/spec/support/shared_examples.rb +++ b/spec/support/shared_examples.rb @@ -2,9 +2,7 @@ RSpec.shared_examples "redirect unless application form is draft" do context "with a submitted application form" do - before do - application_form.update!(status: "submitted", submitted_at: Time.zone.now) - end + before { application_form.update!(submitted_at: Time.zone.now) } it "redirects to the application form" do perform diff --git a/spec/system/assessor_interface/verifying_professional_standing_spec.rb b/spec/system/assessor_interface/verifying_professional_standing_spec.rb index 2607fa5799..7f26cc6c24 100644 --- a/spec/system/assessor_interface/verifying_professional_standing_spec.rb +++ b/spec/system/assessor_interface/verifying_professional_standing_spec.rb @@ -141,7 +141,8 @@ def and_i_submit_an_internal_note def application_form @application_form ||= begin - application_form = create(:application_form, :submitted) + application_form = + create(:application_form, :waiting_on, statuses: %w[waiting_on_lops]) create( :assessment, :with_professional_standing_request, diff --git a/spec/system/assessor_interface/verifying_qualifications_spec.rb b/spec/system/assessor_interface/verifying_qualifications_spec.rb index e894c628b5..0f50cd7304 100644 --- a/spec/system/assessor_interface/verifying_qualifications_spec.rb +++ b/spec/system/assessor_interface/verifying_qualifications_spec.rb @@ -154,7 +154,11 @@ def application_form @application_form ||= begin application_form = - create(:application_form, :waiting_on, waiting_on_qualification: true) + create( + :application_form, + :waiting_on, + statuses: %w[waiting_on_qualification], + ) qualification = create(:qualification, :completed, application_form:) assessment = create(:assessment, :started, application_form:) create(:qualification_request, :requested, assessment:, qualification:) diff --git a/spec/system/assessor_interface/verifying_references_spec.rb b/spec/system/assessor_interface/verifying_references_spec.rb index aa4efb55aa..00cc276465 100644 --- a/spec/system/assessor_interface/verifying_references_spec.rb +++ b/spec/system/assessor_interface/verifying_references_spec.rb @@ -138,8 +138,7 @@ def application_form create( :application_form, :waiting_on, - waiting_on_reference: true, - received_reference: true, + statuses: %w[waiting_on_reference received_reference], ) work_history = create( diff --git a/spec/view_objects/assessor_interface/application_forms_index_view_object_spec.rb b/spec/view_objects/assessor_interface/application_forms_index_view_object_spec.rb index 9b1ae9a01f..0933c483ea 100644 --- a/spec/view_objects/assessor_interface/application_forms_index_view_object_spec.rb +++ b/spec/view_objects/assessor_interface/application_forms_index_view_object_spec.rb @@ -183,7 +183,7 @@ create_list(:application_form, 3, :submitted, :assessment_stage) create_list(:application_form, 4, :submitted, :verification_stage) create_list(:application_form, 5, :submitted, :review_stage) - create_list(:application_form, 6, :submitted, :completed_stage) + create_list(:application_form, 6, :awarded, :completed_stage) end it do From 597a0a3750e74eb866cf6d6e33bb5cd090c99496 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Tue, 21 Nov 2023 09:47:58 +0000 Subject: [PATCH 4/4] Revert "Add application_forms:hidden_from_assessment task" This reverts commit 2056f5a7aaca21a21e431d1b6c014a8d187dd0fa. --- lib/tasks/application_forms.rake | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/lib/tasks/application_forms.rake b/lib/tasks/application_forms.rake index bc05d4b29c..26448c1aab 100644 --- a/lib/tasks/application_forms.rake +++ b/lib/tasks/application_forms.rake @@ -34,36 +34,4 @@ namespace :application_forms do puts "#{application_form.reference}: #{application_form.action_required_by} - #{application_form.status}" end end - - desc "Update hidden from assessment status for all application forms." - task update_hidden_from_assessment: :environment do |_task, _args| - zimbabwe_applications = - ApplicationForm.joins(region: :country).where(countries: { code: "ZW" }) - - puts "Zimbabwe: #{zimbabwe_applications.count}" - zimbabwe_applications.pluck(:reference).each { |reference| puts reference } - puts - - work_history_duration_applications = - ApplicationForm - .where(stage: %w[not_started pre_assessment], needs_work_history: true) - .select(&:created_under_new_regulations?) - .select do |application_form| - WorkHistoryDuration.for_application_form( - application_form, - consider_teaching_qualification: true, - ).count_months < 9 - end - - puts "Work history duration: #{work_history_duration_applications.count}" - work_history_duration_applications - .map(&:reference) - .each { |reference| puts reference } - - ApplicationForm.where( - id: - zimbabwe_applications.pluck(:id) + - work_history_duration_applications.map(&:id), - ).update_all(hidden_from_assessment: true) - end end