Skip to content

Commit

Permalink
rejecting EY claim also emails provider
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Oct 31, 2024
1 parent 099ab4c commit 38f210a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/admin/decisions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def send_claim_result_email

ClaimMailer.approved(@claim).deliver_later if @claim.latest_decision.result == "approved"
ClaimMailer.rejected(@claim).deliver_later if @claim.latest_decision.result == "rejected"

if @claim.latest_decision.result == "rejected" && @claim.has_early_years_policy?
ClaimMailer.rejected_provider_notification(@claim).deliver_later
end
end

def decision_params
Expand Down
20 changes: 20 additions & 0 deletions app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ def rejected(claim)
send_mail(template_ids(claim)[:CLAIM_REJECTED_NOTIFY_TEMPLATE_ID], personalisation)
end

def rejected_provider_notification(claim)
unknown_policy_check(claim)
set_common_instance_variables(claim)

personalisation = {
nursery_name: claim.eligibility.eligible_ey_provider.nursery_name,
ref_number: claim.reference,
practitioner_name: claim.eligibility.practitioner_name,
support_email_address: @support_email_address,
**rejected_reasons_personalisation(@claim.latest_decision&.rejected_reasons_hash)
}

template_mail(
"0c345721-c8d6-493a-95b7-006e84ba9c4e",
to: @claim.eligibility.eligible_ey_provider.primary_key_contact_email_address,
reply_to_id: @policy.notify_reply_to_id,
personalisation:
)
end

def update_after_three_weeks(claim)
unknown_policy_check(claim)
set_common_instance_variables(claim)
Expand Down
4 changes: 4 additions & 0 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ def awaiting_provider_verification?
eligibility.awaiting_provider_verification?
end

def has_early_years_policy?
policy == Policies::EarlyYearsPayments
end

private

def one_login_idv_name_match?
Expand Down
4 changes: 4 additions & 0 deletions app/models/policies/early_years_payments/eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def eligible_ey_provider
def provider_claim_submitted?
provider_claim_submitted_at.present?
end

def practitioner_name
[practitioner_first_name, practitioner_surname].join(" ")
end
end
end
end
23 changes: 23 additions & 0 deletions spec/features/admin/admin_reject_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,27 @@

expect(page).not_to have_content("Reasons")
end

context "early years claim" do
let!(:claim) do
create(
:claim,
:submitted,
policy: Policies::EarlyYearsPayments
)
end

scenario "rejecting sends email to claimant + provider" do
visit admin_claim_tasks_path(claim)
click_on "Approve or reject this claim"
choose "Reject"
check "Claim cancelled by employer"

expect {
click_button "Confirm decision"
}.to change { enqueued_jobs.count { |job| job[:job] == ActionMailer::MailDeliveryJob } }.by(2)

expect(page).to have_content("Claim has been rejected successfully")
end
end
end
33 changes: 33 additions & 0 deletions spec/mailers/claim_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,37 @@ class SomePolicy; end
expect(mail.body).to be_empty
end
end

describe "#rejected_provider_notification" do
let(:claim) do
create(
:claim,
:rejected,
policy: Policies::EarlyYearsPayments
)
end

before do
claim.eligibility.update!(
practitioner_first_name: "John",
practitioner_surname: "Doe"
)
end

it "sends correct email to provider" do
mail = described_class.rejected_provider_notification(claim)

expect(mail.to).to eql([claim.eligibility.eligible_ey_provider.primary_key_contact_email_address])
expect(mail.personalisation[:nursery_name]).to eql(claim.eligibility.eligible_ey_provider.nursery_name)
expect(mail.personalisation[:ref_number]).to eql(claim.reference)
expect(mail.personalisation[:practitioner_name]).to eql("John Doe")
expect(mail.personalisation[:support_email_address]).to eql("[email protected]")

expect(mail.personalisation[:reason_claim_cancelled_by_employer]).to eql("yes")
expect(mail.personalisation[:reason_six_month_retention_check_failed]).to eql("no")
expect(mail.personalisation[:reason_duplicate]).to eql("no")
expect(mail.personalisation[:reason_no_response]).to eql("no")
expect(mail.personalisation[:reason_other]).to eql("no")
end
end
end

0 comments on commit 38f210a

Please sign in to comment.