|
76 | 76 | patient: patient_to_destroy |
77 | 77 | ) |
78 | 78 | end |
| 79 | + let(:patient_programme_vaccinations_search) do |
| 80 | + create( |
| 81 | + :patient_programme_vaccinations_search, |
| 82 | + patient: patient_to_destroy, |
| 83 | + programme: programme |
| 84 | + ) |
| 85 | + end |
79 | 86 | let(:pre_screening) { create(:pre_screening, patient: patient_to_destroy) } |
80 | 87 | let(:school_move) do |
81 | 88 | create(:school_move, :to_school, patient: patient_to_destroy) |
|
185 | 192 | ) |
186 | 193 | end |
187 | 194 |
|
| 195 | + it "moves patient programme vaccinations searches" do |
| 196 | + expect { call }.to change { |
| 197 | + patient_programme_vaccinations_search.reload.patient |
| 198 | + }.to(patient_to_keep) |
| 199 | + end |
| 200 | + |
188 | 201 | it "moves patient specific directions" do |
189 | 202 | expect { call }.to change { |
190 | 203 | patient_specific_direction.reload.patient |
|
377 | 390 | end |
378 | 391 | end |
379 | 392 |
|
| 393 | + describe "vaccination searches" do |
| 394 | + context "when patients have overlapping and unique programme searches" do |
| 395 | + before do |
| 396 | + create( |
| 397 | + :patient_programme_vaccinations_search, |
| 398 | + patient: patient_to_keep, |
| 399 | + programme: Programme.hpv, |
| 400 | + last_searched_at: 1.day.ago |
| 401 | + ) |
| 402 | + create( |
| 403 | + :patient_programme_vaccinations_search, |
| 404 | + patient: patient_to_destroy, |
| 405 | + programme: Programme.hpv, |
| 406 | + last_searched_at: 5.days.ago |
| 407 | + ) |
| 408 | + |
| 409 | + create( |
| 410 | + :patient_programme_vaccinations_search, |
| 411 | + patient: patient_to_destroy, |
| 412 | + programme: Programme.flu, |
| 413 | + last_searched_at: 3.days.ago |
| 414 | + ) |
| 415 | + create( |
| 416 | + :patient_programme_vaccinations_search, |
| 417 | + patient: patient_to_keep, |
| 418 | + programme: Programme.flu, |
| 419 | + last_searched_at: 1.day.ago |
| 420 | + ) |
| 421 | + |
| 422 | + create( |
| 423 | + :patient_programme_vaccinations_search, |
| 424 | + patient: patient_to_keep, |
| 425 | + programme: Programme.menacwy, |
| 426 | + last_searched_at: 2.days.ago |
| 427 | + ) |
| 428 | + |
| 429 | + create( |
| 430 | + :patient_programme_vaccinations_search, |
| 431 | + patient: patient_to_destroy, |
| 432 | + programme: Programme.td_ipv, |
| 433 | + last_searched_at: 2.days.ago |
| 434 | + ) |
| 435 | + end |
| 436 | + |
| 437 | + it "merges searches correctly" do |
| 438 | + expect { call }.to change( |
| 439 | + PatientProgrammeVaccinationsSearch, |
| 440 | + :count |
| 441 | + ).by(-2) |
| 442 | + |
| 443 | + searches = patient_to_keep.patient_programme_vaccinations_searches |
| 444 | + expect(searches.count).to eq(4) |
| 445 | + |
| 446 | + hpv_search = searches.find_by(programme_type: "hpv") |
| 447 | + expect(hpv_search.last_searched_at.to_date).to eq(1.day.ago.to_date) |
| 448 | + |
| 449 | + flu_search = searches.find_by(programme_type: "flu") |
| 450 | + expect(flu_search.last_searched_at.to_date).to eq(1.day.ago.to_date) |
| 451 | + |
| 452 | + tdipv_search = searches.find_by(programme_type: "td_ipv") |
| 453 | + expect(tdipv_search.last_searched_at.to_date).to eq( |
| 454 | + 2.days.ago.to_date |
| 455 | + ) |
| 456 | + |
| 457 | + menacwy_search = searches.find_by(programme_type: "menacwy") |
| 458 | + expect(menacwy_search.last_searched_at.to_date).to eq( |
| 459 | + 2.days.ago.to_date |
| 460 | + ) |
| 461 | + end |
| 462 | + end |
| 463 | + end |
| 464 | + |
380 | 465 | context "when the patient to destroy has a changeset" do |
381 | 466 | before do |
382 | 467 | create(:patient_changeset, :class_import, patient: patient_to_destroy) |
|
0 commit comments