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 74bea113d3..e80b1a700c 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -146,21 +146,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[ @@ -183,19 +168,7 @@ 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 @@ -203,30 +176,32 @@ class ApplicationForm < ApplicationRecord .where.not(countries: { code: "ZW" }) .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 @@ -311,7 +286,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 3900fd9009..952e851dc5 100644 --- a/spec/factories/application_forms.rb +++ b/spec/factories/application_forms.rb @@ -93,7 +93,6 @@ FactoryBot.define do factory :application_form do sequence(:reference) { |n| n.to_s.rjust(7, "0") } - status { "draft" } association :teacher association :region @@ -179,7 +178,6 @@ trait :submitted do not_started_stage - status { "submitted" } statuses { %w[assessment_not_started] } submitted_at { Time.zone.now } working_days_since_submission { 0 } @@ -200,14 +198,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 @@ -215,7 +211,6 @@ submitted action_required_by_external verification_stage - status { "waiting_on" } statuses do %w[ waiting_on_further_information @@ -229,7 +224,6 @@ trait :received do submitted verification_stage - status { "received" } statuses do %w[ received_further_information @@ -243,7 +237,6 @@ trait :overdue do submitted verification_stage - status { "overdue" } statuses do %w[ overdue_further_information @@ -257,21 +250,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 @@ -279,7 +269,6 @@ trait :declined do submitted completed_stage - status { "declined" } statuses { %w[declined] } declined_at { Time.zone.now } end @@ -287,7 +276,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 4a7d6e3e8a..f8fed5e5a1 100644 --- a/spec/models/application_form_spec.rb +++ b/spec/models/application_form_spec.rb @@ -129,21 +129,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