Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LUPEYALPHA-1109] Validation for missing practitioner email #3247

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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