From 4bd11237c360b05090b288180dbd93c84b074f92 Mon Sep 17 00:00:00 2001 From: paulpascal Date: Mon, 6 Jan 2025 15:02:50 +0000 Subject: [PATCH] fix: manage-hierarchy.spec.ts/getWarningInfo test --- test/lib/manage-hierarchy.spec.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/lib/manage-hierarchy.spec.ts b/test/lib/manage-hierarchy.spec.ts index f0a5fd3b..e06891f1 100644 --- a/test/lib/manage-hierarchy.spec.ts +++ b/test/lib/manage-hierarchy.spec.ts @@ -146,6 +146,22 @@ describe('lib/manage-hierarchy.ts', () => { }); describe('getWarningInfo', () => { + let clock; + + // Mocking the system clock to set the current date to June 15, 2024 (quite middle). + // This ensures consistent test behavior for relative date calculations. + // Related issue: https://github.com/medic/cht-user-management/issues/238 + beforeEach(() => { + const fixedDate = DateTime.local(2024, 6, 15).toJSDate(); + clock = sinon.useFakeTimers(fixedDate.getTime()); + }); + + afterEach(() => { + // Restore the original system clock behavior after tests. + clock.restore(); + }); + + const fakeJob: JobParams = { jobName: 'foo', jobData: { sourceId: 'abc' }}; it('below thrsholds', async () => {