Skip to content

Commit

Permalink
Merge pull request #2089 from DFE-Digital/lops-requested-at
Browse files Browse the repository at this point in the history
Request LoPS after preliminary checks
  • Loading branch information
thomasleese authored Apr 24, 2024
2 parents 122d637 + 23f7075 commit a7fa416
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions app/models/professional_standing_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
45 changes: 24 additions & 21 deletions app/services/submit_application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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,
)

assessment = AssessmentFactory.call(application_form:)

if application_form.reduced_evidence_accepted
if reduced_evidence_accepted
UpdateAssessmentInductionRequired.call(assessment:)
end

Expand All @@ -38,40 +38,43 @@ 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,
action: :application_submitted,
)
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 1 addition & 12 deletions spec/factories/assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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|
Expand Down
62 changes: 33 additions & 29 deletions spec/system/assessor_interface/pre_assessment_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -41,34 +55,30 @@
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
application_form
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)",
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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!(
Expand Down

0 comments on commit a7fa416

Please sign in to comment.