Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show multiple DQT matches #1713

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/jobs/find_applicant_in_dqt_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class FindApplicantInDQTJob < ApplicationJob
def perform(application_form_id:)
application_form = ApplicationForm.find(application_form_id)
teachers = FindTeachersInDQT.call(application_form:, reverse_name: true)

application_form.update!(dqt_match: teachers.first) if teachers.any?
application_form.update!(dqt_match: { teachers: })
end
end
1 change: 1 addition & 0 deletions app/lib/dqt/client/find_teachers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class DQT::Client::FindTeachers
include DQT::Client::Connection

attr_reader :application_form, :reverse_name

def initialize(application_form:, reverse_name: false)
@application_form = application_form
@reverse_name = reverse_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def application_form
.find(params[:id])
end

def duplicate_matches
dqt_match.fetch("teachers", dqt_match.present? ? [dqt_match] : [])
end

def task_list_sections
[
pre_assessment_task_list_section,
Expand Down Expand Up @@ -75,6 +79,7 @@ def management_tasks
attr_reader :params, :current_staff

delegate :assessment,
:dqt_match,
:teacher,
:teaching_authority_provides_written_statement,
:work_histories,
Expand Down
15 changes: 9 additions & 6 deletions app/views/assessor_interface/application_forms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
<% content_for :back_link_url, assessor_interface_application_forms_path %>

<% application_form = @view_object.application_form %>
<% assessment = @view_object.assessment %>

<%= render "linked_application_forms",
teacher: application_form.teacher,
email_used_as_reference_in_this_application_form: @view_object.email_used_as_reference_in_this_application_form?,
other_application_forms_where_email_used_as_reference: @view_object.other_application_forms_where_email_used_as_reference %>

<% if @view_object.application_form.dqt_match.present? %>
<% if (duplicate_matches = @view_object.duplicate_matches).present? %>
<%= govuk_notification_banner(title_text: "Important") do |notification_banner| %>
<% notification_banner.with_heading(text: "The application details match a record in DQT") %>
<% notification_banner.with_heading(text: "Application details match DQT record(s)") %>

<p class="govuk-body govuk-!-margin-bottom-1">
DQT contains a matching record for the name and date of birth of this applicant. <strong class="govuk-!-font-weight-bold">Teacher Reference Number: <%= @view_object.application_form.dqt_match["trn"] %></strong>.
</p>
<p class="govuk-body">The surname and date of birth used in this application matches the following records found in the Database of Qualified Teachers (DQT):</p>

<ul class="govuk-list govuk-list--bullet">
<% duplicate_matches.each do |match| %>
<li><%= match["first_name"] %> <%= match["last_name"] %>, TRN <%= match["trn"] %></li>
<% end %>
</ul>
<% end %>
<% end %>

Expand Down
38 changes: 18 additions & 20 deletions spec/jobs/find_applicant_in_dqt_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,30 @@

perform

expect(application_form.reload.dqt_match).to eq({})
expect(application_form.reload.dqt_match).to eq({ "teachers" => [] })
end

it "updates the application form with the TRN" do
result = {
date_of_birth: application_form.date_of_birth.iso8601.to_s,
first_name: "Jane",
last_name: "Smith",
trn: "1234567",
}

allow(FindTeachersInDQT).to receive(:call).and_return(
[
result,
{
date_of_birth: "1980-01-01",
first_name: "Janet",
last_name: "Jones",
trn: "7654321",
},
],
)
results = [
{
"date_of_birth" => application_form.date_of_birth.iso8601.to_s,
"first_name" => "Jane",
"last_name" => "Smith",
"trn" => "1234567",
},
{
"date_of_birth" => "1980-01-01",
"first_name" => "Janet",
"last_name" => "Jones",
"trn" => "7654321",
},
]

allow(FindTeachersInDQT).to receive(:call).and_return(results)

perform

expect(application_form.reload.dqt_match).to eq(result.as_json)
expect(application_form.reload.dqt_match).to eq({ "teachers" => results })
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ def then_i_see_the_application

def and_i_see_the_warning_of_an_existing_record_in_dqt
expect(assessor_application_page).to have_content(
"The application details match a record in DQT",
)
expect(assessor_application_page).to have_content(
"Teacher Reference Number: 7654322",
"Application details match DQT record(s)",
)
expect(assessor_application_page).to have_content("John Smith, TRN 7654322")
end

def and_the_applicant_matches_a_record_in_dqt
Expand Down Expand Up @@ -69,9 +67,9 @@ def application_id

def dqt_match
{
"firstName" => application_form.given_names,
"lastName" => application_form.family_name,
"dateOfBirth" => application_form.date_of_birth.iso8601.to_s,
"first_name" => "John",
"last_name" => "Smith",
"date_of_birth" => application_form.date_of_birth.iso8601.to_s,
"trn" => "7654322",
}
end
Expand Down
Loading