|
28 | 28 | given_a_national_reporting_team_exists |
29 | 29 | and_i_upload_some_vaccination_records |
30 | 30 | and_i_view_a_patient_record |
| 31 | + and_the_cut_off_date_is_set_to_tomorrow |
31 | 32 |
|
32 | 33 | when_i_run_the_command_for_single_team |
33 | 34 |
|
|
109 | 110 | and_the_other_archive_reasons_are_deleted |
110 | 111 | and_the_other_patients_are_deleted |
111 | 112 | end |
| 113 | + |
| 114 | + it "only operates on imports created before the cut-off date" do |
| 115 | + given_a_national_reporting_team_exists |
| 116 | + and_the_national_reporting_team_has_immunisation_imports_both_before_and_after_the_cut_off_date |
| 117 | + |
| 118 | + when_i_run_the_command_for_single_team |
| 119 | + |
| 120 | + then_the_imports_before_the_cut_off_date_are_deleted |
| 121 | + and_the_vaccination_records_from_imports_before_the_cut_off_date_are_deleted |
| 122 | + and_the_imports_on_or_after_the_cut_off_date_are_not_deleted |
| 123 | + and_the_vaccination_records_from_imports_on_or_after_the_cut_off_date_are_not_deleted |
| 124 | + end |
112 | 125 | end |
113 | 126 |
|
114 | 127 | context "when resetting all national_reporting teams" do |
@@ -250,8 +263,22 @@ def and_i_view_the_patient_that_is_associated_with_both_teams |
250 | 263 | end |
251 | 264 |
|
252 | 265 | def and_the_national_reporting_team_has_immunisation_imports_with_vaccination_records |
253 | | - @import1 = create(:immunisation_import, team: @national_reporting_team) |
254 | | - @import2 = create(:immunisation_import, team: @national_reporting_team) |
| 266 | + cut_off_date = |
| 267 | + @national_reporting_team.national_reporting_cut_off_date || |
| 268 | + Time.zone.today |
| 269 | + |
| 270 | + @import1 = |
| 271 | + create( |
| 272 | + :immunisation_import, |
| 273 | + team: @national_reporting_team, |
| 274 | + created_at: cut_off_date - 2.days |
| 275 | + ) |
| 276 | + @import2 = |
| 277 | + create( |
| 278 | + :immunisation_import, |
| 279 | + team: @national_reporting_team, |
| 280 | + created_at: cut_off_date - 1.day |
| 281 | + ) |
255 | 282 |
|
256 | 283 | @vaccination_record1 = |
257 | 284 | create( |
@@ -279,7 +306,13 @@ def and_the_national_reporting_team_has_immunisation_imports_with_vaccination_re |
279 | 306 | end |
280 | 307 |
|
281 | 308 | def and_a_patient_is_associated_with_both_teams |
282 | | - @import = create(:immunisation_import, team: @national_reporting_team) |
| 309 | + cut_off_date = @national_reporting_team.national_reporting_cut_off_date |
| 310 | + @import = |
| 311 | + create( |
| 312 | + :immunisation_import, |
| 313 | + team: @national_reporting_team, |
| 314 | + created_at: cut_off_date - 1.day |
| 315 | + ) |
283 | 316 | @shared_patient = create(:patient) |
284 | 317 | @national_reporting_vaccination_record = |
285 | 318 | create( |
@@ -319,8 +352,19 @@ def given_multiple_national_reporting_teams_exist |
319 | 352 | end |
320 | 353 |
|
321 | 354 | def and_each_team_has_immunisation_imports |
322 | | - @import1 = create(:immunisation_import, team: @national_reporting_team1) |
323 | | - @import2 = create(:immunisation_import, team: @national_reporting_team2) |
| 355 | + cut_off_date = @national_reporting_team1.national_reporting_cut_off_date |
| 356 | + @import1 = |
| 357 | + create( |
| 358 | + :immunisation_import, |
| 359 | + team: @national_reporting_team1, |
| 360 | + created_at: cut_off_date - 1.day |
| 361 | + ) |
| 362 | + @import2 = |
| 363 | + create( |
| 364 | + :immunisation_import, |
| 365 | + team: @national_reporting_team2, |
| 366 | + created_at: cut_off_date - 1.day |
| 367 | + ) |
324 | 368 |
|
325 | 369 | @vaccination_record1 = |
326 | 370 | create( |
@@ -536,7 +580,83 @@ def and_the_status_updater_job_is_enqueued |
536 | 580 | ) |
537 | 581 | end |
538 | 582 |
|
| 583 | + def and_the_cut_off_date_is_set_to_tomorrow |
| 584 | + @national_reporting_team.update!( |
| 585 | + national_reporting_cut_off_date: Time.zone.tomorrow |
| 586 | + ) |
| 587 | + end |
| 588 | + |
539 | 589 | def and_the_access_log_entry_is_not_deleted |
540 | 590 | expect(AccessLogEntry.where(patient: @shared_patient)).to exist |
541 | 591 | end |
| 592 | + |
| 593 | + def and_the_national_reporting_team_has_immunisation_imports_both_before_and_after_the_cut_off_date |
| 594 | + cut_off_date = @national_reporting_team.national_reporting_cut_off_date |
| 595 | + |
| 596 | + @import_before = |
| 597 | + create( |
| 598 | + :immunisation_import, |
| 599 | + team: @national_reporting_team, |
| 600 | + created_at: cut_off_date - 1.day |
| 601 | + ) |
| 602 | + @import_on_cut_off = |
| 603 | + create( |
| 604 | + :immunisation_import, |
| 605 | + team: @national_reporting_team, |
| 606 | + created_at: cut_off_date |
| 607 | + ) |
| 608 | + @import_after = |
| 609 | + create( |
| 610 | + :immunisation_import, |
| 611 | + team: @national_reporting_team, |
| 612 | + created_at: cut_off_date + 1.day |
| 613 | + ) |
| 614 | + |
| 615 | + @vaccination_record_before = |
| 616 | + create( |
| 617 | + :vaccination_record, |
| 618 | + :sourced_from_national_reporting, |
| 619 | + immunisation_import: @import_before, |
| 620 | + team: @national_reporting_team, |
| 621 | + performed_at: cut_off_date - 2.days |
| 622 | + ) |
| 623 | + @vaccination_record_on_cut_off = |
| 624 | + create( |
| 625 | + :vaccination_record, |
| 626 | + :sourced_from_national_reporting, |
| 627 | + immunisation_import: @import_on_cut_off, |
| 628 | + team: @national_reporting_team, |
| 629 | + performed_at: cut_off_date |
| 630 | + ) |
| 631 | + @vaccination_record_after = |
| 632 | + create( |
| 633 | + :vaccination_record, |
| 634 | + :sourced_from_national_reporting, |
| 635 | + immunisation_import: @import_after, |
| 636 | + team: @national_reporting_team, |
| 637 | + performed_at: cut_off_date + 2.days |
| 638 | + ) |
| 639 | + end |
| 640 | + |
| 641 | + def then_the_imports_before_the_cut_off_date_are_deleted |
| 642 | + expect(ImmunisationImport.where(id: @import_before.id)).to be_empty |
| 643 | + end |
| 644 | + |
| 645 | + def and_the_vaccination_records_from_imports_before_the_cut_off_date_are_deleted |
| 646 | + expect( |
| 647 | + VaccinationRecord.where(id: @vaccination_record_before.id) |
| 648 | + ).to be_empty |
| 649 | + end |
| 650 | + |
| 651 | + def and_the_imports_on_or_after_the_cut_off_date_are_not_deleted |
| 652 | + expect(ImmunisationImport.where(id: @import_on_cut_off.id)).to exist |
| 653 | + expect(ImmunisationImport.where(id: @import_after.id)).to exist |
| 654 | + end |
| 655 | + |
| 656 | + def and_the_vaccination_records_from_imports_on_or_after_the_cut_off_date_are_not_deleted |
| 657 | + expect( |
| 658 | + VaccinationRecord.where(id: @vaccination_record_on_cut_off.id) |
| 659 | + ).to exist |
| 660 | + expect(VaccinationRecord.where(id: @vaccination_record_after.id)).to exist |
| 661 | + end |
542 | 662 | end |
0 commit comments