Skip to content

Commit

Permalink
Add resend email actions for payers and providers
Browse files Browse the repository at this point in the history
Includes addition of new mailers, services and updated test logic
  • Loading branch information
Kizr committed Jan 30, 2025
1 parent ba45ff2 commit 3a65501
Show file tree
Hide file tree
Showing 24 changed files with 301 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/_timeline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

.app-timeline__description {
@include govuk-font($size: 19);
margin-top: govuk-spacing(4);
margin-top: govuk-spacing(2);
}

/* ==========================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,32 @@ def show
authorize [:claims, claim_activity]
end

def resend_email
raise
def resend_payer_email
case claim_activity.action
when "payment_request_delivered"
Claims::Payment::ResendEmail.call(payment: claim_activity.record)
when "clawback_request_delivered"
Claims::Clawback::ResendEmail.call(clawback: claim_activity.record)
end

authorize [:claims, claim_activity]
redirect_to claims_support_claims_claim_activity_path(claim_activity), flash: { success: true, heading: t(".success") }
end

def resend_provider_email
Claims::Sampling::ResendEmails.call(provider_sampling:)

authorize [:claims, claim_activity]
redirect_to claims_support_claims_claim_activity_path(claim_activity), flash: { success: true, heading: t(".success", provider_name: provider_sampling.provider_name) }
end

private

def claim_activity
@claim_activity ||= Claims::ClaimActivity.find(params[:id])
end

def provider_sampling
@provider_sampling ||= claim_activity.record.provider_samplings.find(params[:provider_sampling_id])
end
end
8 changes: 8 additions & 0 deletions app/mailers/claims/esfa_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ def claims_require_clawback(clawback)
body: t(".body", url_for_csv: claims_clawback_claims_url(token:), support_email:, service_name:)
end

def resend_claims_require_clawback(clawback)
@clawback = clawback

notify_email to: esfa_email_addresses,
subject: t(".subject"),
body: t(".body", url_for_csv: claims_clawback_claims_url(token:), support_email:, service_name:)
end

private

def esfa_email_addresses
Expand Down
13 changes: 13 additions & 0 deletions app/mailers/claims/payment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ def payment_created_notification(payment)
)
end

def resend_payment_created_notification(payment)
@payment = payment

notify_email to: esfa_email_addresses,
from: support_email,
subject: t(".subject"),
body: t(
".body",
download_page_url: claims_payments_claims_url(token:),
support_email:,
)
end

private

def esfa_email_addresses
Expand Down
7 changes: 7 additions & 0 deletions app/policies/claims/support/claims/claim_activity_policy.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class Claims::Support::Claims::ClaimActivityPolicy < Claims::ApplicationPolicy
def resend_payer_email?
true
end

def resend_provider_email?
true
end
end
13 changes: 13 additions & 0 deletions app/services/claims/clawback/resend_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Claims::Clawback::ResendEmail < ApplicationService
def initialize(clawback:)
@clawback = clawback
end

def call
Claims::ESFAMailer.resend_claims_require_clawback(clawback).deliver_later
end

private

attr_reader :clawback
end
13 changes: 13 additions & 0 deletions app/services/claims/payment/resend_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Claims::Payment::ResendEmail < ApplicationService
def initialize(payment:)
@payment = payment
end

def call
Claims::PaymentMailer.resend_payment_created_notification(payment).deliver_later
end

private

attr_reader :payment
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="govuk-button-group">
<%= govuk_button_link_to t(".download_csv"), claim_activity.record.csv_file, secondary: true %>
<% unless claim_activity.action == "clawback_response_uploaded" %>
<%= govuk_button_link_to t(".resend_email_to_payer"), resend_email_claims_support_claims_claim_activity_path(claim_activity), secondary: true %>
<%= govuk_button_link_to t(".resend_email_to_payer"), resend_payer_email_claims_support_claims_claim_activity_path(claim_activity), secondary: true %>
<% end %>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

<div class="govuk-button-group">
<%= govuk_button_link_to t(".download_csv"), provider_sampling.csv_file, secondary: true %>
<%= govuk_button_link_to t(".resend_email_to_provider"), resend_email_claims_support_claims_claim_activity_path(claim_activity, provider_id: provider_sampling.provider_id), secondary: true %>
<% unless claim_activity.action == "sampling_response_uploaded" %>
<%= govuk_button_link_to t(".resend_email_to_provider"), resend_provider_email_claims_support_claims_claim_activity_path(claim_activity, provider_sampling_id: provider_sampling.id), secondary: true %>
<% end %>
</div>

<table class="govuk-table">
Expand Down
28 changes: 28 additions & 0 deletions config/locales/en/claims/esfa_mailer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,33 @@ en:
# Give feedback or report a problem
If you have any questions or feedback, please contact the team at [%{support_email}](mailto:%{support_email}).

Regards
%{service_name} team
resend_claims_require_clawback:
subject: Claims requiring clawback - Claim funding for mentor training
body: |
To the payer,
^ We are resending this email as requested. Please disregard any previous emails you may have received.
The claims in the CSV file link are ready for clawback— the link to the latest CSV file is valid for 7 days:
%{url_for_csv}
What you need to do:
1. Check and validate the claims in the CSV file by marking them as ‘clawback_in_progress’ or ‘clawback_complete’ in the ‘claim_status’ column.
2. If you mark a claim as ‘clawback_in_progress’, add the reason to the ‘clawback_unsuccessful_reason’ column.
3. Reply to this email and attach the updated CSV file.
The Claim Support team will follow up on the reasons for the claims that you could not claw back and email you an updated version.
If you have a problem opening the link or it has expired, reply to this email and request that it be sent again.
# Give feedback or report a problem
If you have any questions or feedback, please contact the team at [%{support_email}](mailto:%{support_email}).
Regards
%{service_name} team
29 changes: 29 additions & 0 deletions config/locales/en/claims/payment_mailer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,34 @@ en:
If you have any questions or feedback, please contact the team at [%{support_email}](%{support_email}).
Regards
Claim funding for mentor training team
resend_payment_created_notification:
subject: Claims ready for payment - Claim funding for mentor training
body: |
To the payer,
^ We are resending this email as requested. Please disregard any previous emails you may have received.
These claims from the Claim funding for mentor training service (Claim) are ready for payment — the link to the latest CSV file is valid for 7 days:
[%{download_page_url}](%{download_page_url})
What you need to do:
1. Check and validate the claims in the CSV file by marking them as ‘paid’ or ‘unpaid’ in the ‘claim_status’ column.
2. If you mark a claim as ‘unpaid’, add the reason in the ‘claim_unpaid_reason’ column.
3. Reply to this email and attach the updated CSV file.
The Claim Support team will follow up on the reasons for unpaid claims and email back an updated version.
If you have a problem opening the link or it has expired, reply to this email and request that it be sent again.
# Give feedback or report a problem
If you have any questions or feedback, please contact the team at [%{support_email}](%{support_email}).
Regards
Claim funding for mentor training team
2 changes: 1 addition & 1 deletion config/locales/en/claims/provider_mailer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ en:
body: |
%{provider_name},
^ We are resending this email due to an internal issue. Please disregard any previous emails you may have received.
^ We are resending this email as requested. Please disregard any previous emails you may have received.
You are required by Department for Education (DfE) to complete quality assurance on funding claims associated with %{provider_name}.
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en/claims/support/claims/claim_activities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ en:
claim_amount: Claim amount
payment_response_activity:
download_csv: Download CSV
resend_payer_email:
success: An email has been sent to the payer
resend_provider_email:
success: An email has been sent to %{provider_name}
3 changes: 2 additions & 1 deletion config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@

resources :claim_activities, path: "activity", only: %i[index show] do
member do
get :resend_email
get :resend_payer_email
get :resend_provider_email
end
end
end
Expand Down
56 changes: 47 additions & 9 deletions spec/mailers/claims/esfa_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
require "rails_helper"

RSpec.describe Claims::ESFAMailer, type: :mailer do
let(:clawback) { create(:claims_clawback) }
let(:url_for_csv) { claims_clawback_claims_url(token:, host: "claims.localhost") }
let(:token) { Rails.application.message_verifier(:clawback).generate(clawback.id, expires_in: 7.days) }
let(:esfa_emails) { %w[[email protected] [email protected]] }
let(:service_name) { "Claim funding for mentor training" }
let(:support_email) { "[email protected]" }

before do
allow(Rails.application.message_verifier(:clawback)).to receive(:generate).and_return("token")
end

describe "#claims_require_clawback" do
subject(:claims_require_clawback_email) { described_class.claims_require_clawback(clawback) }

let(:clawback) { create(:claims_clawback) }
let(:url_for_csv) { claims_clawback_claims_url(token:, host: "claims.localhost") }
let(:token) { Rails.application.message_verifier(:clawback).generate(clawback.id, expires_in: 7.days) }
let(:esfa_emails) { %w[[email protected] [email protected]] }
let(:service_name) { "Claim funding for mentor training" }
let(:support_email) { "[email protected]" }
it "sends the claims require clawback email" do
ClimateControl.modify CLAIMS_ESFA_EMAIL_ADDRESSES: esfa_emails.join(",") do
expect(claims_require_clawback_email.to).to match_array(esfa_emails)
expect(claims_require_clawback_email.subject).to eq("Claims requiring clawback - Claim funding for mentor training")
expect(claims_require_clawback_email.body.to_s.squish).to eq(<<~EMAIL.squish)
To the payer,
The claims in the CSV file link are ready for clawback— the link to the latest CSV file is valid for 7 days:
#{url_for_csv}
What you need to do:
1. Check and validate the claims in the CSV file by marking them as ‘clawback_in_progress’ or ‘clawback_complete’ in the ‘claim_status’ column.
2. If you mark a claim as ‘clawback_in_progress’, add the reason to the ‘clawback_unsuccessful_reason’ column.
3. Reply to this email and attach the updated CSV file.
The Claim Support team will follow up on the reasons for the claims that you could not claw back and email you an updated version.
If you have a problem opening the link or it has expired, reply to this email and request that it be sent again.
# Give feedback or report a problem
If you have any questions or feedback, please contact the team at [#{support_email}](mailto:#{support_email}).
before do
allow(Rails.application.message_verifier(:clawback)).to receive(:generate).and_return("token")
Regards
#{service_name} team
EMAIL
end
end
end

it "sends the claims require clawback email" do
describe "#resend_claims_require_clawback" do
subject(:claims_require_clawback_email) { described_class.resend_claims_require_clawback(clawback) }

it "sends the resend claims require clawback email" do
ClimateControl.modify CLAIMS_ESFA_EMAIL_ADDRESSES: esfa_emails.join(",") do
expect(claims_require_clawback_email.to).to match_array(esfa_emails)
expect(claims_require_clawback_email.subject).to eq("Claims requiring clawback - Claim funding for mentor training")
expect(claims_require_clawback_email.body.to_s.squish).to eq(<<~EMAIL.squish)
To the payer,
^ We are resending this email as requested. Please disregard any previous emails you may have received.
The claims in the CSV file link are ready for clawback— the link to the latest CSV file is valid for 7 days:
#{url_for_csv}
Expand Down
43 changes: 40 additions & 3 deletions spec/mailers/claims/payment_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@
require "rails_helper"

RSpec.describe Claims::PaymentMailer, freeze: "20 December 2024", type: :mailer do
let(:payment) { create(:claims_payment) }
let(:download_page_url) { claims_payments_claims_url(token:, host: "claims.localhost") }
let(:token) { Rails.application.message_verifier(:payments).generate(payment.id, expires_in: 7.days) }

describe "#payment_created_notification" do
subject(:email) { described_class.payment_created_notification(payment) }

let(:payment) { create(:claims_payment) }
let(:download_page_url) { claims_payments_claims_url(token:, host: "claims.localhost") }
let(:token) { Rails.application.message_verifier(:payments).generate(payment.id, expires_in: 7.days) }
it "sends the sampling checks required email" do
expect(email.to).to contain_exactly("[email protected]")
expect(email.subject).to eq("Claims ready for payment - Claim funding for mentor training")
expect(email.body.to_s.squish).to eq(<<~EMAIL.squish)
To the payer,
These claims from the Claim funding for mentor training service (Claim) are ready for payment — the link to the latest CSV file is valid for 7 days:
[#{download_page_url}](#{download_page_url})
What you need to do:
1. Check and validate the claims in the CSV file by marking them as ‘paid’ or ‘unpaid’ in the ‘claim_status’ column.
2. If you mark a claim as ‘unpaid’, add the reason in the ‘claim_unpaid_reason’ column.
3. Reply to this email and attach the updated CSV file.
The Claim Support team will follow up on the reasons for unpaid claims and email back an updated version.
If you have a problem opening the link or it has expired, reply to this email and request that it be sent again.
# Give feedback or report a problem
If you have any questions or feedback, please contact the team at [[email protected]]([email protected]).
Regards
Claim funding for mentor training team
EMAIL
end
end

describe "#resend_payment_created_notification" do
subject(:email) { described_class.resend_payment_created_notification(payment) }

it "sends the sampling checks required email" do
expect(email.to).to contain_exactly("[email protected]")
expect(email.subject).to eq("Claims ready for payment - Claim funding for mentor training")
expect(email.body.to_s.squish).to eq(<<~EMAIL.squish)
To the payer,
^ We are resending this email as requested. Please disregard any previous emails you may have received.
These claims from the Claim funding for mentor training service (Claim) are ready for payment — the link to the latest CSV file is valid for 7 days:
[#{download_page_url}](#{download_page_url})
Expand Down
4 changes: 4 additions & 0 deletions spec/mailers/previews/claims/esfa_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ class Claims::ESFAMailerPreview < ActionMailer::Preview
def claims_require_clawback
Claims::ESFAMailer.claims_require_clawback("https://example.com")
end

def resend_claims_require_clawback
Claims::ESFAMailer.resend_claims_require_clawback("https://example.com")
end
end
4 changes: 4 additions & 0 deletions spec/mailers/previews/claims/payment_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ def payment_created_notification
Claims::PaymentMailer.payment_created_notification(payment)
end

def resend_payment_created_notification
Claims::PaymentMailer.resend_payment_created_notification(payment)
end

private

def payment
Expand Down
Loading

0 comments on commit 3a65501

Please sign in to comment.