Skip to content

Commit d610b53

Browse files
Don't reset NR teams with no cutoff date
This handles a potentially problematic edge case Jira-Issue: MAV-7080
1 parent bf3d882 commit d610b53

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

app/lib/mavis_cli/teams/reset_national_reporting.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ def find_teams(workgroup)
7575
raise ArgumentError,
7676
"Team #{workgroup} is not a national reporting team"
7777
end
78+
if team.national_reporting_cut_off_date.nil?
79+
raise ArgumentError,
80+
"Team #{workgroup} does not have a national reporting cut off date set; no data to delete"
81+
end
7882

7983
[team]
8084
else
81-
Team.where(type: :national_reporting)
85+
Team
86+
.where(type: :national_reporting)
87+
.where.not(national_reporting_cut_off_date: nil)
8288
end
8389
end
8490

spec/features/cli_teams_reset_national_reporting_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@
8282
}.to raise_error(ArgumentError, /not a national reporting team/)
8383
end
8484

85+
it "raises an error when the team has no national reporting cut off date" do
86+
given_a_national_reporting_team_exists_without_a_cut_off_date
87+
expect {
88+
run_command_with_workgroup(@national_reporting_team.workgroup)
89+
}.to raise_error(
90+
ArgumentError,
91+
/does not have a national reporting cut off date set/
92+
)
93+
end
94+
8595
it "does not delete records that have been sent to the Imms API" do
8696
given_a_national_reporting_team_exists
8797
and_the_national_reporting_team_has_immunisation_imports_with_vaccination_records
@@ -141,6 +151,18 @@
141151
and_no_vaccination_records_are_deleted
142152
and_no_patients_are_deleted
143153
end
154+
155+
it "skips national_reporting teams that have no cut off date set" do
156+
given_a_national_reporting_team_exists_without_a_cut_off_date
157+
and_the_national_reporting_team_has_immunisation_imports_with_vaccination_records
158+
159+
when_i_run_the_command_for_all_teams
160+
161+
then_the_output_indicates_no_teams_found
162+
and_no_immunisation_imports_are_deleted
163+
and_no_vaccination_records_are_deleted
164+
and_no_patients_are_deleted
165+
end
144166
end
145167

146168
private
@@ -160,6 +182,18 @@ def given_a_national_reporting_team_exists
160182
alias_method :and_a_national_reporting_team_exists,
161183
:given_a_national_reporting_team_exists
162184

185+
def given_a_national_reporting_team_exists_without_a_cut_off_date
186+
@national_reporting_team =
187+
create(
188+
:team,
189+
:national_reporting,
190+
national_reporting_cut_off_date: nil,
191+
programmes: [Programme.hpv, Programme.flu],
192+
organisation: national_reporting_organisation,
193+
workgroup: "national-reporting-team"
194+
)
195+
end
196+
163197
def and_the_feature_flag_is_enabled
164198
Flipper.enable(:sync_national_reporting_to_imms_api)
165199
end

0 commit comments

Comments
 (0)