|
18 | 18 | )
|
19 | 19 | end
|
20 | 20 |
|
| 21 | + let!(:existing_school) { create(:school, urn: "109464", team: current_team) } |
| 22 | + |
| 23 | + let!(:existing_session) do |
| 24 | + create( |
| 25 | + :session, |
| 26 | + location: existing_school, |
| 27 | + team: current_team, |
| 28 | + programmes: [hpv_programme] |
| 29 | + ) |
| 30 | + end |
| 31 | + |
| 32 | + let!(:existing_batch) do |
| 33 | + create(:batch, team: current_team, vaccine: hpv_programme.vaccines.first) |
| 34 | + end |
| 35 | + |
| 36 | + let!(:existing_vaccination_record) do |
| 37 | + create( |
| 38 | + :vaccination_record, |
| 39 | + session: existing_session, |
| 40 | + batch: existing_batch, |
| 41 | + programme: hpv_programme |
| 42 | + ) |
| 43 | + end |
| 44 | + |
21 | 45 | let(:csv_data) { <<-CSV }
|
22 | 46 | URN,SEN,ICB Shortname
|
23 | 47 | 109464,,BLMK ICB
|
|
39 | 63 |
|
40 | 64 | allow(CSV).to receive(:foreach).and_return(parsed_csv_data)
|
41 | 65 |
|
42 |
| - parsed_csv_data.each do |row| |
| 66 | + # The first school is `existing_school`. |
| 67 | + parsed_csv_data[1..].each do |row| |
43 | 68 | create(
|
44 | 69 | :school,
|
45 | 70 | urn: row.fetch("URN"),
|
|
93 | 118 | expect { current_team.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
94 | 119 | end
|
95 | 120 |
|
| 121 | + it "reassigns batches, sessions and vaccination records" do |
| 122 | + expect(existing_school.team).to eq(current_team) |
| 123 | + expect(existing_session.team).to eq(current_team) |
| 124 | + expect(existing_batch.team).to eq(current_team) |
| 125 | + expect(existing_vaccination_record.team).to eq(current_team) |
| 126 | + |
| 127 | + call |
| 128 | + new_team = |
| 129 | + organisation.teams.find_by(workgroup: "bedslutonmiltonkeynessais") |
| 130 | + |
| 131 | + expect(existing_school.reload.team).to eq(new_team) |
| 132 | + expect(existing_session.reload.team).to eq(new_team) |
| 133 | + expect(existing_batch.reload.team).to eq(new_team) |
| 134 | + expect(existing_vaccination_record.reload.team).to eq(new_team) |
| 135 | + end |
| 136 | + |
96 | 137 | context "with patients in community clinic" do
|
97 | 138 | let(:current_session) do
|
98 | 139 | current_team.generic_clinic_session(academic_year: AcademicYear.current)
|
|
0 commit comments