Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #72 add endpoint for verifying bceid #75

Merged
merged 8 commits into from
Feb 21, 2024
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, 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', () => {
ianliuwk1019 marked this conversation as resolved.
Show resolved Hide resolved
MCatherine1994 marked this conversation as resolved.
Show resolved Hide resolved
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 IDIRUserResponse).found).toBe(false);
expect((result as IDIRUserResponse).userId).toBe(TEST_BUSINESS_BCEID_USERID_NON_EXIST);
expect((result as IDIRUserResponse).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 IDIRUserResponse).found).toBe(true);
expect((result as IDIRUserResponse).userId).toBe(TEST_BUSINESS_BCEID_USERID);
expect((result as IDIRUserResponse).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;
MCatherine1994 marked this conversation as resolved.
Show resolved Hide resolved

@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