Skip to content

Commit

Permalink
Merge pull request #3360 from DFE-Digital/ey-provider-rejection-email
Browse files Browse the repository at this point in the history
[LUPEYALPHA-1235] Rejecting EY claim also emails provider
  • Loading branch information
asmega authored Nov 1, 2024
2 parents 0161fd2 + dcdd633 commit eb1b25a
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/controllers/admin/decisions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ def send_claim_result_email
return if @claim.awaiting_qa?

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.email_address.present?
ClaimMailer.rejected(@claim).deliver_later
end

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 @@ -453,6 +453,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
2 changes: 0 additions & 2 deletions app/models/policies/early_years_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ module EarlyYearsPayments
LevellingUpPremiumPayments
]

VERIFIERS = []

# TODO: This is needed once the reply-to email address has been added to Gov Notify
def notify_reply_to_id
nil
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 @@ -33,6 +33,10 @@ def employment_task_available_at
def employment_task_available?
Date.today >= employment_task_available_at
end

def practitioner_name
[practitioner_first_name, practitioner_surname].join(" ")
end
end
end
end
49 changes: 49 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,53 @@

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

context "early years claim" do
context "claimant has not completed their half" do
let!(:claim) do
create(
:claim,
:submitted,
policy: Policies::EarlyYearsPayments,
email_address: nil
)
end

scenario "rejecting sends email to provider only when claimant yet to complete" 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(1)

expect(page).to have_content("Claim has been rejected successfully")
end
end

context "claimant has completed their half" 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
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 eb1b25a

Please sign in to comment.