-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This updates the consent reminders and requests to track when the notifications are sent by creating ConsentNotification instances.
- Loading branch information
1 parent
df5fa04
commit 334cfe2
Showing
6 changed files
with
98 additions
and
28 deletions.
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
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
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 |
---|---|---|
@@ -1,31 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
describe ConsentRequestsSessionBatchJob do | ||
let(:parents_of_patient_without_consent_sent) { create_list(:parent, 2) } | ||
subject(:perform_now) do | ||
travel_to(today) { described_class.perform_now(session) } | ||
end | ||
|
||
it "only sends emails to patient's parents to whom they have not been sent yet" do | ||
patient_with_consent_sent = | ||
create(:patient, consent_request_sent_at: Time.zone.today) | ||
patient_not_sent_consent = | ||
create(:patient, parents: parents_of_patient_without_consent_sent) | ||
session = | ||
create( | ||
:session, | ||
patients: [patient_with_consent_sent, patient_not_sent_consent] | ||
) | ||
let(:today) { Date.new(2024, 1, 1) } | ||
|
||
expect { described_class.perform_now(session) }.to send_email( | ||
to: parents_of_patient_without_consent_sent.first.email | ||
).and send_email(to: parents_of_patient_without_consent_sent.second.email) | ||
let(:programme) { create(:programme) } | ||
let(:parents) { create_list(:parent, 2) } | ||
|
||
let!(:patient_with_consent_sent) do | ||
create(:patient, :consent_request_sent, programme:) | ||
end | ||
let!(:patient_not_sent_consent) { create(:patient, parents:) } | ||
let!(:patient_with_consent) do | ||
create(:patient, :consent_given_triage_not_needed, programme:) | ||
end | ||
|
||
let(:session) do | ||
create( | ||
:session, | ||
patients: [ | ||
patient_with_consent_sent, | ||
patient_not_sent_consent, | ||
patient_with_consent | ||
], | ||
programmes: [programme] | ||
) | ||
end | ||
|
||
it "only sends emails to patient's parents to whom they have not been sent yet" do | ||
expect { perform_now }.to send_email( | ||
to: parents.first.email | ||
).and send_email(to: parents.second.email) | ||
|
||
expect(ActionMailer::Base.deliveries.count).to eq(2) | ||
end | ||
|
||
it "updates the consent_request_sent_at attribute for patients" do | ||
patient = create(:patient) | ||
session = create(:session, patients: [patient]) | ||
expect { perform_now }.to change { | ||
patient_not_sent_consent.reload.consent_request_sent_at | ||
}.to(today) | ||
end | ||
|
||
it "creates a consent notification record" do | ||
expect { perform_now }.to change(ConsentNotification, :count).by(1) | ||
|
||
described_class.perform_now(session) | ||
expect(patient.reload.consent_request_sent_at).to be_today | ||
consent_notification = | ||
ConsentNotification.find_by( | ||
programme:, | ||
patient: patient_not_sent_consent, | ||
reminder: false | ||
) | ||
expect(consent_notification).not_to be_nil | ||
expect(consent_notification.sent_at).to be_today | ||
end | ||
end |