Skip to content

Commit

Permalink
10339: Update assertions to avoid using mock user object as createUse…
Browse files Browse the repository at this point in the history
…rRecords removes empty strings; remove duplicate test;
  • Loading branch information
nechama-krigsman committed Aug 15, 2024
1 parent c4e4113 commit 8251203
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions web-api/src/persistence/dynamo/users/createUserRecords.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
COUNTRY_TYPES,
ROLES,
SERVICE_INDICATOR_TYPES,
} from '@shared/business/entities/EntityConstants';
import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext';
import {
caseServicesSupervisorUser,
Expand All @@ -21,13 +26,36 @@ describe('createUserRecords', () => {
userId: mockPrivatePractitionerUser.userId,
});

expect(applicationContext.getDocumentClient().put.mock.calls.length).toBe(
3,
);

expect(
applicationContext.getDocumentClient().put.mock.calls[0][0],
).toMatchObject({
Item: {
...mockPrivatePractitionerUser,
pk: `user|${mockPrivatePractitionerUser.userId}`,
sk: `user|${mockPrivatePractitionerUser.userId}`,
barNumber: 'pt1234',
contact: {
address1: '234 Main St',
address2: 'Apartment 4',
address3: 'Under the stairs',
city: 'Chicago',
country: COUNTRY_TYPES.DOMESTIC,
countryType: COUNTRY_TYPES.DOMESTIC,
phone: '+1 (555) 555-5555',
postalCode: '61234',
state: 'IL',
},
email: '[email protected]',
entityName: 'User',
name: 'Private Practitioner',
pk: `user|${privatePractitionerUser.userId}`,
practiceType: 'Private',
role: ROLES.privatePractitioner,
section: 'privatePractitioner',
serviceIndicator: SERVICE_INDICATOR_TYPES.SI_PAPER,
sk: `user|${privatePractitionerUser.userId}`,
userId: '330d4b65-620a-489d-8414-6623653ebc4f',
},
});
expect(
Expand Down Expand Up @@ -166,46 +194,28 @@ describe('createUserRecords', () => {
applicationContext.getDocumentClient().put.mock.calls[0][0],
).toMatchObject({
Item: {
...privatePractitionerUserWithoutBarNumber,
barNumber: undefined,
contact: {
address1: '234 Main St',
address2: 'Apartment 4',
address3: 'Under the stairs',
city: 'Chicago',
country: COUNTRY_TYPES.DOMESTIC,
countryType: COUNTRY_TYPES.DOMESTIC,
phone: '+1 (555) 555-5555',
postalCode: '61234',
state: 'IL',
},
email: '[email protected]',
entityName: 'User',
name: 'Private Practitioner',
pk: `user|${privatePractitionerUserWithoutBarNumber.userId}`,
practiceType: 'Private',
role: ROLES.privatePractitioner,
section: 'privatePractitioner',
serviceIndicator: SERVICE_INDICATOR_TYPES.SI_PAPER,
sk: `user|${privatePractitionerUserWithoutBarNumber.userId}`,
},
});
});

it('should persist a private practitioner user with name and barNumber mapping records', async () => {
await createUserRecords({
applicationContext,
user: mockPrivatePractitionerUser,
userId: mockPrivatePractitionerUser.userId,
});

expect(applicationContext.getDocumentClient().put.mock.calls.length).toBe(
3,
);
expect(
applicationContext.getDocumentClient().put.mock.calls[0][0],
).toMatchObject({
Item: {
...mockPrivatePractitionerUser,
pk: `user|${mockPrivatePractitionerUser.userId}`,
sk: `user|${mockPrivatePractitionerUser.userId}`,
},
});
expect(
applicationContext.getDocumentClient().put.mock.calls[1][0],
).toMatchObject({
Item: {
pk: 'privatePractitioner|PRIVATE PRACTITIONER',
sk: `user|${mockPrivatePractitionerUser.userId}`,
},
});
expect(
applicationContext.getDocumentClient().put.mock.calls[2][0],
).toMatchObject({
Item: {
pk: 'privatePractitioner|PT1234',
sk: `user|${mockPrivatePractitionerUser.userId}`,
userId: '330d4b65-620a-489d-8414-6623653ebc4f',
},
});
});
Expand Down

0 comments on commit 8251203

Please sign in to comment.