Skip to content

Commit

Permalink
Merge pull request #70 from bcgov/dev
Browse files Browse the repository at this point in the history
Dev -> test
  • Loading branch information
hannah-macdonald1 authored Jan 21, 2025
2 parents fdae339 + adb35ba commit 6f47d81
Show file tree
Hide file tree
Showing 29 changed files with 316 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/common/constants/upstream-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const createdDateFieldName = 'Created Date';
const updatedByFieldName = 'Updated By';
const updatedByIdFieldName = 'Updated By Id';
const updatedDateFieldName = 'Updated Date';
const trustedIdirHeaderName = 'X-ICM-TrustedUsername';
const pageSizeMin = 1;
const pageSizeMax = 100;
const pageSizeDefault = 10;
Expand Down Expand Up @@ -45,6 +46,7 @@ export {
updatedByFieldName,
updatedByIdFieldName,
updatedDateFieldName,
trustedIdirHeaderName,
pageSizeMin,
pageSizeMax,
pageSizeDefault,
Expand Down
9 changes: 8 additions & 1 deletion src/common/guards/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ describe('AuthService', () => {
statusText: 'OK',
} as AxiosResponse<any, any>),
);
const result = await service.getAssignedIdirUpstream(id, recordType);
const result = await service.getAssignedIdirUpstream(
id,
recordType,
'idir',
);
expect(spy).toHaveBeenCalledTimes(1);
expect(cacheSpy).toHaveBeenCalledTimes(1);
expect(result).toEqual(testIdir);
Expand All @@ -220,6 +224,7 @@ describe('AuthService', () => {
const result = await service.getAssignedIdirUpstream(
validId,
validRecordType,
'idir',
);
expect(spy).toHaveBeenCalledTimes(1);
expect(cacheSpy).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -249,6 +254,7 @@ describe('AuthService', () => {
const idir = await service.getAssignedIdirUpstream(
validId,
RecordType.Case,
'idir',
);
expect(spy).toHaveBeenCalledTimes(1);
expect(cacheSpy).toHaveBeenCalledTimes(1);
Expand All @@ -263,6 +269,7 @@ describe('AuthService', () => {
const result = await service.getAssignedIdirUpstream(
validId,
validRecordType,
'idir',
);
expect(cacheSpy).toHaveBeenCalledTimes(1);
expect(result).toEqual(null);
Expand Down
9 changes: 7 additions & 2 deletions src/common/guards/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
import { firstValueFrom } from 'rxjs';
import { AxiosError } from 'axios';
import { TokenRefresherService } from '../../../external-api/token-refresher/token-refresher.service';
import { idirUsernameHeaderField } from '../../../common/constants/upstream-constants';
import {
idirUsernameHeaderField,
trustedIdirHeaderName,
} from '../../../common/constants/upstream-constants';

@Injectable()
export class AuthService {
Expand Down Expand Up @@ -59,7 +62,7 @@ export class AuthService {

if (upstreamResult === undefined) {
this.logger.log(`Cache not hit, going upstream...`);
upstreamResult = await this.getAssignedIdirUpstream(id, recordType);
upstreamResult = await this.getAssignedIdirUpstream(id, recordType, idir);
if (upstreamResult !== null) {
await this.cacheManager.set(key, upstreamResult, this.cacheTime);
}
Expand Down Expand Up @@ -87,6 +90,7 @@ export class AuthService {
async getAssignedIdirUpstream(
id: string,
recordType: RecordType,
idir: string,
): Promise<string | null> {
let workspace;
const params = {
Expand All @@ -104,6 +108,7 @@ export class AuthService {
const headers = {
Accept: CONTENT_TYPE,
'Accept-Encoding': '*',
[trustedIdirHeaderName]: idir,
};
const url =
this.baseUrl +
Expand Down
22 changes: 18 additions & 4 deletions src/controllers/cases/cases.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('CasesController', () => {
let controller: CasesController;
let casesService: CasesService;
const { res, mockClear } = getMockRes();
const req = getMockReq({ headers: { [idirUsernameHeaderField]: 'idir' } });

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand Down Expand Up @@ -120,13 +121,15 @@ describe('CasesController', () => {

const result =
await controller.getListCaseSupportNetworkInformationRecord(
req,
idPathParams,
res,
filterQueryParams,
);
expect(casesServiceSpy).toHaveBeenCalledWith(
idPathParams,
res,
'idir',
filterQueryParams,
);
expect(result).toEqual(new NestedSupportNetworkEntity(data));
Expand All @@ -152,10 +155,11 @@ describe('CasesController', () => {

const result =
await controller.getSingleCaseSupportNetworkInformationRecord(
req,
idPathParams,
res,
);
expect(casesServiceSpy).toHaveBeenCalledWith(idPathParams, res);
expect(casesServiceSpy).toHaveBeenCalledWith(idPathParams, res, 'idir');
expect(result).toEqual(new SupportNetworkEntity(data));
},
);
Expand All @@ -181,13 +185,15 @@ describe('CasesController', () => {
);

const result = await controller.getListCaseInPersonVisitRecord(
req,
idPathParams,
res,
filterQueryParams,
);
expect(casesServiceSpy).toHaveBeenCalledWith(
idPathParams,
res,
'idir',
filterQueryParams,
);
expect(result).toEqual(new NestedInPersonVisitsEntity(data));
Expand All @@ -209,10 +215,11 @@ describe('CasesController', () => {
.mockReturnValueOnce(Promise.resolve(new InPersonVisitsEntity(data)));

const result = await controller.getSingleCaseInPersonVisitRecord(
req,
idPathParams,
res,
);
expect(casesServiceSpy).toHaveBeenCalledWith(idPathParams, res);
expect(casesServiceSpy).toHaveBeenCalledWith(idPathParams, res, 'idir');
expect(result).toEqual(new InPersonVisitsEntity(data));
},
);
Expand Down Expand Up @@ -240,9 +247,9 @@ describe('CasesController', () => {
);

const result = await controller.postSingleCaseInPersonVisitRecord(
getMockReq({ headers: { [idirUsernameHeaderField]: idir } }),
body,
idPathParams,
getMockReq({ headers: { [idirUsernameHeaderField]: idir } }),
);
expect(casesServiceSpy).toHaveBeenCalledWith(body, idir, idPathParams);
expect(result).toEqual(new NestedInPersonVisitsEntity(data));
Expand Down Expand Up @@ -270,13 +277,15 @@ describe('CasesController', () => {
);

const result = await controller.getSingleCaseAttachmentRecord(
req,
idPathParams,
res,
filterQueryParams,
);
expect(caseServiceSpy).toHaveBeenCalledWith(
idPathParams,
res,
'idir',
filterQueryParams,
);
expect(result).toEqual(new NestedAttachmentsEntity(data));
Expand Down Expand Up @@ -319,13 +328,15 @@ describe('CasesController', () => {
);

const result = await controller.getSingleCaseAttachmentDetailsRecord(
req,
idPathParams,
res,
filterQueryParams,
);
expect(caseServiceSpy).toHaveBeenCalledWith(
idPathParams,
res,
'idir',
filterQueryParams,
);
expect(result).toEqual(new AttachmentDetailsEntity(data));
Expand All @@ -351,13 +362,15 @@ describe('CasesController', () => {
.mockReturnValueOnce(Promise.resolve(new NestedContactsEntity(data)));

const result = await controller.getListCaseContactRecord(
req,
idPathParams,
res,
filterQueryParams,
);
expect(caseServiceSpy).toHaveBeenCalledWith(
idPathParams,
res,
'idir',
filterQueryParams,
);
expect(result).toEqual(new NestedContactsEntity(data));
Expand All @@ -379,10 +392,11 @@ describe('CasesController', () => {
.mockReturnValueOnce(Promise.resolve(new ContactsEntity(data)));

const result = await controller.getSingleCaseContactRecord(
req,
idPathParams,
res,
);
expect(caseServiceSpy).toHaveBeenCalledWith(idPathParams, res);
expect(caseServiceSpy).toHaveBeenCalledWith(idPathParams, res, 'idir');
expect(result).toEqual(new ContactsEntity(data));
},
);
Expand Down
34 changes: 30 additions & 4 deletions src/controllers/cases/cases.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class CasesController {
},
})
async getListCaseSupportNetworkInformationRecord(
@Req() req: Request,
@Param(
new ValidationPipe({
transform: true,
Expand All @@ -155,6 +156,7 @@ export class CasesController {
return await this.casesService.getListCaseSupportNetworkInformationRecord(
id,
res,
req.headers[idirUsernameHeaderField] as string,
filter,
);
}
Expand All @@ -181,6 +183,7 @@ export class CasesController {
},
})
async getSingleCaseSupportNetworkInformationRecord(
@Req() req: Request,
@Param(
new ValidationPipe({
transform: true,
Expand All @@ -194,6 +197,7 @@ export class CasesController {
return await this.casesService.getSingleCaseSupportNetworkInformationRecord(
id,
res,
req.headers[idirUsernameHeaderField] as string,
);
}

Expand Down Expand Up @@ -225,6 +229,7 @@ export class CasesController {
},
})
async getListCaseInPersonVisitRecord(
@Req() req: Request,
@Param(
new ValidationPipe({
transform: true,
Expand All @@ -247,6 +252,7 @@ export class CasesController {
return await this.casesService.getListCaseInPersonVisitRecord(
id,
res,
req.headers[idirUsernameHeaderField] as string,
filter,
);
}
Expand All @@ -273,6 +279,7 @@ export class CasesController {
},
})
async getSingleCaseInPersonVisitRecord(
@Req() req: Request,
@Param(
new ValidationPipe({
transform: true,
Expand All @@ -283,7 +290,11 @@ export class CasesController {
id: VisitIdPathParams,
@Res({ passthrough: true }) res: Response,
): Promise<InPersonVisitsEntity> {
return await this.casesService.getSingleCaseInPersonVisitRecord(id, res);
return await this.casesService.getSingleCaseInPersonVisitRecord(
id,
res,
req.headers[idirUsernameHeaderField] as string,
);
}

@UseInterceptors(ClassSerializerInterceptor)
Expand All @@ -304,6 +315,7 @@ export class CasesController {
},
})
async postSingleCaseInPersonVisitRecord(
@Req() req: Request,
@Body(
new ValidationPipe({
transform: true,
Expand All @@ -320,7 +332,6 @@ export class CasesController {
}),
)
id: IdPathParams,
@Req() req: Request,
): Promise<NestedInPersonVisitsEntity> {
return await this.casesService.postSingleCaseInPersonVisitRecord(
inPersonVisitDto,
Expand Down Expand Up @@ -357,6 +368,7 @@ export class CasesController {
},
})
async getSingleCaseAttachmentRecord(
@Req() req: Request,
@Param(
new ValidationPipe({
transform: true,
Expand All @@ -379,6 +391,7 @@ export class CasesController {
return await this.casesService.getSingleCaseAttachmentRecord(
id,
res,
req.headers[idirUsernameHeaderField] as string,
filter,
);
}
Expand Down Expand Up @@ -415,6 +428,7 @@ export class CasesController {
},
})
async getSingleCaseAttachmentDetailsRecord(
@Req() req: Request,
@Param(
new ValidationPipe({
transform: true,
Expand All @@ -437,6 +451,7 @@ export class CasesController {
return await this.casesService.getSingleCaseAttachmentDetailsRecord(
id,
res,
req.headers[idirUsernameHeaderField] as string,
filter,
);
}
Expand Down Expand Up @@ -469,6 +484,7 @@ export class CasesController {
},
})
async getListCaseContactRecord(
@Req() req: Request,
@Param(
new ValidationPipe({
transform: true,
Expand All @@ -488,7 +504,12 @@ export class CasesController {
)
filter?: FilterQueryParams,
): Promise<NestedContactsEntity> {
return await this.casesService.getListCaseContactRecord(id, res, filter);
return await this.casesService.getListCaseContactRecord(
id,
res,
req.headers[idirUsernameHeaderField] as string,
filter,
);
}

@UseInterceptors(ClassSerializerInterceptor)
Expand All @@ -513,6 +534,7 @@ export class CasesController {
},
})
async getSingleCaseContactRecord(
@Req() req: Request,
@Param(
new ValidationPipe({
transform: true,
Expand All @@ -523,6 +545,10 @@ export class CasesController {
id: ContactIdPathParams,
@Res({ passthrough: true }) res: Response,
): Promise<ContactsEntity> {
return await this.casesService.getSingleCaseContactRecord(id, res);
return await this.casesService.getSingleCaseContactRecord(
id,
res,
req.headers[idirUsernameHeaderField] as string,
);
}
}
Loading

0 comments on commit 6f47d81

Please sign in to comment.