diff --git a/app/forms/journeys/early_years_payment/provider/start/email_address_form.rb b/app/forms/journeys/early_years_payment/provider/start/email_address_form.rb index f29d1f59b9..89e21d5baf 100644 --- a/app/forms/journeys/early_years_payment/provider/start/email_address_form.rb +++ b/app/forms/journeys/early_years_payment/provider/start/email_address_form.rb @@ -13,6 +13,9 @@ def save ) journey_session.save! ClaimMailer.early_years_payment_provider_email(answers, otp_code(email_address), email_address).deliver_now + else + journey_session.answers.assign_attributes(email_address: email_address) + journey_session.save! end end diff --git a/app/models/journeys/early_years_payment/provider/start/slug_sequence.rb b/app/models/journeys/early_years_payment/provider/start/slug_sequence.rb index ae1a2e7afc..518e943d34 100644 --- a/app/models/journeys/early_years_payment/provider/start/slug_sequence.rb +++ b/app/models/journeys/early_years_payment/provider/start/slug_sequence.rb @@ -6,6 +6,7 @@ class SlugSequence SLUGS = %w[ email-address check-your-email + ineligible ].freeze def self.start_page_url diff --git a/app/models/policies/early_years_payments/policy_eligibility_checker.rb b/app/models/policies/early_years_payments/policy_eligibility_checker.rb index d1d7a09e04..cf73e2575c 100644 --- a/app/models/policies/early_years_payments/policy_eligibility_checker.rb +++ b/app/models/policies/early_years_payments/policy_eligibility_checker.rb @@ -16,12 +16,24 @@ def status end def ineligible? - return false if answers.is_a?(Journeys::EarlyYearsPayment::Provider::Start::SessionAnswers) - ineligibility_reason.present? end def ineligibility_reason + start_ineligibility_reason || authenticated_ineligibility_reason + end + + def start_ineligibility_reason + return nil unless answers.is_a?(Journeys::EarlyYearsPayment::Provider::Start::SessionAnswers) + + if !EligibleEyProvider.eligible_email?(answers.email_address) + :email_not_on_whitelist + end + end + + def authenticated_ineligibility_reason + return nil unless answers.is_a?(Journeys::EarlyYearsPayment::Provider::Authenticated::SessionAnswers) + if answers.nursery_urn.to_s == "none_of_the_above" :nursery_is_not_listed elsif answers.child_facing_confirmation_given == false diff --git a/app/views/early_years_payment/provider/start/claims/_ineligibility_email_not_on_whitelist.html.erb b/app/views/early_years_payment/provider/start/claims/_ineligibility_email_not_on_whitelist.html.erb new file mode 100644 index 0000000000..9266bab88d --- /dev/null +++ b/app/views/early_years_payment/provider/start/claims/_ineligibility_email_not_on_whitelist.html.erb @@ -0,0 +1,14 @@ +<% content_for(:page_title, page_title("You do not have access to this service", journey: current_journey_routing_name)) %> +<% @backlink_path = claim_path(current_journey_routing_name, "email-address") %> + +
+
+

You do not have access to this service

+

+ This email address does not have access to this service. Check the email address you entered and try again. +

+

+ To request access, contact us at <%= govuk_mail_to t("early_years_payment_provider_start.feedback_email") %>. +

+
+
diff --git a/app/views/early_years_payment/provider/start/claims/ineligible.html.erb b/app/views/early_years_payment/provider/start/claims/ineligible.html.erb new file mode 100644 index 0000000000..b499137cfb --- /dev/null +++ b/app/views/early_years_payment/provider/start/claims/ineligible.html.erb @@ -0,0 +1,2 @@ +<% ineligibility_reason = Journeys::EarlyYearsPayment::Provider::Start::EligibilityChecker.new(journey_session:).ineligibility_reason %> +<%= render "ineligibility_#{ineligibility_reason}" %> diff --git a/spec/features/early_years_payment/provider/start/ineligible_email_spec.rb b/spec/features/early_years_payment/provider/start/ineligible_email_spec.rb new file mode 100644 index 0000000000..c75e016d8a --- /dev/null +++ b/spec/features/early_years_payment/provider/start/ineligible_email_spec.rb @@ -0,0 +1,41 @@ +require "rails_helper" + +RSpec.feature "Early years payment provider" do + let(:journey_session) { Journeys::EarlyYearsPayment::Provider::Start::Session.last } + + scenario "entering an email address which is not on the whitelist" do + when_early_years_payment_provider_start_journey_configuration_exists + when_eligible_ey_provider_exists + + visit landing_page_path(Journeys::EarlyYearsPayment::Provider::Start::ROUTING_NAME) + click_link "Start now" + + expect(page.title).to have_text("Enter your email address") + expect(page).to have_content("Enter your email address") + fill_in "Email address", with: "someoneelse@example.com" + click_on "Submit" + + expect(page.title).to have_text("You do not have access to this service") + expect(page).to have_content("You do not have access to this service") + expect(page).to have_content("This email address does not have access to this service. Check the email address you entered and try again.") + expect(page).not_to have_css ".govuk-notification-banner--success" + end + + scenario "entering an email address which is not valid" do + when_early_years_payment_provider_start_journey_configuration_exists + when_eligible_ey_provider_exists + + visit landing_page_path(Journeys::EarlyYearsPayment::Provider::Start::ROUTING_NAME) + click_link "Start now" + + expect(page.title).to have_text("Enter your email address") + expect(page).to have_content("Enter your email address") + fill_in "Email address", with: "invalidemailaddress" + click_on "Submit" + + expect(page.title).to have_text("You do not have access to this service") + expect(page).to have_content("You do not have access to this service") + expect(page).to have_content("This email address does not have access to this service. Check the email address you entered and try again.") + expect(page).not_to have_css ".govuk-notification-banner--success" + end +end