From 184f8d2e9a078f3539480bb8783e42d22d75f220 Mon Sep 17 00:00:00 2001 From: vacabor <166112501+vacabor@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:30:35 +0100 Subject: [PATCH] WIP: Validation for missing practitioner email --- .../authenticated/check_your_answers_form.rb | 10 +++++++++- config/locales/en.yml | 3 ++- .../authenticated/check_your_answers_form_spec.rb | 13 ++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/forms/journeys/early_years_payment/provider/authenticated/check_your_answers_form.rb b/app/forms/journeys/early_years_payment/provider/authenticated/check_your_answers_form.rb index aabc2c5118..28e7ac833b 100644 --- a/app/forms/journeys/early_years_payment/provider/authenticated/check_your_answers_form.rb +++ b/app/forms/journeys/early_years_payment/provider/authenticated/check_your_answers_form.rb @@ -5,7 +5,9 @@ module Authenticated class CheckYourAnswersForm < Form attribute :provider_contact_name - validates :provider_contact_name, presence: {message: i18n_error_message(:valid)} + validates :provider_contact_name, presence: {message: i18n_error_message(:name)} + + validate :employee_email_provided def save return false if invalid? @@ -13,6 +15,12 @@ def save journey_session.answers.assign_attributes(provider_contact_name:) journey_session.save! end + + def employee_email_provided + if journey_session.answers.practitioner_email_address.blank? + errors.add(:practitioner_email_address, Form.i18n_error_message(:email)) + end + end end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index f63dfe0447..268199200b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1387,7 +1387,8 @@ en: valid: Enter a valid email address check_your_answers: errors: - valid: You cannot submit this claim without providing your full name + name: You cannot submit this claim without providing your full name + email: You cannot submit this claim without providing the employee’s email address check_your_answers: title: Check your answers before submitting this claim heading_send_application: Before submitting this claim diff --git a/spec/forms/journeys/early_years_payment/provider/authenticated/check_your_answers_form_spec.rb b/spec/forms/journeys/early_years_payment/provider/authenticated/check_your_answers_form_spec.rb index 04d8f2ffc2..6317fc7c94 100644 --- a/spec/forms/journeys/early_years_payment/provider/authenticated/check_your_answers_form_spec.rb +++ b/spec/forms/journeys/early_years_payment/provider/authenticated/check_your_answers_form_spec.rb @@ -2,7 +2,8 @@ RSpec.describe Journeys::EarlyYearsPayment::Provider::Authenticated::CheckYourAnswersForm, type: :model do let(:journey) { Journeys::EarlyYearsPayment::Provider::Authenticated } - let(:journey_session) { create(:early_years_payment_provider_authenticated_session) } + let(:journey_session) { create(:early_years_payment_provider_authenticated_session, answers:) } + let(:answers) { build(:early_years_payment_provider_authenticated_answers, :submittable) } let(:provider_contact_name) { nil } let(:params) do @@ -25,14 +26,20 @@ .with_message("You cannot submit this claim without providing your full name") ) end + + it "raises a validation error when provider email address is missing" do + answers.practitioner_email_address = nil + subject.save + expect(subject.errors[:practitioner_email_address]).to include("You cannot submit this claim without providing the employee’s email address") + end end describe "#save" do - let(:provider_contact_name) { "John Doe" } + let(:provider_contact_name) { "Jane Doe" } it "updates the journey session" do expect { expect(subject.save).to be(true) }.to( - change { journey_session.reload.answers.provider_contact_name }.to("John Doe") + change { journey_session.reload.answers.provider_contact_name }.to("Jane Doe") ) end end