From db5f9a7f45445f2deefdc1de39599593aca3819c Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Mon, 21 Oct 2024 17:07:49 -0400 Subject: [PATCH 1/4] 10313-bug: stupidly forgot to actually use my constant in the code --- .../business/useCases/user/verifyUserPendingEmailInteractor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.ts b/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.ts index b5abb7efad1..6f9d43e2462 100644 --- a/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.ts +++ b/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.ts @@ -24,7 +24,7 @@ export const userTokenHasExpired = ( calculateDifferenceInHours( createISODateString(), tokenExpirationTimestamp, - ) > 1 + ) > TOKEN_EXPIRATION_TIME_HOURS ); }; From 4bb7f4e5d7236bd092ea3e6855255c937e95e87c Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Mon, 21 Oct 2024 17:51:45 -0400 Subject: [PATCH 2/4] 10313-bug: add test and change if to when --- .../user/verifyUserPendingEmailInteractor.test.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts b/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts index 54157094696..5312a630a83 100644 --- a/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts +++ b/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts @@ -23,21 +23,29 @@ import { validUser } from '../../../../../shared/src/test/mockUsers'; describe('Verify User Pending Email', () => { const TOKEN = '41189629-abe1-46d7-b7a4-9d3834f919cb'; const TOKEN_TIMESTAMP_VALID = createISODateString(); + const TOKEN_TIMESTAMP_ALMOST_INVALID = DateTime.now() + .setZone('utc') + .minus({ hours: TOKEN_EXPIRATION_TIME_HOURS - 1 }) + .toISO()!; + const TOKEN_TIMESTAMP_EXPIRED: string = DateTime.now() .setZone('utc') .minus({ hours: TOKEN_EXPIRATION_TIME_HOURS + 1 }) .toISO()!; describe('userTokenHasExpired', () => { - it('should return true if no token', () => { + it('should return true when no token', () => { expect(userTokenHasExpired(undefined)).toBe(true); }); - it('should return true if token is outside the expiration window', () => { + it('should return true when token is outside the expiration window', () => { expect(userTokenHasExpired(TOKEN_TIMESTAMP_EXPIRED)).toBe(true); }); - it('should return false if token is within expiration window', () => { + it('should return false when token is fresh', () => { expect(userTokenHasExpired(TOKEN_TIMESTAMP_VALID)).toBe(false); }); + it('should return false whem token is almost but not yet expired', () => { + expect(userTokenHasExpired(TOKEN_TIMESTAMP_ALMOST_INVALID)).toBe(false); + }); }); describe('verifyUserPendingEmailInteractor', () => { From d27adf82cdb31de44b067d3387a3996ea0ced569 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Tue, 22 Oct 2024 09:36:44 -0400 Subject: [PATCH 3/4] 10313-bug: update tests to use better (=stricter) boundary conditions --- .../useCases/user/verifyUserPendingEmailInteractor.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts b/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts index 5312a630a83..b93d01d2022 100644 --- a/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts +++ b/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts @@ -23,14 +23,16 @@ import { validUser } from '../../../../../shared/src/test/mockUsers'; describe('Verify User Pending Email', () => { const TOKEN = '41189629-abe1-46d7-b7a4-9d3834f919cb'; const TOKEN_TIMESTAMP_VALID = createISODateString(); + // .001 hours = 3.6 seconds. This gives us a reasonable degree of accuracy + // around expiration boundaries without creating a flaky test. const TOKEN_TIMESTAMP_ALMOST_INVALID = DateTime.now() .setZone('utc') - .minus({ hours: TOKEN_EXPIRATION_TIME_HOURS - 1 }) + .minus({ hours: TOKEN_EXPIRATION_TIME_HOURS - 0.001 }) .toISO()!; const TOKEN_TIMESTAMP_EXPIRED: string = DateTime.now() .setZone('utc') - .minus({ hours: TOKEN_EXPIRATION_TIME_HOURS + 1 }) + .minus({ hours: TOKEN_EXPIRATION_TIME_HOURS + 0.001 }) .toISO()!; describe('userTokenHasExpired', () => { From b74d7aa3aa5c8f4e93506c4293740cfeb8f2a3a3 Mon Sep 17 00:00:00 2001 From: Christopher Bisom Date: Tue, 22 Oct 2024 09:37:29 -0400 Subject: [PATCH 4/4] 10313-bug: typo --- .../useCases/user/verifyUserPendingEmailInteractor.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts b/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts index b93d01d2022..e9e30e6b206 100644 --- a/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts +++ b/web-api/src/business/useCases/user/verifyUserPendingEmailInteractor.test.ts @@ -45,7 +45,7 @@ describe('Verify User Pending Email', () => { it('should return false when token is fresh', () => { expect(userTokenHasExpired(TOKEN_TIMESTAMP_VALID)).toBe(false); }); - it('should return false whem token is almost but not yet expired', () => { + it('should return false when token is almost but not yet expired', () => { expect(userTokenHasExpired(TOKEN_TIMESTAMP_ALMOST_INVALID)).toBe(false); }); });