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-1062] Ineligibility page for when the claim has already been submitted #3296

Merged
merged 2 commits into from
Oct 11, 2024
Merged
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 @@ -10,23 +10,19 @@ class FindReferenceForm < Form
def save
return false if invalid?

existing_claim = Claim
.by_policy(Policies::EarlyYearsPayments)
.find_by(reference: reference_number, practitioner_email_address: email)

journey_session.answers.assign_attributes(
reference_number:,
start_email: email,
reference_number_found: claim_exists?
reference_number_found: existing_claim.present?,
claim_already_submitted: existing_claim&.submitted?,
nursery_name: existing_claim&.eligibility&.eligible_ey_provider&.nursery_name
)
journey_session.save!
end

private

def claim_exists?
Claim
.by_policy(Policies::EarlyYearsPayments)
.where(reference: reference_number)
.where(practitioner_email_address: email)
.exists?
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Practitioner
class SessionAnswers < Journeys::SessionAnswers
attribute :reference_number, :string
attribute :reference_number_found, :boolean, default: nil
attribute :claim_already_submitted, :boolean, default: nil
attribute :nursery_name
attribute :start_email, :string

def policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def practitioner_ineligibility_reason

if answers.reference_number_found == false
:reference_number_not_found
elsif answers.claim_already_submitted == true
:claim_already_submitted
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% content_for(:page_title, page_title("You've already submitted your claim", journey: current_journey_routing_name)) %>
<% @backlink_path = claim_path(current_journey_routing_name, "find-reference", request.query_parameters) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
You've already submitted your claim
</h1>

<p class="govuk-body">
We're reviewing your application and we'll let you know by email if it's accepted or rejected.
</p>

<p class="govuk-body">
After 6 months in your role, we'll check that you’re still working at <%= answers.nursery_name %>. If you are:
</p>

<ul class="govuk-list govuk-list--bullet">
<li>we’ll pay the full incentive amount into your bank account</li>
<li>email you to confirm the payment</li>
</ul>

<p class="govuk-body">
If you have questions or need support with this claim, email
<%= govuk_link_to t("early_years_payment_practitioner.feedback_email"), "mailto:#{t("early_years_payment_practitioner.feedback_email")}", no_visited_state: true %>
</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FactoryBot.define do
factory :early_years_practitioner_answers, class: "Journeys::EarlyYearsPayment::Practitioner::SessionAnswers" do
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,34 @@

expect(page).to have_content "Enter your claim reference"
end

context "when the claim is already submitted" do
let(:eligible_ey_provider) { create(:eligible_ey_provider, nursery_name: "Test Nursery") }

let(:claim) do
create(
:claim,
:submitted,
policy: Policies::EarlyYearsPayments,
eligibility: build(:early_years_payments_eligibility, nursery_urn: eligible_ey_provider.urn),
reference: "foo",
practitioner_email_address: "[email protected]"
)
end

scenario "should show ineligibility page when a submitted claim reference is given" do
when_early_years_payment_practitioner_journey_configuration_exists

visit "/early-years-payment-practitioner/find-reference?skip_landing_page=true&[email protected]"
expect(page).to have_content "Enter your claim reference"
fill_in "Claim reference number", with: claim.reference
click_button "Submit"

expect(page).to have_content "You've already submitted your claim"
expect(page).to have_content "After 6 months in your role, we'll check that you’re still working at Test Nursery."

click_link "Back"
expect(page).to have_content "Enter your claim reference"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
let(:reference_number) { nil }
let(:email) { nil }

let(:eligible_ey_provider) { create(:eligible_ey_provider) }

let(:params) do
ActionController::Parameters.new(claim: {reference_number:, email:})
end
Expand Down Expand Up @@ -48,6 +50,7 @@
create(
:claim,
policy: Policies::EarlyYearsPayments,
eligibility: build(:early_years_payments_eligibility, nursery_urn: eligible_ey_provider.urn),
reference: "foo"
)
end
Expand All @@ -64,6 +67,30 @@
}.to change { journey_session.reload.answers.reference_number_found }.from(nil).to(true)
end

it "updates nursery_name in session" do
expect {
subject.save
}.to change { journey_session.reload.answers.nursery_name }.from(nil).to(eligible_ey_provider.nursery_name)
end

context "when the claim is already submitted" do
let(:claim) do
create(
:claim,
:submitted,
policy: Policies::EarlyYearsPayments,
eligibility: build(:early_years_payments_eligibility, nursery_urn: eligible_ey_provider.urn),
reference: "foo"
)
end

it "updates claim_already_submitted in session" do
expect {
subject.save
}.to change { journey_session.reload.answers.claim_already_submitted }.from(nil).to(true)
end
end

context "when reference is a random string" do
let(:reference_number) { "foo" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,35 @@
expect(subject.ineligibility_reason).to eql(:nursery_is_not_listed)
end
end

context "when ineligible as :reference_number_not_found" do
let(:answers) do
build(
:early_years_practitioner_answers,
reference_number_found: false
)
end

it "is ineligble as :reference_number_not_found" do
expect(subject).to be_ineligible
expect(subject.status).to eql(:ineligible)
expect(subject.ineligibility_reason).to eql(:reference_number_not_found)
end
end

context "when ineligible as :claim_already_submitted" do
let(:answers) do
build(
:early_years_practitioner_answers,
claim_already_submitted: true
)
end

it "is ineligble as :claim_already_submitted" do
expect(subject).to be_ineligible
expect(subject.status).to eql(:ineligible)
expect(subject.ineligibility_reason).to eql(:claim_already_submitted)
end
end
end
end