diff --git a/app/controllers/assessor_interface/assessment_sections_controller.rb b/app/controllers/assessor_interface/assessment_sections_controller.rb index 6302cb9d1e..8e17e60d48 100644 --- a/app/controllers/assessor_interface/assessment_sections_controller.rb +++ b/app/controllers/assessor_interface/assessment_sections_controller.rb @@ -31,7 +31,7 @@ def update if @form.save if assessment_section.preliminary? if assessment.all_preliminary_sections_passed? - notify_teacher + request_professional_standing unassign_assessor else redirect_to [ @@ -93,16 +93,13 @@ def form_params ) end - def notify_teacher - unless application_form.teaching_authority_provides_written_statement - return - end + def request_professional_standing + requestable = assessment.professional_standing_request + return if requestable.nil? || requestable.requested? - DeliverEmail.call( - application_form:, - mailer: TeacherMailer, - action: :initial_checks_passed, - ) + RequestRequestable.call(requestable:, user: current_staff) + + ApplicationFormStatusUpdater.call(application_form:, user: current_staff) end def unassign_assessor diff --git a/app/models/professional_standing_request.rb b/app/models/professional_standing_request.rb index fc1f5a208a..df721b38e4 100644 --- a/app/models/professional_standing_request.rb +++ b/app/models/professional_standing_request.rb @@ -38,8 +38,18 @@ def expires_after end end + def after_requested(*) + if should_send_emails? + DeliverEmail.call( + application_form:, + mailer: TeacherMailer, + action: :initial_checks_passed, + ) + end + end + def after_received(*) - if should_send_received_email? + if should_send_emails? DeliverEmail.call( application_form:, mailer: TeacherMailer, @@ -59,7 +69,7 @@ def after_expired(user:) private - def should_send_received_email? + def should_send_emails? application_form.declined_at.nil? && application_form.teaching_authority_provides_written_statement end diff --git a/app/services/submit_application_form.rb b/app/services/submit_application_form.rb index 704c5f035f..f596748a72 100644 --- a/app/services/submit_application_form.rb +++ b/app/services/submit_application_form.rb @@ -13,7 +13,7 @@ def call ActiveRecord::Base.transaction do application_form.update!( - requires_preliminary_check: region.requires_preliminary_check, + requires_preliminary_check:, subjects: application_form.subjects.compact_blank, submitted_at: Time.zone.now, working_days_since_submission: 0, @@ -21,7 +21,7 @@ def call assessment = AssessmentFactory.call(application_form:) - if application_form.reduced_evidence_accepted + if reduced_evidence_accepted UpdateAssessmentInductionRequired.call(assessment:) end @@ -38,16 +38,7 @@ def call action: :application_received, ) - if !application_form.requires_preliminary_check && - application_form.teaching_authority_provides_written_statement - DeliverEmail.call( - application_form:, - mailer: TeacherMailer, - action: :initial_checks_passed, - ) - end - - if region.teaching_authority_requires_submission_email + if teaching_authority_requires_submission_email DeliverEmail.call( application_form:, mailer: TeachingAuthorityMailer, @@ -55,23 +46,35 @@ def call ) end - FindApplicantInDQTJob.perform_later(application_form) - - # Sometimes DQT doesn't find a result the first time - FindApplicantInDQTJob.set(wait: 5.minutes).perform_later(application_form) + perform_duplicate_jobs end private attr_reader :application_form, :user - delegate :region, to: :application_form + delegate :reduced_evidence_accepted, + :region, + :requires_preliminary_check, + :teaching_authority_provides_written_statement, + to: :application_form + + delegate :teaching_authority_requires_submission_email, to: :region def create_professional_standing_request(assessment) - return unless application_form.teaching_authority_provides_written_statement + return unless teaching_authority_provides_written_statement + + requestable = ProfessionalStandingRequest.create!(assessment:) + + unless requires_preliminary_check + RequestRequestable.call(requestable:, user:) + end + end - ProfessionalStandingRequest - .create!(assessment:) - .tap { |requestable| RequestRequestable.call(requestable:, user:) } + def perform_duplicate_jobs + FindApplicantInDQTJob.perform_later(application_form) + + # Sometimes DQT doesn't find a result the first time + FindApplicantInDQTJob.set(wait: 5.minutes).perform_later(application_form) end end 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 fe30190cca..0c09fa21d7 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 @@ -119,15 +119,24 @@ def await_professional_standing_task_list_item I18n.t( "assessor_interface.application_forms.show.assessment_tasks.items.await_professional_standing_request", ), - link: [ - :locate, - :assessor_interface, - application_form, - assessment, - :professional_standing_request, - ], + link: + if professional_standing_request.requested? + [ + :locate, + :assessor_interface, + application_form, + assessment, + :professional_standing_request, + ] + end, status: - professional_standing_request.received? ? :completed : :waiting_on, + if professional_standing_request.received? + :completed + elsif professional_standing_request.requested? + :waiting_on + else + :cannot_start + end, } end diff --git a/spec/factories/assessments.rb b/spec/factories/assessments.rb index 62e9a3ce9f..141fc41287 100644 --- a/spec/factories/assessments.rb +++ b/spec/factories/assessments.rb @@ -84,12 +84,7 @@ trait :with_further_information_request do after(:create) do |assessment, _evaluator| - create( - :further_information_request, - :requested, - :with_items, - assessment:, - ) + create(:requested_further_information_request, :with_items, assessment:) end end @@ -99,12 +94,6 @@ end end - trait :with_requested_professional_standing_request do - after(:create) do |assessment, _evaluator| - create(:requested_professional_standing_request, assessment:) - end - end - trait :with_reference_requests do after(:create) do |assessment, _evaluator| assessment.application_form.work_histories.each do |work_history| diff --git a/spec/system/assessor_interface/pre_assessment_tasks_spec.rb b/spec/system/assessor_interface/pre_assessment_tasks_spec.rb index af48087f1b..8fd84d9ce4 100644 --- a/spec/system/assessor_interface/pre_assessment_tasks_spec.rb +++ b/spec/system/assessor_interface/pre_assessment_tasks_spec.rb @@ -8,10 +8,10 @@ given_there_is_an_application_form_with_professional_standing_request end - it "passes preliminary check" do + it "passes preliminary check and locate professional standing" do when_i_visit_the(:assessor_application_page, reference:) then_i_see_the(:assessor_application_page, reference:) - and_i_see_a_waiting_on_status + and_i_see_a_preliminary_check_status and_i_see_an_unstarted_preliminary_check_task when_i_click_on_the_preliminary_check_task @@ -20,12 +20,26 @@ and_i_see_a_completed_preliminary_check_task and_the_teacher_receives_a_checks_passed_email and_the_assessor_is_unassigned + + when_i_visit_the(:assessor_application_page, reference:) + then_i_see_the(:assessor_application_page, reference:) + and_i_see_a_waiting_on_status + and_i_click_awaiting_professional_standing + then_i_see_the( + :assessor_locate_professional_standing_request_page, + reference:, + ) + + when_i_fill_in_the_locate_form + then_i_see_the(:assessor_application_page, reference:) + and_i_see_a_assessment_not_started_status + and_the_teacher_receives_a_professional_standing_received_email end it "fails preliminary check" do when_i_visit_the(:assessor_application_page, reference:) then_i_see_the(:assessor_application_page, reference:) - and_i_see_a_waiting_on_status + and_i_see_a_preliminary_check_status and_i_see_an_unstarted_preliminary_check_task when_i_click_on_the_preliminary_check_task @@ -41,22 +55,6 @@ and_i_see_the_failure_reasons end - it "locate professional standing" do - when_i_visit_the(:assessor_application_page, reference:) - then_i_see_the(:assessor_application_page, reference:) - and_i_see_a_waiting_on_status - and_i_click_awaiting_professional_standing - then_i_see_the( - :assessor_locate_professional_standing_request_page, - reference:, - ) - - when_i_fill_in_the_locate_form - then_i_see_the(:assessor_application_page, reference:) - and_i_see_a_preliminary_check_status - and_the_teacher_receives_a_professional_standing_received_email - end - private def given_there_is_an_application_form_with_professional_standing_request @@ -64,11 +62,23 @@ def given_there_is_an_application_form_with_professional_standing_request end def and_i_see_a_waiting_on_status + expect(assessor_application_page.status_summary.value).to have_text( + "WAITING ON LOPS", + ) + end + + def and_i_see_a_preliminary_check_status expect(assessor_application_page.status_summary.value).to have_text( "PRELIMINARY CHECK", ) end + def and_i_see_a_assessment_not_started_status + expect(assessor_application_page.status_summary.value).to have_text( + "ASSESSMENT NOT STARTED", + ) + end + def and_i_see_an_unstarted_preliminary_check_task expect(assessor_application_page.task_list).to have_content( "Preliminary check (qualifications)", @@ -78,7 +88,7 @@ def and_i_see_an_unstarted_preliminary_check_task ) expect( assessor_application_page.awaiting_professional_standing_task, - ).to have_content("WAITING ON") + ).to have_content("CANNOT START") end def when_i_click_on_the_preliminary_check_task @@ -155,15 +165,9 @@ def when_i_fill_in_the_locate_form form.submit_button.click end - def and_i_see_a_preliminary_check_status - expect(assessor_application_page.status_summary.value).to have_text( - "PRELIMINARY CHECK", - ) - end - def and_the_teacher_receives_a_professional_standing_received_email - expect(TeacherMailer.deliveries.count).to eq(1) - expect(TeacherMailer.deliveries.first.subject).to eq( + expect(TeacherMailer.deliveries.count).to eq(2) + expect(TeacherMailer.deliveries.second.subject).to eq( I18n.t( "mailer.teacher.professional_standing_received.subject", certificate: "Letter of Professional Standing", @@ -185,7 +189,7 @@ def application_form create( :assessment, :with_preliminary_qualifications_section, - :with_requested_professional_standing_request, + :with_professional_standing_request, application_form:, ) application_form.region.update!( diff --git a/spec/view_objects/assessor_interface/application_forms_show_view_object_spec.rb b/spec/view_objects/assessor_interface/application_forms_show_view_object_spec.rb index 7f0d8c7f54..3341001d5d 100644 --- a/spec/view_objects/assessor_interface/application_forms_show_view_object_spec.rb +++ b/spec/view_objects/assessor_interface/application_forms_show_view_object_spec.rb @@ -102,6 +102,7 @@ let!(:professional_standing_request) do create(:professional_standing_request, assessment:) end + before do application_form.update!( teaching_authority_provides_written_statement: true, @@ -112,10 +113,22 @@ is_expected.to include_task_list_item( "Pre-assessment tasks", "Awaiting third-party professional standing", - status: :waiting_on, + status: :cannot_start, ) end + context "and professional standing request is requested" do + before { professional_standing_request.requested! } + + it do + is_expected.to include_task_list_item( + "Pre-assessment tasks", + "Awaiting third-party professional standing", + status: :waiting_on, + ) + end + end + context "and professional standing request received" do before do professional_standing_request.update!(