Skip to content

Commit

Permalink
Allow setting qualifications_assessor_note
Browse files Browse the repository at this point in the history
This updates the form, service and controller to ensure that the note
can be saved to the assessment model so it can be used later.
  • Loading branch information
thomasleese committed Feb 15, 2024
1 parent 60c9ede commit d10f9c4
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def update
application_form.qualifications.where(
id: session[:qualification_ids],
),
qualifications_assessor_note: session[:qualifications_assessor_note],
work_histories:
application_form.work_histories.where(id: session[:work_history_ids]),
)
Expand Down Expand Up @@ -94,8 +95,9 @@ def edit_qualification_requests
@form =
SelectQualificationsForm.new(
application_form:,
session:,
qualification_ids: application_form.qualifications.pluck(:id),
qualifications_assessor_note: assessment.qualifications_assessor_note,
session:,
)
end

Expand All @@ -108,11 +110,18 @@ def update_qualification_requests
:qualification_ids,
).compact_blank

qualifications_assessor_note =
params.dig(
:assessor_interface_select_qualifications_form,
:qualifications_assessor_note,
) || ""

@form =
SelectQualificationsForm.new(
application_form:,
session:,
qualification_ids:,
qualifications_assessor_note:,
session:,
)

if @form.save
Expand Down
3 changes: 3 additions & 0 deletions app/forms/assessor_interface/select_qualifications_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ class AssessorInterface::SelectQualificationsForm
end,
}

attribute :qualifications_assessor_note

def save
return false unless valid?
session[:qualification_ids] = qualification_ids
session[:qualifications_assessor_note] = qualifications_assessor_note
true
end
end
4 changes: 4 additions & 0 deletions app/services/verify_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ def initialize(
user:,
professional_standing:,
qualifications:,
qualifications_assessor_note:,
work_histories:
)
@assessment = assessment
@user = user
@professional_standing = professional_standing
@qualifications = qualifications
@qualifications_assessor_note = qualifications_assessor_note
@work_histories = work_histories
end

Expand All @@ -22,6 +24,7 @@ def call

reference_requests =
ActiveRecord::Base.transaction do
assessment.qualifications_assessor_note = qualifications_assessor_note
assessment.verify!

create_professional_standing_request
Expand Down Expand Up @@ -49,6 +52,7 @@ class AlreadyVerified < StandardError
:user,
:professional_standing,
:qualifications,
:qualifications_assessor_note,
:work_histories

delegate :application_form, to: :assessment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
small: true,
legend: nil %>

<%= f.govuk_text_area :qualifications_assessor_note %>

<%= govuk_inset_text do %>
<p class="govuk-body">
You can deselect 1 or more qualifications from the list if you do not want to verify them.
Expand Down
2 changes: 2 additions & 0 deletions config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ en:
received_options:
true: Response received and not valid
false: Response not received
assessor_interface_select_qualifications_form:
qualifications_assessor_note: "Internal note: Add any explanatory notes for admins."
assessor_interface_verify_professional_standing_form:
verify_professional_standing_options:
true: Yes, verify LoPS
Expand Down
19 changes: 17 additions & 2 deletions spec/forms/assessor_interface/select_qualifications_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
end
let(:session) { {} }
let(:qualification_ids) { "" }
let(:qualifications_assessor_note) { "A note." }

subject(:form) do
described_class.new(application_form:, session:, qualification_ids:)
described_class.new(
application_form:,
session:,
qualification_ids:,
qualifications_assessor_note:,
)
end

describe "validations" do
Expand All @@ -26,6 +32,9 @@
[qualification_1.id.to_s, qualification_2.id.to_s],
)
end
it do
is_expected.to_not validate_presence_of(:qualifications_assessor_note)
end
end

describe "#save" do
Expand All @@ -37,10 +46,16 @@

it { is_expected.to be true }

it "changes the session" do
it "sets the qualification IDs" do
expect { save }.to change { session[:qualification_ids] }.to(
[qualification_1.id.to_s, qualification_2.id.to_s],
)
end

it "sets the qualifications assessor note" do
expect { save }.to change { session[:qualifications_assessor_note] }.to(
"A note.",
)
end
end
end
8 changes: 8 additions & 0 deletions spec/services/verify_assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
let(:user) { create(:staff, :confirmed) }
let(:professional_standing) { true }
let(:qualification) { create(:qualification, :completed, application_form:) }
let(:qualifications_assessor_note) { "A note." }
let(:work_history) { create(:work_history, :completed, application_form:) }

subject(:call) do
Expand All @@ -16,6 +17,7 @@
user:,
professional_standing:,
qualifications: [qualification],
qualifications_assessor_note:,
work_histories: [work_history],
)
end
Expand Down Expand Up @@ -101,6 +103,12 @@
end
end

it "changes the assessment qualifications assessor note" do
expect { call }.to change(assessment, :qualifications_assessor_note).to(
"A note.",
)
end

it "changes the application form stage" do
expect { call }.to change(application_form, :stage).to("verification")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class QualificationRequestsAssessmentRecommendationVerify < SitePrism::Page
sections :qualification_checkboxes,
GovukCheckboxItem,
".govuk-checkboxes__item"
element :qualifications_assessor_note_textarea, ".govuk-textarea"
element :submit_button, ".govuk-button"
end
end
Expand Down
9 changes: 5 additions & 4 deletions spec/system/assessor_interface/completing_assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,11 @@ def when_i_select_yes_verify_qualifications
end

def when_i_select_the_qualifications
assessor_qualification_requests_assessment_recommendation_verify_page
.form
.submit_button
.click
form =
assessor_qualification_requests_assessment_recommendation_verify_page.form

form.qualifications_assessor_note_textarea.fill_in with: "A note."
form.submit_button.click
end

def when_i_select_yes_verify_professional_standing
Expand Down

0 comments on commit d10f9c4

Please sign in to comment.