Testing Dates
When writing tests involving working days and scheduled event based letters, if you’re creating or updating an entity with a date property, then you need to apply the offset in the opposite order in the test to what is applied in the application itself.
This is because changing the date in the same order will produce different results:
2020-12-30 - 1 year = 2019-12-30
2019-12-30 + 18 working days = 2020-01-24
Then when we try to get back to 2020-12-30
from 2020-01-24
if we go back in the same order:
2020-01-24 + 1 year = 2021-01-24
2021-01-24 - 18 working days = 2020-12-29
So you have to use the opposite order to which the transformation was applied:
2020-01-24 - 18 working days = 2019-12-30
2019-12-30 + 1 year = 2020-12-30
Moreover, if you start off on a weekend, then the reverse transformation will end up with a different date since it can’t land on back on the weekend.
To get around this, we’ve tried the following approach:
(Starting Date) -/+ (X working days) - 1-2 working days
This should produce a date of today or a few days earlier. This is ok, since the letters have a threshold of being sent 7 days late.