Skip to content

Commit

Permalink
WIP: Validation for missing practitioner email
Browse files Browse the repository at this point in the history
  • Loading branch information
vacabor committed Oct 1, 2024
1 parent a622b14 commit 184f8d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ 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?

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
Expand Down
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 184f8d2

Please sign in to comment.