Skip to content

Commit

Permalink
Merge pull request #31 from bcgov/feat/pagination
Browse files Browse the repository at this point in the history
Add pagination to GET Requests
  • Loading branch information
hannah-macdonald1 authored Nov 19, 2024
2 parents be96b64 + 1900796 commit 5dfaa24
Show file tree
Hide file tree
Showing 33 changed files with 694 additions and 250 deletions.
13 changes: 12 additions & 1 deletion src/common/constants/enumerations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ enum VisitDetails {
NotPrivateCaregiver = 'Not private - Visit with caregiver',
}

export { RecordType, EntityType, RecordEntityMap, VisitDetails };
enum RecordCountNeededEnum {
True = 'true',
False = 'false',
}

export {
RecordType,
EntityType,
RecordEntityMap,
VisitDetails,
RecordCountNeededEnum,
};
8 changes: 6 additions & 2 deletions src/common/constants/parameter-constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const VIEW_MODE = 'Catalog';
const CHILD_LINKS = 'None';
const CONTENT_TYPE = 'application/json';
const PAGINATION = 'N';
const UNIFORM_RESPONSE = 'y';
const recordCountHeaderName = 'total-record-count';
const sinceParamName = 'since';

const idRegex = /[0-9\-A-Za-z]+/;
const idName = 'rowId';
Expand All @@ -15,7 +17,9 @@ export {
VIEW_MODE,
CHILD_LINKS,
CONTENT_TYPE,
PAGINATION,
UNIFORM_RESPONSE,
recordCountHeaderName,
sinceParamName,
idRegex,
idName,
casesAttachmentsFieldName,
Expand Down
16 changes: 16 additions & 0 deletions src/common/constants/swagger-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { recordCountHeaderName } from './parameter-constants';

const totalRecordCountHeadersSwagger = {
[recordCountHeaderName]: {
schema: { type: 'integer' },
description:
'Total number of records available for this query. Use StartRowNum to get more data if not all records needed are returned.',
example: 1,
},
};

const noContentResponseSwagger = {
description: 'Empty body. Returned when no records match the given criteria.',
};

export { totalRecordCountHeadersSwagger, noContentResponseSwagger };
16 changes: 16 additions & 0 deletions src/common/constants/upstream-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const upstreamDateFormat = 'MM/dd/yyyy HH:mm:ss';
const childVisitType = 'In Person Child Youth';
const childVisitIdirFieldName = 'Login Name';
const childVisitEntityIdFieldName = 'Parent Id';
const startRowNumParamName = 'StartRowNum';
const recordCountNeededParamName = 'recordcountneeded';
const pageSizeParamName = 'PageSize';
const pageSizeMin = 1;
const pageSizeMax = 100;
const pageSizeDefault = 10;
const startRowNumMin = 0;
const startRowNumDefault = 0;

export {
baseUrlEnvVarName,
Expand All @@ -20,4 +28,12 @@ export {
childVisitType,
childVisitIdirFieldName,
childVisitEntityIdFieldName,
startRowNumParamName,
recordCountNeededParamName,
pageSizeParamName,
pageSizeMin,
pageSizeMax,
pageSizeDefault,
startRowNumMin,
startRowNumDefault,
};
55 changes: 39 additions & 16 deletions src/controllers/cases/cases.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SupportNetworkEntity,
SupportNetworkSingleResponseCaseExample,
} from '../../entities/support-network.entity';
import { SinceQueryParams } from '../../dto/since-query-params.dto';
import { FilterQueryParams } from '../../dto/filter-query-params.dto';
import { IdPathParams } from '../../dto/id-path-params.dto';
import { AuthService } from '../../common/guards/auth/auth.service';
import { TokenRefresherService } from '../../external-api/token-refresher/token-refresher.service';
Expand All @@ -22,19 +22,26 @@ import {
NestedInPersonVisitsEntity,
PostInPersonVisitResponseExample,
} from '../../entities/in-person-visits.entity';
import { idName } from '../../common/constants/parameter-constants';
import {
idName,
sinceParamName,
} from '../../common/constants/parameter-constants';
import { AttachmentsService } from '../../helpers/attachments/attachments.service';
import {
AttachmentsSingleResponseCaseExample,
AttachmentsEntity,
} from '../../entities/attachments.entity';
import { VisitDetails } from '../../common/constants/enumerations';
import { getMockReq } from '@jest-mock/express';
import { idirUsernameHeaderField } from '../../common/constants/upstream-constants';
import { getMockReq, getMockRes } from '@jest-mock/express';
import {
idirUsernameHeaderField,
startRowNumParamName,
} from '../../common/constants/upstream-constants';

describe('CasesController', () => {
let controller: CasesController;
let casesService: CasesService;
const { res, mockClear } = getMockRes();

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand All @@ -57,6 +64,7 @@ describe('CasesController', () => {

controller = module.get<CasesController>(CasesController);
casesService = module.get<CasesService>(CasesService);
mockClear();
});

it('should be defined', () => {
Expand All @@ -68,23 +76,28 @@ describe('CasesController', () => {
[
SupportNetworkSingleResponseCaseExample,
{ [idName]: 'test' } as IdPathParams,
{ since: '2020-02-02' } as SinceQueryParams,
{
[sinceParamName]: '2020-02-02',
[startRowNumParamName]: 0,
} as FilterQueryParams,
],
])(
'should return single values given good input',
async (data, idPathParams, sinceQueryParams) => {
async (data, idPathParams, filterQueryParams) => {
const casesServiceSpy = jest
.spyOn(casesService, 'getSingleCaseSupportNetworkInformationRecord')
.mockReturnValueOnce(Promise.resolve(new SupportNetworkEntity(data)));

const result =
await controller.getSingleCaseSupportNetworkInformationRecord(
idPathParams,
sinceQueryParams,
res,
filterQueryParams,
);
expect(casesServiceSpy).toHaveBeenCalledWith(
idPathParams,
sinceQueryParams,
res,
filterQueryParams,
);
expect(result).toEqual(new SupportNetworkEntity(data));
},
Expand All @@ -96,22 +109,27 @@ describe('CasesController', () => {
[
InPersonVisitsSingleResponseCaseExample,
{ [idName]: 'test' } as IdPathParams,
{ since: '2020-02-02' } as SinceQueryParams,
{
[sinceParamName]: '2020-02-02',
[startRowNumParamName]: 0,
} as FilterQueryParams,
],
])(
'should return single values given good input',
async (data, idPathParams, sinceQueryParams) => {
async (data, idPathParams, filterQueryParams) => {
const casesServiceSpy = jest
.spyOn(casesService, 'getSingleCaseInPersonVisitRecord')
.mockReturnValueOnce(Promise.resolve(new InPersonVisitsEntity(data)));

const result = await controller.getSingleCaseInPersonVisitRecord(
idPathParams,
sinceQueryParams,
res,
filterQueryParams,
);
expect(casesServiceSpy).toHaveBeenCalledWith(
idPathParams,
sinceQueryParams,
res,
filterQueryParams,
);
expect(result).toEqual(new InPersonVisitsEntity(data));
},
Expand Down Expand Up @@ -155,22 +173,27 @@ describe('CasesController', () => {
[
AttachmentsSingleResponseCaseExample,
{ [idName]: 'test' } as IdPathParams,
{ since: '2020-02-02' } as SinceQueryParams,
{
[sinceParamName]: '2020-02-02',
[startRowNumParamName]: 0,
} as FilterQueryParams,
],
])(
'should return single values given good input',
async (data, idPathParams, sinceQueryParams) => {
async (data, idPathParams, filterQueryParams) => {
const caseServiceSpy = jest
.spyOn(casesService, 'getSingleCaseAttachmentRecord')
.mockReturnValueOnce(Promise.resolve(new AttachmentsEntity(data)));

const result = await controller.getSingleCaseAttachmentRecord(
idPathParams,
sinceQueryParams,
res,
filterQueryParams,
);
expect(caseServiceSpy).toHaveBeenCalledWith(
idPathParams,
sinceQueryParams,
res,
filterQueryParams,
);
expect(result).toEqual(new AttachmentsEntity(data));
},
Expand Down
Loading

0 comments on commit 5dfaa24

Please sign in to comment.