diff --git a/app/forms/assessor_interface/application_form_name_form.rb b/app/forms/assessor_interface/application_form_name_form.rb new file mode 100644 index 0000000000..b46bfed5b2 --- /dev/null +++ b/app/forms/assessor_interface/application_form_name_form.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AssessorInterface::ApplicationFormNameForm + include ActiveModel::Model + include ActiveModel::Attributes + + attr_accessor :application_form, :user + attribute :given_names, :string + attribute :family_name, :string + + validates :application_form, :user, presence: true + + def save + return false if invalid? + + UpdateApplicationFormName.call( + application_form:, + user:, + given_names:, + family_name:, + ) + + true + end +end diff --git a/config/locales/helpers.en.yml b/config/locales/helpers.en.yml index b98a3700c2..e8d53d8203 100644 --- a/config/locales/helpers.en.yml +++ b/config/locales/helpers.en.yml @@ -2,6 +2,9 @@ en: helpers: caption: {} hint: + assessor_interface_application_form_name_form: + given_names: Type the updated given names in the text box below + family_name: Type the updated family name in the text box below assessor_interface_assessment_section_form: selected_failure_reasons: Select all options that are relevant to you. failure_reason_notes: @@ -58,6 +61,9 @@ en: start_date: For example, 3 2020, If you cannot remember the exact month or year, enter an estimate. end_date: For example, 3 2020, If you cannot remember the exact month or year, enter an estimate. label: + assessor_interface_application_form_name_form: + given_names: Change given names + family_name: Change family name assessor_interface_assessment_recommendation_form: recommendation_options: award: Award QTS diff --git a/spec/forms/assessor_interface/application_form_name_form_spec.rb b/spec/forms/assessor_interface/application_form_name_form_spec.rb new file mode 100644 index 0000000000..e5562b1a49 --- /dev/null +++ b/spec/forms/assessor_interface/application_form_name_form_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe AssessorInterface::ApplicationFormNameForm, type: :model do + let(:application_form) { create(:application_form) } + let(:user) { create(:staff) } + + let(:given_names) { "A new given name" } + let(:family_name) { "A new family name" } + + subject(:form) do + described_class.new(application_form:, user:, given_names:, family_name:) + end + + describe "validations" do + it { is_expected.to validate_presence_of(:application_form) } + it { is_expected.to validate_presence_of(:user) } + end + + describe "#save" do + subject(:save) { form.save } + + it "calls the UpdateApplicationFormName service" do + expect(UpdateApplicationFormName).to receive(:call).with( + application_form:, + user:, + given_names:, + family_name:, + ) + expect(save).to be true + end + end +end