|
3 | 3 | describe InvalidateSelfConsentsJob do
|
4 | 4 | subject(:perform_now) { described_class.perform_now }
|
5 | 5 |
|
| 6 | + let(:patient) { consent.patient } |
| 7 | + let(:programme) { consent.programme } |
| 8 | + let(:team) { consent.team } |
| 9 | + |
6 | 10 | context "with parental consent from yesterday" do
|
7 | 11 | let(:consent) { create(:consent, created_at: 1.day.ago) }
|
8 | 12 |
|
| 13 | + before { create(:patient_vaccination_status, patient:, programme:) } |
| 14 | + |
9 | 15 | it "does not invalidate the consent" do
|
10 | 16 | expect { perform_now }.not_to(change { consent.reload.invalidated? })
|
11 | 17 | end
|
12 | 18 |
|
13 | 19 | context "with triage" do
|
14 | 20 | let(:triage) do
|
15 |
| - create( |
16 |
| - :triage, |
17 |
| - created_at: 1.day.ago, |
18 |
| - team: consent.team, |
19 |
| - programme: consent.programme, |
20 |
| - patient: consent.patient |
21 |
| - ) |
| 21 | + create(:triage, created_at: 1.day.ago, team:, programme:, patient:) |
22 | 22 | end
|
23 | 23 |
|
24 | 24 | it "does not invalidate the triage" do
|
|
30 | 30 | context "with parental consent from today" do
|
31 | 31 | let(:consent) { create(:consent) }
|
32 | 32 |
|
| 33 | + before { create(:patient_vaccination_status, patient:, programme:) } |
| 34 | + |
33 | 35 | it "does not invalidate the consent" do
|
34 | 36 | expect { perform_now }.not_to(change { consent.reload.invalidated? })
|
35 | 37 | end
|
36 | 38 |
|
37 | 39 | context "with triage" do
|
38 |
| - let(:triage) do |
39 |
| - create( |
40 |
| - :triage, |
41 |
| - team: consent.team, |
42 |
| - programme: consent.programme, |
43 |
| - patient: consent.patient |
44 |
| - ) |
45 |
| - end |
| 40 | + let(:triage) { create(:triage, team:, programme:, patient:) } |
46 | 41 |
|
47 | 42 | it "does not invalidate the triage" do
|
48 | 43 | expect { perform_now }.not_to(change { triage.reload.invalidated? })
|
|
53 | 48 | context "with self-consent from yesterday" do
|
54 | 49 | let(:consent) { create(:consent, :self_consent, created_at: 1.day.ago) }
|
55 | 50 |
|
| 51 | + before { create(:patient_vaccination_status, patient:, programme:) } |
| 52 | + |
56 | 53 | it "invalidates the consent" do
|
57 | 54 | expect { perform_now }.to change { consent.reload.invalidated? }.from(
|
58 | 55 | false
|
|
61 | 58 |
|
62 | 59 | context "with triage" do
|
63 | 60 | let(:triage) do
|
64 |
| - create( |
65 |
| - :triage, |
66 |
| - created_at: 1.day.ago, |
67 |
| - team: consent.team, |
68 |
| - programme: consent.programme, |
69 |
| - patient: consent.patient |
70 |
| - ) |
| 61 | + create(:triage, created_at: 1.day.ago, team:, programme:, patient:) |
71 | 62 | end
|
72 | 63 |
|
73 | 64 | it "invalidates the triage" do
|
|
76 | 67 | ).to(true)
|
77 | 68 | end
|
78 | 69 | end
|
| 70 | + |
| 71 | + context "if the patient was vaccinated" do |
| 72 | + before do |
| 73 | + create( |
| 74 | + :vaccination_record, |
| 75 | + team:, |
| 76 | + programme:, |
| 77 | + patient:, |
| 78 | + created_at: 1.day.ago |
| 79 | + ) |
| 80 | + |
| 81 | + patient.vaccination_statuses.update_all(status: :vaccinated) |
| 82 | + end |
| 83 | + |
| 84 | + it "does not invalidate the consent" do |
| 85 | + expect { perform_now }.not_to(change { consent.reload.invalidated? }) |
| 86 | + end |
| 87 | + |
| 88 | + context "with triage" do |
| 89 | + let(:triage) do |
| 90 | + create(:triage, created_at: 1.day.ago, team:, programme:, patient:) |
| 91 | + end |
| 92 | + |
| 93 | + it "does not invalidate the triage" do |
| 94 | + expect { perform_now }.not_to(change { triage.reload.invalidated? }) |
| 95 | + end |
| 96 | + end |
| 97 | + end |
79 | 98 | end
|
80 | 99 |
|
81 | 100 | context "with self-consent from today" do
|
82 | 101 | let(:consent) { create(:consent, :self_consent) }
|
83 | 102 |
|
| 103 | + before { create(:patient_vaccination_status, patient:, programme:) } |
| 104 | + |
84 | 105 | it "does not invalidate the consent" do
|
85 | 106 | expect { perform_now }.not_to(change { consent.reload.invalidated? })
|
86 | 107 | end
|
87 | 108 |
|
88 | 109 | context "with triage" do
|
89 |
| - let(:triage) do |
90 |
| - create( |
91 |
| - :triage, |
92 |
| - team: consent.team, |
93 |
| - programme: consent.programme, |
94 |
| - patient: consent.patient |
95 |
| - ) |
96 |
| - end |
| 110 | + let(:triage) { create(:triage, team:, programme:, patient:) } |
97 | 111 |
|
98 | 112 | it "does not invalidate the triage" do
|
99 | 113 | expect { perform_now }.not_to(change { triage.reload.invalidated? })
|
|
129 | 143 | )
|
130 | 144 | end
|
131 | 145 |
|
| 146 | + before do |
| 147 | + create(:patient_vaccination_status, patient:, programme: self_programme) |
| 148 | + create(:patient_vaccination_status, patient:, programme: parent_programme) |
| 149 | + end |
| 150 | + |
132 | 151 | it "does not invalidate the parent consent" do
|
133 | 152 | expect { perform_now }.not_to(
|
134 | 153 | change { parent_consent.reload.invalidated? }
|
|
0 commit comments