-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
10553: Add unit test for "getUserByIdOnceAllUpdatesComplete";
- Loading branch information
John Cruz
committed
Dec 12, 2024
1 parent
7ed70d7
commit 4df64be
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
web-api/src/persistence/dynamo/users/getUserByIdOnceAllUpdatesComplete.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { UserRecord } from '@web-api/persistence/dynamo/dynamoTypes'; | ||
import { applicationContext } from '@shared/business/test/createTestApplicationContext'; | ||
import { getUserByIdOnceAllUpdatesComplete } from '@web-api/persistence/dynamo/users/getUserByIdOnceAllUpdatesComplete'; | ||
|
||
describe('getUserByIdOnceAllUpdatesComplete', () => { | ||
const TEST_USER_ID = 'TEST_USER_ID'; | ||
let RESOLVER: Function; | ||
|
||
beforeEach(() => { | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getUserById.mockImplementation( | ||
() => new Promise(resolve => (RESOLVER = resolve)), | ||
); | ||
}); | ||
|
||
it('should wait until the user is done updating to return the user record', async () => { | ||
let COMPLETE_FLAG = false; | ||
|
||
void getUserByIdOnceAllUpdatesComplete({ | ||
applicationContext, | ||
userId: TEST_USER_ID, | ||
}).then(userInfo => { | ||
expect(userInfo).toEqual({ isUpdatingInformation: false }); | ||
COMPLETE_FLAG = true; | ||
}); | ||
|
||
let getUserByIdCalls = | ||
applicationContext.getPersistenceGateway().getUserById.mock.calls; | ||
expect(getUserByIdCalls.length).toEqual(1); | ||
RESOLVER({ isUpdatingInformation: true } as UserRecord); | ||
await sleep(50); | ||
expect(COMPLETE_FLAG).toEqual(false); | ||
|
||
getUserByIdCalls = | ||
applicationContext.getPersistenceGateway().getUserById.mock.calls; | ||
expect(getUserByIdCalls.length).toEqual(2); | ||
RESOLVER({ isUpdatingInformation: true } as UserRecord); | ||
await sleep(50); | ||
expect(COMPLETE_FLAG).toEqual(false); | ||
|
||
getUserByIdCalls = | ||
applicationContext.getPersistenceGateway().getUserById.mock.calls; | ||
expect(getUserByIdCalls.length).toEqual(3); | ||
RESOLVER({ isUpdatingInformation: false } as UserRecord); | ||
await sleep(50); | ||
expect(COMPLETE_FLAG).toEqual(true); | ||
}); | ||
}); | ||
|
||
function sleep(timeInMilliseconds: number) { | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(null); | ||
}, timeInMilliseconds); | ||
}); | ||
} |