-
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.
Merge pull request #5648 from flexion/10553-bug
10553: Process to update contact info fails if DAWSON is also updating other contact info at the same time
- Loading branch information
Showing
30 changed files
with
884 additions
and
34 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
shared/src/business/entities/factories/UserFactory.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,36 @@ | ||
import { Practitioner } from '@shared/business/entities/Practitioner'; | ||
import { ROLES } from '@shared/business/entities/EntityConstants'; | ||
import { User } from '@shared/business/entities/User'; | ||
import { UserFactory } from '@shared/business/entities/factories/UserFactory'; | ||
|
||
describe('UserFactory', () => { | ||
describe('getClass', () => { | ||
it('should return "Practitioner" class type if role is "privatePractitioner"', () => { | ||
const TEST_USER = { role: ROLES.privatePractitioner }; | ||
const userFactory = new UserFactory(TEST_USER); | ||
const classInstance = userFactory.getClass(); | ||
expect(classInstance).toEqual(Practitioner); | ||
}); | ||
|
||
it('should return "Practitioner" class type if role is "irsPractitioner"', () => { | ||
const TEST_USER = { role: ROLES.irsPractitioner }; | ||
const userFactory = new UserFactory(TEST_USER); | ||
const classInstance = userFactory.getClass(); | ||
expect(classInstance).toEqual(Practitioner); | ||
}); | ||
|
||
it('should return "Practitioner" class type if role is "inactivePractitioner"', () => { | ||
const TEST_USER = { role: ROLES.inactivePractitioner }; | ||
const userFactory = new UserFactory(TEST_USER); | ||
const classInstance = userFactory.getClass(); | ||
expect(classInstance).toEqual(Practitioner); | ||
}); | ||
|
||
it('should return "User" class type if role is "admin"', () => { | ||
const TEST_USER = { role: ROLES.admin }; | ||
const userFactory = new UserFactory(TEST_USER); | ||
const classInstance = userFactory.getClass(); | ||
expect(classInstance).toEqual(User); | ||
}); | ||
}); | ||
}); |
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,27 @@ | ||
import { Practitioner } from '@shared/business/entities/Practitioner'; | ||
import { ROLES, Role } from '@shared/business/entities/EntityConstants'; | ||
import { User } from '@shared/business/entities/User'; | ||
|
||
type MinimalFactoryInfo = { | ||
role: Role; | ||
}; | ||
|
||
export class UserFactory { | ||
private rawUser: MinimalFactoryInfo; | ||
|
||
constructor(rawUser: MinimalFactoryInfo) { | ||
this.rawUser = rawUser; | ||
} | ||
|
||
public getClass(): typeof User | typeof Practitioner { | ||
if ( | ||
this.rawUser.role === ROLES.privatePractitioner || | ||
this.rawUser.role === ROLES.irsPractitioner || | ||
this.rawUser.role === ROLES.inactivePractitioner | ||
) { | ||
return Practitioner; | ||
} | ||
|
||
return User; | ||
} | ||
} |
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
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
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
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
179 changes: 179 additions & 0 deletions
179
web-api/src/business/useCases/user/queueEmailUpdateAssociatedCasesWorker.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,179 @@ | ||
import { | ||
MAX_ITERATIONS, | ||
queueEmailUpdateAssociatedCasesWorker, | ||
} from '@web-api/business/useCases/user/queueEmailUpdateAssociatedCasesWorker'; | ||
import { RawUser } from '@shared/business/entities/User'; | ||
import { applicationContext } from '@shared/business/test/createTestApplicationContext'; | ||
import { mockPetitionerUser } from '@shared/test/mockAuthUsers'; | ||
import { petitionerUser } from '@shared/test/mockUsers'; | ||
import { sleep } from '@shared/tools/helpers'; | ||
|
||
describe('queueEmailUpdateAssociatedCasesWorker', () => { | ||
let TEST_USER: RawUser; | ||
let RESOLVER: Function; | ||
|
||
beforeEach(() => { | ||
TEST_USER = { | ||
...petitionerUser, | ||
isUpdatingInformation: true, | ||
}; | ||
|
||
applicationContext.getPersistenceGateway().updateUser.mockReturnValue(null); | ||
|
||
applicationContext | ||
.getUseCases() | ||
.queueUpdateAssociatedCasesWorker.mockReturnValue(null); | ||
|
||
applicationContext | ||
.getPersistenceGateway() | ||
.getCasesByEmailTotal.mockImplementation( | ||
() => | ||
new Promise(resolve => { | ||
RESOLVER = resolve; | ||
}), | ||
); | ||
|
||
applicationContext.getUtilities().sleep.mockImplementation(() => {}); | ||
}); | ||
|
||
it('should disable user flag and short circuit if there is no associated cases to user', async () => { | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getDocketNumbersByUser.mockReturnValue([]); | ||
|
||
await queueEmailUpdateAssociatedCasesWorker( | ||
applicationContext, | ||
{ user: TEST_USER }, | ||
mockPetitionerUser, | ||
); | ||
|
||
const updateUserCalls = | ||
applicationContext.getPersistenceGateway().updateUser.mock.calls; | ||
expect(updateUserCalls.length).toEqual(1); | ||
expect(updateUserCalls[0][0].user).toMatchObject({ | ||
isUpdatingInformation: false, | ||
}); | ||
|
||
const queueUpdateAssociatedCasesWorkerCalls = | ||
applicationContext.getUseCases().queueUpdateAssociatedCasesWorker.mock | ||
.calls; | ||
expect(queueUpdateAssociatedCasesWorkerCalls.length).toEqual(0); | ||
}); | ||
|
||
function assertFunctionCalls(expectedCount: number) { | ||
expect( | ||
applicationContext.getPersistenceGateway().getDocketNumbersByUser.mock | ||
.calls.length, | ||
).toEqual(expectedCount + 1); | ||
|
||
expect( | ||
applicationContext.getPersistenceGateway().getCasesByEmailTotal.mock.calls | ||
.length, | ||
).toEqual(expectedCount); | ||
} | ||
|
||
it('should call "queueUpdateAssociatedCasesWorker" with user information and wait until all expected cases to update', async () => { | ||
const TEST_DOCKER_NUMBERS = ['TEST_1', 'TEST_2', 'TEST_3', 'TEST_4']; | ||
let COMPLETE_FLAG = false; | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getDocketNumbersByUser.mockReturnValue(TEST_DOCKER_NUMBERS); | ||
|
||
void queueEmailUpdateAssociatedCasesWorker( | ||
applicationContext, | ||
{ user: TEST_USER }, | ||
mockPetitionerUser, | ||
).then(() => { | ||
const queueUpdateAssociatedCasesWorkerCalls = | ||
applicationContext.getUseCases().queueUpdateAssociatedCasesWorker.mock | ||
.calls; | ||
|
||
expect(queueUpdateAssociatedCasesWorkerCalls.length).toEqual(1); | ||
expect(queueUpdateAssociatedCasesWorkerCalls[0][1]).toEqual({ | ||
user: TEST_USER, | ||
}); | ||
expect(queueUpdateAssociatedCasesWorkerCalls[0][2]).toEqual( | ||
mockPetitionerUser, | ||
); | ||
|
||
const updateUserCalls = | ||
applicationContext.getPersistenceGateway().updateUser.mock.calls; | ||
expect(updateUserCalls.length).toEqual(1); | ||
expect(updateUserCalls[0][0].user).toMatchObject({ | ||
isUpdatingInformation: false, | ||
}); | ||
|
||
COMPLETE_FLAG = true; | ||
}); | ||
|
||
await sleep(100); | ||
assertFunctionCalls(1); | ||
RESOLVER(0); | ||
|
||
await sleep(50); | ||
assertFunctionCalls(2); | ||
RESOLVER(2); | ||
|
||
await sleep(50); | ||
assertFunctionCalls(3); | ||
RESOLVER(TEST_DOCKER_NUMBERS.length); | ||
|
||
await sleep(50); | ||
expect(COMPLETE_FLAG).toEqual(true); | ||
}); | ||
|
||
it('should call resolve the interactor when the max number of iterations is met', async () => { | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getCasesByEmailTotal.mockImplementation(() => {}); | ||
|
||
const TEST_DOCKER_NUMBERS = ['TEST_1', 'TEST_2', 'TEST_3', 'TEST_4']; | ||
let COMPLETE_FLAG = false; | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getDocketNumbersByUser.mockReturnValue(TEST_DOCKER_NUMBERS); | ||
|
||
void queueEmailUpdateAssociatedCasesWorker( | ||
applicationContext, | ||
{ user: TEST_USER }, | ||
mockPetitionerUser, | ||
).then(() => { | ||
COMPLETE_FLAG = true; | ||
}); | ||
|
||
await sleep(100); | ||
expect(COMPLETE_FLAG).toEqual(true); | ||
|
||
const getCasesByEmailTotalCalls = | ||
applicationContext.getPersistenceGateway().getCasesByEmailTotal.mock | ||
.calls; | ||
|
||
expect(getCasesByEmailTotalCalls.length).toEqual(MAX_ITERATIONS + 1); | ||
}); | ||
|
||
it('should resolve the interactor when the there is an error thrown in the check method', async () => { | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getCasesByEmailTotal.mockImplementation(() => { | ||
throw Error('TEST ERROR'); | ||
}); | ||
|
||
const TEST_DOCKER_NUMBERS = ['TEST_1', 'TEST_2', 'TEST_3', 'TEST_4']; | ||
applicationContext | ||
.getPersistenceGateway() | ||
.getDocketNumbersByUser.mockReturnValue(TEST_DOCKER_NUMBERS); | ||
|
||
await queueEmailUpdateAssociatedCasesWorker( | ||
applicationContext, | ||
{ user: TEST_USER }, | ||
mockPetitionerUser, | ||
); | ||
|
||
const updateUserCalls = | ||
applicationContext.getPersistenceGateway().updateUser.mock.calls; | ||
expect(updateUserCalls.length).toEqual(1); | ||
expect(updateUserCalls[0][0].user).toMatchObject({ | ||
isUpdatingInformation: false, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.