Skip to content

Commit 58ffccc

Browse files
authored
Merge pull request #5840 from nhsuk/fix-flaky-test-end-of-month-dob
Fix flaky tests caused by MMR date calculations
2 parents ecc502a + 1febc1c commit 58ffccc

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

spec/lib/status_generator/vaccination_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,16 @@
345345
:vaccination_record,
346346
patient:,
347347
programme:,
348-
performed_at: patient.date_of_birth + 1.year + 3.months
348+
performed_at:
349+
(patient.date_of_birth + 1.year + 3.months).then do
350+
# When date is at the end of the month, adding months to it
351+
# results in dates that are also at the end of the month,
352+
# which can cause test failures. For example if dob is
353+
# 2021-01-31, then 1 year + 3 months is 2022-04-30, but when
354+
# AgeConcern#age_months calculates age, the result is 14
355+
# months, triggering a false negative in our test here.
356+
it == it.end_of_month ? it + 1.day : it
357+
end
349358
)
350359
end
351360

0 commit comments

Comments
 (0)