-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3396 from DFE-Digital/ey-progress-update-emails
[CAPT-1908] EY progress update emails
- Loading branch information
Showing
11 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class EarlyYearsProgressEmailsJob < CronJob | ||
self.cron_expression = "0 8 * * *" # Every day at 08:00 | ||
|
||
def perform | ||
periods_after_submission = [2.months, 5.months] | ||
today = Date.today | ||
|
||
periods_after_submission.each do |period_after_submission| | ||
previous_date = today - period_after_submission | ||
|
||
# handle when current month has more days then previous month | ||
if today.last_day_of_the_month? && (today.day > previous_date.end_of_month.day) | ||
next | ||
end | ||
|
||
window_open = previous_date.beginning_of_day | ||
|
||
# handle when previous month has more days that current month | ||
window_close = if today.last_day_of_the_month? && (previous_date.end_of_month.day > today.day) | ||
previous_date.end_of_month.end_of_day | ||
else # normal 1:1 | ||
previous_date.end_of_day | ||
end | ||
|
||
Claim | ||
.by_policy(Policies::EarlyYearsPayments) | ||
.awaiting_decision | ||
.where(submitted_at: window_open..window_close) | ||
.find_each do |claim| | ||
EarlyYearsPaymentsMailer.with(claim:).progress_update.deliver_later | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,4 +78,8 @@ def mailer | |
def task_available?(task) | ||
true | ||
end | ||
|
||
def require_in_progress_update_emails? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "core_ext/date" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module CoreExt | ||
module Date | ||
def last_day_of_the_month? | ||
day == end_of_month.day | ||
end | ||
end | ||
end | ||
|
||
Date.include CoreExt::Date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe EarlyYearsProgressEmailsJob do | ||
let(:policy) { Policies::EarlyYearsPayments } | ||
|
||
describe "#perform" do | ||
context "when no claims" do | ||
it "does not enqueue any jobs" do | ||
expect { subject.perform }.not_to have_enqueued_job | ||
end | ||
end | ||
|
||
context "when normal day of the month" do | ||
it "enqueues jobs normally" do | ||
travel_to(Date.new(2024, 11, 12)) do | ||
create(:claim, :submitted, policy:, submitted_at: 2.months.ago - 1.day) | ||
claim_2 = create(:claim, :submitted, policy:, submitted_at: 2.months.ago) | ||
create(:claim, :submitted, policy:, submitted_at: 2.months.ago + 1.day) | ||
|
||
create(:claim, :submitted, policy:, submitted_at: 5.months.ago - 1.day) | ||
claim_5 = create(:claim, :submitted, policy:, submitted_at: 5.months.ago) | ||
create(:claim, :submitted, policy:, submitted_at: 5.months.ago + 1.day) | ||
|
||
expect { subject.perform }.to have_enqueued_job.twice | ||
|
||
expect(GlobalID::Locator.locate(queue_adapter.enqueued_jobs[0].dig(:args, 3, "params", "claim", "_aj_globalid"))).to eql(claim_2) | ||
expect(GlobalID::Locator.locate(queue_adapter.enqueued_jobs[1].dig(:args, 3, "params", "claim", "_aj_globalid"))).to eql(claim_5) | ||
end | ||
end | ||
end | ||
|
||
context "when current month same number of days as previous month" do | ||
it "enqueues jobs normally" do | ||
travel_to(Date.new(2024, 12, 31)) do | ||
create(:claim, :submitted, policy:, submitted_at: 2.months.ago - 1.day) | ||
claim_2 = create(:claim, :submitted, policy:, submitted_at: 2.months.ago) | ||
create(:claim, :submitted, policy:, submitted_at: 2.months.ago + 1.day) | ||
|
||
expect { subject.perform }.to have_enqueued_job.once | ||
|
||
expect(GlobalID::Locator.locate(queue_adapter.enqueued_jobs[0].dig(:args, 3, "params", "claim", "_aj_globalid"))).to eql(claim_2) | ||
end | ||
end | ||
end | ||
|
||
context "when current month has more days than previous month" do | ||
it "enqueues no jobs on last day" do | ||
claim_1 = create(:claim, :submitted, policy:, submitted_at: Date.new(2024, 2, 28)) | ||
claim_2 = create(:claim, :submitted, policy:, submitted_at: Date.new(2024, 2, 29)) | ||
claim_3 = create(:claim, :submitted, policy:, submitted_at: Date.new(2024, 3, 1)) | ||
|
||
travel_to(Date.new(2024, 4, 28)) do | ||
expect { subject.perform }.to have_enqueued_job.once | ||
expect(GlobalID::Locator.locate(queue_adapter.enqueued_jobs[0].dig(:args, 3, "params", "claim", "_aj_globalid"))).to eql(claim_1) | ||
end | ||
|
||
travel_to(Date.new(2024, 4, 29)) do | ||
expect { subject.perform }.to have_enqueued_job.once | ||
expect(GlobalID::Locator.locate(queue_adapter.enqueued_jobs[1].dig(:args, 3, "params", "claim", "_aj_globalid"))).to eql(claim_2) | ||
end | ||
|
||
travel_to(Date.new(2024, 4, 30)) do | ||
expect { subject.perform }.not_to have_enqueued_job | ||
end | ||
|
||
travel_to(Date.new(2024, 5, 1)) do | ||
expect { subject.perform }.to have_enqueued_job.once | ||
expect(GlobalID::Locator.locate(queue_adapter.enqueued_jobs[2].dig(:args, 3, "params", "claim", "_aj_globalid"))).to eql(claim_3) | ||
end | ||
end | ||
end | ||
|
||
context "when previous month has more days than current month" do | ||
it "enqueues extra jobs on last day" do | ||
claim_1 = create(:claim, :submitted, policy:, submitted_at: Date.new(2024, 7, 29)) | ||
claim_2 = create(:claim, :submitted, policy:, submitted_at: Date.new(2024, 7, 30)) | ||
claim_3 = create(:claim, :submitted, policy:, submitted_at: Date.new(2024, 7, 31)) | ||
claim_4 = create(:claim, :submitted, policy:, submitted_at: Date.new(2024, 8, 1)) | ||
|
||
travel_to(Date.new(2024, 9, 29)) do | ||
expect { subject.perform }.to have_enqueued_job.once | ||
expect(GlobalID::Locator.locate(queue_adapter.enqueued_jobs[0].dig(:args, 3, "params", "claim", "_aj_globalid"))).to eql(claim_1) | ||
end | ||
|
||
travel_to(Date.new(2024, 9, 30)) do | ||
expect { subject.perform }.to have_enqueued_job.twice | ||
|
||
expect do | ||
claims = queue_adapter.enqueued_jobs[1..2].map do |job| | ||
GlobalID::Locator.locate(job.dig(:args, 3, "params", "claim", "_aj_globalid")) | ||
end | ||
|
||
expect(claims).to include(claim_2) | ||
expect(claims).to include(claim_3) | ||
end | ||
end | ||
|
||
travel_to(Date.new(2024, 10, 1)) do | ||
expect { subject.perform }.to have_enqueued_job.once | ||
expect(GlobalID::Locator.locate(queue_adapter.enqueued_jobs[3].dig(:args, 3, "params", "claim", "_aj_globalid"))).to eql(claim_4) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe EarlyYearsPaymentsMailer, type: :mailer do | ||
let(:claim) { build(:claim, :submitted, policy: Policies::EarlyYearsPayments) } | ||
|
||
describe "#progress_update" do | ||
it "forms correct email" do | ||
mail = described_class.with(claim:).progress_update | ||
|
||
expect(mail.to).to eql([claim.email_address]) | ||
expect(mail.personalisation[:first_name]).to eql(claim.first_name) | ||
expect(mail.personalisation[:application_date]).to eql(claim.submitted_at.to_date.to_fs(:long_date)) | ||
expect(mail.personalisation[:ref_number]).to eql(claim.reference) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters