|
11 | 11 | let(:patient) { create(:patient) } |
12 | 12 |
|
13 | 13 | before do |
| 14 | + # Associate patient with teams through locations |
14 | 15 | create(:patient_location, patient:, session: session_a) |
15 | 16 | create(:patient_location, patient:, session: session_b) |
16 | 17 | end |
17 | 18 |
|
18 | 19 | describe "#perform" do |
19 | | - subject(:perform) { described_class.new.perform(patient.id) } |
20 | | - |
21 | 20 | context "when patient exists in multiple teams" do |
22 | 21 | context "deceased" do |
23 | | - before do |
| 22 | + it "creates deceased notices for all associated teams" do |
24 | 23 | patient.update_columns( |
25 | 24 | # if we use update! the jobs gets called automatically |
26 | 25 | date_of_death: Time.current, |
27 | 26 | date_of_death_recorded_at: Time.current |
28 | 27 | ) |
29 | | - end |
30 | 28 |
|
31 | | - it "creates deceased notices for all associated teams" do |
32 | | - expect { perform }.to change { team_a.important_notices.count }.by( |
33 | | - 1 |
34 | | - ).and change { team_b.important_notices.count }.by(1) |
| 29 | + expect { described_class.new.perform(patient.id) }.to change { |
| 30 | + team_a.important_notices.count |
| 31 | + }.by(1).and change { team_b.important_notices.count }.by(1) |
35 | 32 |
|
36 | 33 | expect(team_a.important_notices.first.type).to eq("deceased") |
37 | 34 | expect(team_a.important_notices.first.message).to eq( |
38 | 35 | "Record updated with child’s date of death" |
39 | 36 | ) |
40 | | - |
41 | | - expect { described_class.new.perform(patient.id) }.to not_change( |
42 | | - team_a.important_notices, |
43 | | - :count |
44 | | - ).and not_change(team_b.important_notices, :count) |
45 | 37 | end |
46 | 38 | end |
47 | 39 |
|
48 | 40 | context "restricted" do |
49 | | - before { patient.update_column(:restricted_at, Time.current) } |
50 | | - |
51 | 41 | it "creates restricted notices for all associated teams" do |
52 | | - expect { perform }.to change(ImportantNotice, :count).by(2) |
| 42 | + patient.update_column(:restricted_at, Time.current) |
| 43 | + expect { described_class.new.perform(patient.id) }.to change( |
| 44 | + ImportantNotice, |
| 45 | + :count |
| 46 | + ).by(2) |
53 | 47 |
|
54 | 48 | notices = patient.important_notices.where(type: :restricted) |
55 | 49 | expect(notices.pluck(:team_id)).to contain_exactly( |
|
61 | 55 | end |
62 | 56 |
|
63 | 57 | context "patient is no longer restricted" do |
64 | | - before do |
| 58 | + it "dismisses existing restricted notices" do |
65 | 59 | patient.update!(restricted_at: Time.current) |
66 | 60 | patient.update_column(:restricted_at, nil) |
67 | | - end |
68 | 61 |
|
69 | | - it "dismisses existing restricted notices" do |
70 | | - expect { perform }.to change { |
| 62 | + expect { described_class.new.perform(patient.id) }.to change { |
71 | 63 | ImportantNotice |
72 | 64 | .active(team: team_a) |
73 | 65 | .where(patient:, type: :restricted) |
|
78 | 70 | end |
79 | 71 |
|
80 | 72 | context "invalidated" do |
81 | | - before { patient.update_column(:invalidated_at, Time.current) } |
82 | | - |
83 | 73 | it "creates invalidated notices for all associated teams" do |
84 | | - expect { perform }.to change(ImportantNotice, :count).by(2) |
| 74 | + patient.update_column(:invalidated_at, Time.current) |
| 75 | + |
| 76 | + expect { described_class.new.perform(patient.id) }.to change( |
| 77 | + ImportantNotice, |
| 78 | + :count |
| 79 | + ).by(2) |
85 | 80 |
|
86 | 81 | notices = patient.important_notices.where(type: :invalidated) |
87 | 82 | expect(notices.pluck(:team_id)).to contain_exactly( |
|
93 | 88 | end |
94 | 89 |
|
95 | 90 | context "patient is no longer invalidated" do |
96 | | - before do |
| 91 | + it "dismisses existing invalidated notices" do |
97 | 92 | patient.update!(invalidated_at: Time.current) |
98 | 93 | patient.update_column(:invalidated_at, nil) |
99 | | - end |
100 | 94 |
|
101 | | - it "dismisses existing invalidated notices" do |
102 | | - expect { perform }.to change { |
| 95 | + expect { described_class.new.perform(patient.id) }.to change { |
103 | 96 | ImportantNotice |
104 | 97 | .active(team: team_a) |
105 | 98 | .where(patient:, type: :invalidated) |
|
0 commit comments