Skip to content

Commit

Permalink
feat: #72 add endpoint for verifying bceid (#75)
Browse files Browse the repository at this point in the history
* chore: fix dependabot warnings

* feat(72): added endpoint for verifying bceid, refs: #72

* feat(72): add test for verifying bceid user, but skip it for now, refs: #72

* merge: update package-lock.json to be the same as main branch, refs: #72

* fix(72): fix return type, refs: #72

* fix(72): fix type in test, refs: #72

* refactor(72): refactor the service method and add comments for clarification, refs: #72
  • Loading branch information
MCatherine1994 authored Feb 21, 2024
1 parent f6031df commit 5a7eff7
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 46 deletions.
2 changes: 1 addition & 1 deletion backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import 'dotenv/config';
import { IdimWebserviceController } from './idim-webservice.controller';
import { IdimWebserviceService } from './idim-webservice.service';
import { IDIRUserResponse } from './idim-webservice.dto';
import { IDIRUserResponse, BCEIDUserResponse, RequesterAccountTypeCode } from './idim-webservice.dto';

describe('IdimWebserviceController', () => {
let controller: IdimWebserviceController;
Expand All @@ -25,36 +25,36 @@ describe('IdimWebserviceController', () => {
describe('verifyIdirUser', () => {
const TEST_IDIR_USERID = 'CMENG';
const TEST_IDIR_USERID_NON_EXIST = 'test';
const TEST_REQUESTER_TYPE_CODE = 'Internal';
const TEST_REQUESTER_TYPE_CODE_NOT_SUPPORT = '';

it('find non existing idir user', async () => {
const result = await controller.verifyIdirUser(
TEST_IDIR_USERID_NON_EXIST,
TEST_IDIR_USERID,
TEST_REQUESTER_TYPE_CODE
RequesterAccountTypeCode.Internal
);
expect((result as IDIRUserResponse).found).toBe(false);
expect((result as IDIRUserResponse).userId).toBe(null);
expect((result as IDIRUserResponse).displayName).toBe(null);
expect((result as IDIRUserResponse).userId).toBe(TEST_IDIR_USERID_NON_EXIST);
expect((result as IDIRUserResponse).firstName).toBe(undefined);
});

it('find existing idir user', async () => {
it('IDIR find existing IDIR user', async () => {
const result = await controller.verifyIdirUser(
TEST_IDIR_USERID,
TEST_IDIR_USERID,
TEST_REQUESTER_TYPE_CODE
RequesterAccountTypeCode.Internal
);
expect((result as IDIRUserResponse).found).toBe(true);
expect((result as IDIRUserResponse).userId).toBe(TEST_IDIR_USERID);
expect((result as IDIRUserResponse).firstName).not.toBe(null);
});

it('find using non existing requester id', async () => {
await expect(
controller.verifyIdirUser(
TEST_IDIR_USERID,
TEST_IDIR_USERID_NON_EXIST,
TEST_REQUESTER_TYPE_CODE
RequesterAccountTypeCode.Internal
)
).rejects.toThrowError('Requester account cannot be found.');
});
Expand All @@ -69,4 +69,54 @@ describe('IdimWebserviceController', () => {
).rejects.toThrowError('Http Exception');
});
});

describe.skip('verifyBceidUser', () => {
const TEST_REQUESTER_IDIR_GUID = process.env.TEST_REQUESTER_IDIR_GUID;
const TEST_REQUESTER_IDIR_GUIDD_NON_EXIST = 'test-non-exists-guid';
const TEST_REQUESTER_TYPE_CODE_NOT_SUPPORT = '';
const TEST_BUSINESS_BCEID_USERID = 'LOAD-2-TEST'
const TEST_BUSINESS_BCEID_USERID_NON_EXIST = 'test-non-exists-userid'

it('find non existing business BCEID user', async () => {
const result = await controller.verifyBceidUser(
TEST_BUSINESS_BCEID_USERID_NON_EXIST,
TEST_REQUESTER_IDIR_GUID,
RequesterAccountTypeCode.Internal
);
expect((result as BCEIDUserResponse).found).toBe(false);
expect((result as BCEIDUserResponse).userId).toBe(TEST_BUSINESS_BCEID_USERID_NON_EXIST);
expect((result as BCEIDUserResponse).firstName).toBe(undefined);
});

it('find using non existing requester guid', async () => {
await expect(
controller.verifyBceidUser(
TEST_BUSINESS_BCEID_USERID,
TEST_REQUESTER_IDIR_GUIDD_NON_EXIST,
RequesterAccountTypeCode.Internal
)
).rejects.toThrowError('Requester account cannot be found.');
});

it('find without requester type code', async () => {
await expect(
controller.verifyBceidUser(
TEST_BUSINESS_BCEID_USERID,
TEST_REQUESTER_IDIR_GUID,
TEST_REQUESTER_TYPE_CODE_NOT_SUPPORT
)
).rejects.toThrowError('Http Exception');
});

it('IDIR find existing business BCEID user', async () => {
const result = await controller.verifyBceidUser(
TEST_BUSINESS_BCEID_USERID,
TEST_REQUESTER_IDIR_GUID,
RequesterAccountTypeCode.Internal
);
expect((result as BCEIDUserResponse).found).toBe(true);
expect((result as BCEIDUserResponse).userId).toBe(TEST_BUSINESS_BCEID_USERID);
expect((result as BCEIDUserResponse).firstName).not.toBe(null);
});
});
});
20 changes: 20 additions & 0 deletions backend/src/modules/idim-webservice/idim-webservice.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AuthGuard } from '../auth/auth.guard';
import { IdimWebserviceService } from './idim-webservice.service';
import {
IDIRUserResponse,
BCEIDUserResponse,
RequesterAccountTypeCode,
} from './idim-webservice.dto';

Expand Down Expand Up @@ -41,4 +42,23 @@ export class IdimWebserviceController {
requesterAccountTypeCode
);
}

@Get('bceid')
@ApiResponse({ status: HttpStatus.OK, type: BCEIDUserResponse })
@ApiQuery({
name: 'requesterAccountTypeCode',
enum: RequesterAccountTypeCode,
})
async verifyBceidUser(
@Query('userId') userId: string,
@Query('requesterUserGuid') requesterUserGuid: string,
@Query('requesterAccountTypeCode')
requesterAccountTypeCode: string
): Promise<HttpException | BCEIDUserResponse> {
return this.idimWebserviceService.verifyBceidUser(
userId,
requesterUserGuid,
requesterAccountTypeCode
);
}
}
31 changes: 30 additions & 1 deletion backend/src/modules/idim-webservice/idim-webservice.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';

export enum RequesterAccountTypeCode {
Internal = 'Internal',
Business = 'Business'
}

export class IDIRUserResponse {
Expand All @@ -12,7 +13,7 @@ export class IDIRUserResponse {
userId: string;

@ApiProperty()
displayName: string;
guid: string;

@ApiProperty()
firstName: string;
Expand All @@ -23,3 +24,31 @@ export class IDIRUserResponse {
@ApiProperty()
email: string;
}

export class BCEIDUserResponse {
@ApiProperty()
found: boolean;

@ApiProperty()
userId: string;

@ApiProperty()
guid: string;

@ApiProperty()
businessGuid: string;

@ApiProperty()
businessLegalName: string;

@ApiProperty()
firstName: string;

@ApiProperty()
lastName: string;

@ApiProperty()
email: string;
}


Loading

0 comments on commit 5a7eff7

Please sign in to comment.