Skip to content

Commit a8392c0

Browse files
committed
PUB-2365 - Added unit test
1 parent fa97504 commit a8392c0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/main/service/CreateAccountService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ export class CreateAccountService {
144144
];
145145
}
146146

147-
formatCreateAccountPIPayload(azureAccount): any[] {
147+
formatCreateMediaAccountPIPayload(azureAccount): any[] {
148148
return [
149149
{
150150
email: azureAccount.email,
151151
provenanceUserId: azureAccount.azureAccountId,
152-
roles: azureAccount.role,
152+
roles: 'VERIFIED',
153153
userProvenance: 'PI_AAD',
154154
},
155155
];
@@ -175,7 +175,7 @@ export class CreateAccountService {
175175
);
176176
if (azureResponse?.['CREATED_ACCOUNTS'][0]) {
177177
const response = await accountManagementRequests.createPIAccount(
178-
this.formatCreateAccountPIPayload(azureResponse['CREATED_ACCOUNTS'][0]),
178+
this.formatCreateMediaAccountPIPayload(azureResponse['CREATED_ACCOUNTS'][0]),
179179
requester
180180
);
181181
return response ? true : false;

src/test/unit/service/CreateAccountService.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const azureResponse = {
9292
CREATED_ACCOUNTS: [
9393
{
9494
email: 'email',
95-
provenanceUserId: 'azureAccountId',
95+
azureAccountId: 'azureAccountId',
9696
roles: 'role',
9797
},
9898
],
@@ -365,6 +365,20 @@ describe('Create Account Service', () => {
365365
expect(res).toEqual(true);
366366
});
367367

368+
it('check call to create media account contains VERIFIED role', async () => {
369+
createPIAccStub.resetHistory();
370+
createAzureAccountStub.withArgs(validMediaConvertedPayload, validEmail).resolves(azureResponse);
371+
createPIAccStub.resolves(true);
372+
await createAccountService.createMediaAccount(validMediaPayload, validEmail);
373+
sinon.assert.calledWithMatch(
374+
createPIAccStub,
375+
sinon.match((arg) =>
376+
arg[0].roles === 'VERIFIED'
377+
),
378+
validEmail
379+
);
380+
});
381+
368382
it('should return false if create azure account request fails', async () => {
369383
createAzureAccountStub.withArgs(validMediaConvertedPayload, validEmail).resolves(null);
370384
expect(await createAccountService.createMediaAccount(validMediaPayload, validEmail)).toEqual(false);

0 commit comments

Comments
 (0)