|
3 | 3 | describe InvalidateSelfConsentsJob do
|
4 | 4 | subject(:perform_now) { described_class.perform_now }
|
5 | 5 |
|
| 6 | + let(:academic_year) { AcademicYear.current } |
| 7 | + let(:patient) { consent.patient } |
| 8 | + let(:programme) { consent.programme } |
| 9 | + let(:team) { consent.team } |
| 10 | + |
6 | 11 | context "with parental consent from yesterday" do
|
7 |
| - let(:consent) { create(:consent, created_at: 1.day.ago) } |
| 12 | + let(:consent) { create(:consent, academic_year:, created_at: 1.day.ago) } |
| 13 | + |
| 14 | + before { create(:patient_vaccination_status, patient:, programme:) } |
8 | 15 |
|
9 | 16 | it "does not invalidate the consent" do
|
10 | 17 | expect { perform_now }.not_to(change { consent.reload.invalidated? })
|
|
14 | 21 | let(:triage) do
|
15 | 22 | create(
|
16 | 23 | :triage,
|
| 24 | + academic_year:, |
17 | 25 | created_at: 1.day.ago,
|
18 |
| - team: consent.team, |
19 |
| - programme: consent.programme, |
20 |
| - patient: consent.patient |
| 26 | + team:, |
| 27 | + programme:, |
| 28 | + patient: |
21 | 29 | )
|
22 | 30 | end
|
23 | 31 |
|
|
28 | 36 | end
|
29 | 37 |
|
30 | 38 | context "with parental consent from today" do
|
31 |
| - let(:consent) { create(:consent) } |
| 39 | + let(:consent) { create(:consent, academic_year:) } |
| 40 | + |
| 41 | + before { create(:patient_vaccination_status, patient:, programme:) } |
32 | 42 |
|
33 | 43 | it "does not invalidate the consent" do
|
34 | 44 | expect { perform_now }.not_to(change { consent.reload.invalidated? })
|
35 | 45 | end
|
36 | 46 |
|
37 | 47 | context "with triage" do
|
38 | 48 | let(:triage) do
|
39 |
| - create( |
40 |
| - :triage, |
41 |
| - team: consent.team, |
42 |
| - programme: consent.programme, |
43 |
| - patient: consent.patient |
44 |
| - ) |
| 49 | + create(:triage, academic_year:, team:, programme:, patient:) |
45 | 50 | end
|
46 | 51 |
|
47 | 52 | it "does not invalidate the triage" do
|
|
51 | 56 | end
|
52 | 57 |
|
53 | 58 | context "with self-consent from yesterday" do
|
54 |
| - let(:consent) { create(:consent, :self_consent, created_at: 1.day.ago) } |
| 59 | + let(:consent) do |
| 60 | + create(:consent, :self_consent, academic_year:, created_at: 1.day.ago) |
| 61 | + end |
| 62 | + |
| 63 | + before { create(:patient_vaccination_status, patient:, programme:) } |
55 | 64 |
|
56 | 65 | it "invalidates the consent" do
|
57 | 66 | expect { perform_now }.to change { consent.reload.invalidated? }.from(
|
|
63 | 72 | let(:triage) do
|
64 | 73 | create(
|
65 | 74 | :triage,
|
| 75 | + academic_year:, |
66 | 76 | created_at: 1.day.ago,
|
67 |
| - team: consent.team, |
68 |
| - programme: consent.programme, |
69 |
| - patient: consent.patient |
| 77 | + team:, |
| 78 | + programme:, |
| 79 | + patient: |
70 | 80 | )
|
71 | 81 | end
|
72 | 82 |
|
|
76 | 86 | ).to(true)
|
77 | 87 | end
|
78 | 88 | end
|
| 89 | + |
| 90 | + context "if the patient was vaccinated" do |
| 91 | + before do |
| 92 | + create( |
| 93 | + :vaccination_record, |
| 94 | + team:, |
| 95 | + programme:, |
| 96 | + patient:, |
| 97 | + created_at: 1.day.ago |
| 98 | + ) |
| 99 | + |
| 100 | + patient.vaccination_statuses.update_all(status: :vaccinated) |
| 101 | + end |
| 102 | + |
| 103 | + it "does not invalidate the consent" do |
| 104 | + expect { perform_now }.not_to(change { consent.reload.invalidated? }) |
| 105 | + end |
| 106 | + |
| 107 | + context "with triage" do |
| 108 | + let(:triage) do |
| 109 | + create( |
| 110 | + :triage, |
| 111 | + academic_year:, |
| 112 | + created_at: 1.day.ago, |
| 113 | + team:, |
| 114 | + programme:, |
| 115 | + patient: |
| 116 | + ) |
| 117 | + end |
| 118 | + |
| 119 | + it "does not invalidate the triage" do |
| 120 | + expect { perform_now }.not_to(change { triage.reload.invalidated? }) |
| 121 | + end |
| 122 | + end |
| 123 | + end |
79 | 124 | end
|
80 | 125 |
|
81 | 126 | context "with self-consent from today" do
|
82 |
| - let(:consent) { create(:consent, :self_consent) } |
| 127 | + let(:consent) { create(:consent, :self_consent, academic_year:) } |
| 128 | + |
| 129 | + before { create(:patient_vaccination_status, patient:, programme:) } |
83 | 130 |
|
84 | 131 | it "does not invalidate the consent" do
|
85 | 132 | expect { perform_now }.not_to(change { consent.reload.invalidated? })
|
86 | 133 | end
|
87 | 134 |
|
88 | 135 | context "with triage" do
|
89 | 136 | let(:triage) do
|
90 |
| - create( |
91 |
| - :triage, |
92 |
| - team: consent.team, |
93 |
| - programme: consent.programme, |
94 |
| - patient: consent.patient |
95 |
| - ) |
| 137 | + create(:triage, academic_year:, team:, programme:, patient:) |
96 | 138 | end
|
97 | 139 |
|
98 | 140 | it "does not invalidate the triage" do
|
|
114 | 156 | :consent,
|
115 | 157 | :self_consent,
|
116 | 158 | patient:,
|
| 159 | + academic_year:, |
117 | 160 | created_at: 1.day.ago,
|
118 | 161 | programme: self_programme,
|
119 | 162 | team:
|
|
123 | 166 | create(
|
124 | 167 | :consent,
|
125 | 168 | patient:,
|
| 169 | + academic_year:, |
126 | 170 | created_at: 1.day.ago,
|
127 | 171 | programme: parent_programme,
|
128 | 172 | team:
|
129 | 173 | )
|
130 | 174 | end
|
131 | 175 |
|
| 176 | + before do |
| 177 | + create(:patient_vaccination_status, patient:, programme: self_programme) |
| 178 | + create(:patient_vaccination_status, patient:, programme: parent_programme) |
| 179 | + end |
| 180 | + |
132 | 181 | it "does not invalidate the parent consent" do
|
133 | 182 | expect { perform_now }.not_to(
|
134 | 183 | change { parent_consent.reload.invalidated? }
|
|
0 commit comments