|
4 | 4 | let(:programme) { Programme.sample } |
5 | 5 |
|
6 | 6 | describe "#save" do |
7 | | - context "resolving a vaccination record" do |
8 | | - subject do |
9 | | - described_class.new( |
10 | | - apply_changes: "apply", |
11 | | - object: vaccination_record, |
12 | | - current_team: team |
13 | | - ).save |
14 | | - end |
| 7 | + subject(:save) { form.save } |
| 8 | + |
| 9 | + let(:form) do |
| 10 | + described_class.new(apply_changes:, object:, current_team: team) |
| 11 | + end |
15 | 12 |
|
| 13 | + context "resolving a vaccination record" do |
| 14 | + let(:apply_changes) { "apply" } |
| 15 | + let(:object) { vaccination_record } |
16 | 16 | let(:team) { create(:team, programmes: [programme]) } |
17 | 17 | let(:vaccination_record) do |
18 | 18 | create(:vaccination_record, programme:, team:) |
19 | 19 | end |
20 | 20 |
|
21 | 21 | it_behaves_like "a method that updates team cached counts" |
| 22 | + |
| 23 | + it "does not call PatientStatusUpdater" do |
| 24 | + expect(PatientStatusUpdater).not_to receive(:call) |
| 25 | + expect(save).to be(true) |
| 26 | + end |
22 | 27 | end |
23 | 28 |
|
24 | 29 | context "resolving a patient record" do |
| 30 | + let(:team) { create(:team, programmes: [programme]) } |
| 31 | + let(:patient) do |
| 32 | + create(:patient, pending_changes: { "given_name" => "Updated" }) |
| 33 | + end |
| 34 | + |
| 35 | + context "when applying pending changes" do |
| 36 | + let(:apply_changes) { "apply" } |
| 37 | + let(:object) { patient } |
| 38 | + |
| 39 | + it "calls PatientStatusUpdater" do |
| 40 | + expect(PatientStatusUpdater).to receive(:call).with(patient:) |
| 41 | + expect(save).to be(true) |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context "when discarding changes" do |
| 46 | + let(:apply_changes) { "discard" } |
| 47 | + let(:object) { patient } |
| 48 | + |
| 49 | + it "does not call PatientStatusUpdater" do |
| 50 | + expect(PatientStatusUpdater).not_to receive(:call) |
| 51 | + expect(save).to be(true) |
| 52 | + end |
| 53 | + end |
| 54 | + |
25 | 55 | context "when a patient import issue includes parent relationships" do |
26 | | - let(:team) { create(:team, programmes: [programme]) } |
27 | 56 | let(:session) { create(:session, team:, programmes: [programme]) } |
28 | 57 | let(:class_import) { create(:class_import, session:) } |
29 | 58 | let(:existing_patient) { create(:patient) } |
|
93 | 122 | expect(class_import.patients.reload).to contain_exactly(new_patient) |
94 | 123 | end |
95 | 124 |
|
| 125 | + it "calls PatientStatusUpdater with the new patient when keeping both" do |
| 126 | + form = |
| 127 | + described_class.new( |
| 128 | + apply_changes: "keep_both", |
| 129 | + object: existing_patient, |
| 130 | + current_team: team |
| 131 | + ) |
| 132 | + |
| 133 | + expect(PatientStatusUpdater).to receive(:call).with( |
| 134 | + patient: instance_of(Patient) |
| 135 | + ) |
| 136 | + expect(form.save).to be(true) |
| 137 | + end |
| 138 | + |
96 | 139 | it "keeps imported parent relationships when discarding changes" do |
97 | 140 | form = |
98 | 141 | described_class.new( |
|
0 commit comments