Skip to content

Commit

Permalink
Add ability to change applicant name
Browse files Browse the repository at this point in the history
This adds the ability for an assessor with the right permissions to
change the applicant name associated with an application.
  • Loading branch information
thomasleese committed Aug 21, 2023
1 parent bbdc705 commit e40930c
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 3 deletions.
28 changes: 28 additions & 0 deletions app/controllers/assessor_interface/application_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ def status
@view_object = show_view_object
end

def edit
authorize [:assessor_interface, application_form]

@form = ApplicationFormNameForm.new
end

def update
authorize [:assessor_interface, application_form]

@form =
ApplicationFormNameForm.new(
form_params.merge(application_form:, user: current_staff),
)

if @form.save
redirect_to [:assessor_interface, application_form]
else
render :edit, status: :unprocessable_entity
end
end

def withdraw
authorize [:assessor_interface, application_form]
end
Expand Down Expand Up @@ -65,5 +86,12 @@ def show_view_object
def application_form
@application_form ||= show_view_object.application_form
end

def form_params
params.require(:assessor_interface_application_form_name_form).permit(
:given_names,
:family_name,
)
end
end
end
34 changes: 34 additions & 0 deletions app/views/assessor_interface/application_forms/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<% title = "Change details for ‘#{application_form_full_name(@application_form)}’" %>

<% content_for :page_title, "#{"Error: " if @form.errors.any?}#{title}" %>
<% content_for :back_link_url, assessor_interface_application_form_path(@application_form) %>

<%= form_with model: @form, url: [:assessor_interface, @application_form], method: :put do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-xl"><%= title %></h1>

<h2 class="govuk-heading-m">Current name</h2>

<%= govuk_summary_list(actions: false) do |summary_list|
summary_list.with_row do |row|
row.with_key { "Given names" }
row.with_value { @application_form.given_names }
end

summary_list.with_row do |row|
row.with_key { "Family name" }
row.with_value { @application_form.family_name }
end
end %>

<h2 class="govuk-heading-m">Change name</h2>
<p class="govuk-body">Use this form to change one or more of the names.</p>

<%= f.govuk_text_field :given_names %>
<%= f.govuk_text_field :family_name %>

<%= f.govuk_submit do %>
<%= govuk_link_to "Cancel", [:assessor_interface, @application_form] %>
<% end %>
<% end %>
4 changes: 1 addition & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
namespace :assessor_interface, path: "/assessor" do
root to: redirect("/assessor/applications")

resources :application_forms,
path: "/applications",
only: %i[index show destroy] do
resources :application_forms, path: "/applications", except: :new do
collection do
post "filters/apply", to: "application_forms#apply_filters"
get "filters/clear", to: "application_forms#clear_filters"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module PageObjects
module AssessorInterface
class EditApplication < SitePrism::Page
set_url "/assessor/applications/{application_form_id}/edit"

section :form, "form" do
element :given_names_field,
"#assessor-interface-application-form-name-form-given-names-field"
element :family_name_field,
"#assessor-interface-application-form-name-form-family-name-field"
element :submit_button, ".govuk-button"
end
end
end
end
5 changes: 5 additions & 0 deletions spec/support/page_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def assessor_assessment_section_page
PageObjects::AssessorInterface::AssessmentSection.new
end

def assessor_edit_application_page
@assessor_edit_application_page ||=
PageObjects::AssessorInterface::EditApplication.new
end

def assessor_edit_professional_standing_request_location_page
@assessor_edit_professional_standing_request_location_page ||=
PageObjects::AssessorInterface::EditProfessionalStandingRequestLocation.new
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Assessor change application form name", type: :system do
before do
given_the_service_is_open
given_there_is_an_application_form
end

it "checks manage applications permission" do
given_i_am_authorized_as_a_user(assessor)

when_i_visit_the(:assessor_edit_application_page, application_form_id:)
then_i_see_the_forbidden_page
end

it "allows changing application form name" do
given_i_am_authorized_as_a_user(manager)

when_i_visit_the(:assessor_application_page, application_id:)
then_i_see_the(:assessor_application_page)

when_i_click_on_change_name
then_i_see_the(:assessor_edit_application_page, application_form_id:)

when_i_fill_in_the_name
then_i_see_the(:assessor_application_page, application_id:)
end

def given_there_is_an_application_form
application_form
end

def when_i_click_on_change_name
assessor_application_page
.summary_list
.find_row(key: "Name")
.actions
.link
.click
end

def when_i_fill_in_the_name
assessor_edit_application_page.form.given_names_field.fill_in with:
"New given names"
assessor_edit_application_page.form.family_name_field.fill_in with:
"New family name"
assessor_edit_application_page.form.submit_button.click
end

def application_form
@application_form ||=
create(
:application_form,
:submitted,
:with_personal_information,
:with_assessment,
)
end

delegate :id, to: :application_form, prefix: true
alias_method :application_id, :application_form_id

def assessor
create(:staff, :confirmed, :with_award_decline_permission)
end

def manager
create(:staff, :confirmed, :with_change_name_permission)
end
end

0 comments on commit e40930c

Please sign in to comment.