From f6aed9c0ff8917f8788921fef53e85db3ce5556a Mon Sep 17 00:00:00 2001 From: muntaxir4 Date: Sat, 27 Jul 2024 16:31:34 +0530 Subject: [PATCH 1/7] Create common paginate method with unit tests --- apps/api/src/common/paginate.spec.ts | 93 ++++++++++++++++++++++++++++ apps/api/src/common/paginate.ts | 75 ++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 apps/api/src/common/paginate.spec.ts create mode 100644 apps/api/src/common/paginate.ts diff --git a/apps/api/src/common/paginate.spec.ts b/apps/api/src/common/paginate.spec.ts new file mode 100644 index 00000000..6269f9e2 --- /dev/null +++ b/apps/api/src/common/paginate.spec.ts @@ -0,0 +1,93 @@ +import { paginate } from './paginate' + +describe('paginate', () => { + it('should paginate without default query', () => { + const totalCount = 100 + const relativeUrl = '/items' + const query = { page: 2, limit: 10 } + + const result = paginate(totalCount, relativeUrl, query) + + expect(result).toBeDefined() + expect(result).toEqual( + expect.objectContaining({ + page: 2, + perPage: 10, + pageCount: 10, + totalCount: 100 + }) + ) + expect(result.links.self).toEqual('/items?page=2&limit=10') + expect(result.links.first).toEqual('/items?page=0&limit=10') + expect(result.links.previous).toEqual('/items?page=1&limit=10') + expect(result.links.next).toEqual('/items?page=3&limit=10') + expect(result.links.last).toEqual('/items?page=9&limit=10') + }) + + it('should paginate with default query', () => { + const totalCount = 100 + const relativeUrl = '/items' + const query = { page: 5, limit: 10 } + const defaultQuery = { pricing: 'pro', filter: 'admin' } + + const result = paginate(totalCount, relativeUrl, query, defaultQuery) + + expect(result).toBeDefined() + expect(result).toEqual( + expect.objectContaining({ + page: 5, + perPage: 10, + pageCount: 10, + totalCount: 100 + }) + ) + expect(result.links.self).toEqual( + '/items?filter=admin&pricing=pro&page=5&limit=10' + ) + expect(result.links.first).toEqual( + '/items?filter=admin&pricing=pro&page=0&limit=10' + ) + expect(result.links.previous).toEqual( + '/items?filter=admin&pricing=pro&page=4&limit=10' + ) + expect(result.links.next).toEqual( + '/items?filter=admin&pricing=pro&page=6&limit=10' + ) + expect(result.links.last).toEqual( + '/items?filter=admin&pricing=pro&page=9&limit=10' + ) + }) + + it('should paginate correctly edge cases where pervious or next is null', () => { + const totalCount = 10 + const relativeUrl = '/items' + const query = { page: 0, limit: 10 } + + const result = paginate(totalCount, relativeUrl, query) + + expect(result).toBeDefined() + expect(result).toEqual( + expect.objectContaining({ + page: 0, + perPage: 10, + pageCount: 1, + totalCount: 10 + }) + ) + expect(result.links.self).toEqual('/items?page=0&limit=10') + expect(result.links.first).toEqual('/items?page=0&limit=10') + expect(result.links.previous).toBeNull() + expect(result.links.next).toBeNull() + expect(result.links.last).toEqual('/items?page=0&limit=10') + }) + + it('should not be able to paginate when limit is 0 or undefined', () => { + const totalCount = 10 + const relativeUrl = '/items' + const query = { page: 0, limit: 0 } + + expect(() => paginate(totalCount, relativeUrl, query)).toThrow( + 'Limit is required' + ) + }) +}) diff --git a/apps/api/src/common/paginate.ts b/apps/api/src/common/paginate.ts new file mode 100644 index 00000000..18a2243e --- /dev/null +++ b/apps/api/src/common/paginate.ts @@ -0,0 +1,75 @@ +export interface PaginatedMetadata { + page: number + perPage: number + pageCount: number + totalCount: number + links: { + self: string + first: string + previous: string | null + next: string | null + last: string + } +} + +interface QueryOptions { + page: number + limit: number + sort?: string + order?: string + search?: string +} + +//convert query object to query string to use in links +const getQueryString = (query: QueryOptions) => { + return Object.keys(query) + .map((key) => `${key}=${query[key]}`) + .join('&') +} + +export const paginate = ( + totalCount: number, + relativeUrl: string, + query: QueryOptions, + defaultQuery?: Record +) => { + //query.limit cannot be 0 or undefined + if (!query.limit) throw new Error('Limit is required') + let defaultQueryStr = '' + if (defaultQuery) { + //sorting entries to make sure the order is consistent and predictable during tests + const sortedEntries = Object.entries(defaultQuery).sort(([keyA], [keyB]) => + keyA.localeCompare(keyB) + ) + //ignore keys with undefined values. Undefined values may occur when qury params are optional + defaultQueryStr = sortedEntries.reduce((res, [key, value]) => { + if (value !== undefined) { + res += `${key}=${value}&` + } + return res + }, '') + } + + const metadata = {} as PaginatedMetadata + metadata.page = query.page + metadata.perPage = query.limit + metadata.pageCount = Math.ceil(totalCount / query.limit) + metadata.totalCount = totalCount + + //create links from relativeUrl , defalutQueryStr and query of type QueryOptions + metadata.links = { + self: `${relativeUrl}?${defaultQueryStr + getQueryString(query)}`, + first: `${relativeUrl}?${defaultQueryStr + getQueryString({ ...query, page: 0 })}`, + previous: + query.page === 0 + ? null + : `${relativeUrl}?${defaultQueryStr + getQueryString({ ...query, page: query.page - 1 })}`, + next: + query.page === metadata.pageCount - 1 + ? null + : `${relativeUrl}?${defaultQueryStr + getQueryString({ ...query, page: query.page + 1 })}`, + last: `${relativeUrl}?${defaultQueryStr + getQueryString({ ...query, page: metadata.pageCount - 1 })}` + } + + return metadata +} From feada559010efc951c75ee941eba4a4e5f60ec08 Mon Sep 17 00:00:00 2001 From: muntaxir4 Date: Sat, 27 Jul 2024 17:38:11 +0530 Subject: [PATCH 2/7] Add pagination metadata to Environment module --- .../service/environment.service.ts | 25 ++++++++++++++-- .../src/types/environment.types.d.ts | 13 ++++++++ packages/api-client/tests/environment.spec.ts | 30 +++++++++++++++++-- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/apps/api/src/environment/service/environment.service.ts b/apps/api/src/environment/service/environment.service.ts index 4ae10629..367f141a 100644 --- a/apps/api/src/environment/service/environment.service.ts +++ b/apps/api/src/environment/service/environment.service.ts @@ -17,6 +17,7 @@ import { UpdateEnvironment } from '../dto/update.environment/update.environment' import { PrismaService } from '../../prisma/prisma.service' import createEvent from '../../common/create-event' import { AuthorityCheckerService } from '../../common/authority-checker.service' +import { paginate } from '../../common/paginate' @Injectable() export class EnvironmentService { @@ -171,8 +172,8 @@ export class EnvironmentService { prisma: this.prisma }) - // Get the environments - return await this.prisma.environment.findMany({ + // Get the environments for the required page + const items = await this.prisma.environment.findMany({ where: { projectId, name: { @@ -195,11 +196,29 @@ export class EnvironmentService { } }, skip: page * limit, - take: limit, + take: Number(limit), orderBy: { [sort]: order } }) + // Calculate metadata for pagination + const totalCount = await this.prisma.environment.count({ + where: { + projectId, + name: { + contains: search + } + } + }) + const metadata = paginate(totalCount, `/environment/all/${projectId}`, { + page: Number(page), + limit: Number(limit), + sort, + order, + search + }) + + return { items, metadata } } async deleteEnvironment(user: User, environmentId: Environment['id']) { diff --git a/packages/api-client/src/types/environment.types.d.ts b/packages/api-client/src/types/environment.types.d.ts index 14b44839..1c48884b 100644 --- a/packages/api-client/src/types/environment.types.d.ts +++ b/packages/api-client/src/types/environment.types.d.ts @@ -67,6 +67,19 @@ export interface GetAllEnvironmentsOfProjectResponse { profilePictureUrl: string | null } }[] + metadata: { + page: number + perPage: number + pageCount: number + totalCount: number + links: { + self: string + first: string + previous: string | null + next: string | null + last: string + } + } } export interface DeleteEnvironmentRequest { diff --git a/packages/api-client/tests/environment.spec.ts b/packages/api-client/tests/environment.spec.ts index be06923f..f4395749 100644 --- a/packages/api-client/tests/environment.spec.ts +++ b/packages/api-client/tests/environment.spec.ts @@ -87,8 +87,20 @@ describe('Get Environments Tests', () => { } ) - expect(environments).toHaveLength(2) - expect(environments[0].name).toBe('Default') + expect(environments.items).toHaveLength(2) + expect(environments.items[0].name).toBe('Default') + expect(environments.metadata.totalCount).toEqual(2) + expect(environments.metadata.links.self).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(environments.metadata.links.first).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(environments.metadata.links.previous).toBeNull() + expect(environments.metadata.links.next).toBeNull() + expect(environments.metadata.links.last).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) } catch (error) { console.error(error) process.exit(1) @@ -211,7 +223,19 @@ describe('Get Environments Tests', () => { } ) - expect(environments).toHaveLength(2) + expect(environments.items).toHaveLength(2) + expect(environments.metadata.totalCount).toEqual(2) + expect(environments.metadata.links.self).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(environments.metadata.links.first).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(environments.metadata.links.previous).toBeNull() + expect(environments.metadata.links.next).toBeNull() + expect(environments.metadata.links.last).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) } catch (error) { console.error(error) process.exit(1) From 2a725e286d3d50e807a6f000b0f604cbe4c02514 Mon Sep 17 00:00:00 2001 From: muntaxir4 Date: Sat, 27 Jul 2024 23:35:22 +0530 Subject: [PATCH 3/7] extend Env Response with Page and resolve merge conflicts --- apps/cli/src/types/index.types.d.ts | 17 +++ .../src/types/environment.types.d.ts | 22 +--- packages/api-client/tests/environment.spec.ts | 108 ++++++++---------- 3 files changed, 71 insertions(+), 76 deletions(-) diff --git a/apps/cli/src/types/index.types.d.ts b/apps/cli/src/types/index.types.d.ts index 5ec40ef6..7fdb06ce 100644 --- a/apps/cli/src/types/index.types.d.ts +++ b/apps/cli/src/types/index.types.d.ts @@ -12,4 +12,21 @@ export interface ProfileConfig { } } +export interface Page { + items: T[] + metadata: { + page: number + perPage: number + pageCount: number + totalCount: number + links: { + self: string + first: string + previous: string | null + next: string | null + last: string + } + } +} + export type PrivateKeyConfig = Record diff --git a/packages/api-client/src/types/environment.types.d.ts b/packages/api-client/src/types/environment.types.d.ts index 1c48884b..ed140704 100644 --- a/packages/api-client/src/types/environment.types.d.ts +++ b/packages/api-client/src/types/environment.types.d.ts @@ -1,3 +1,5 @@ +import { Page } from '../../../../apps/cli/src/types/index.types' + export interface CreateEnvironmentRequest { name: string description?: string @@ -53,8 +55,8 @@ export interface GetAllEnvironmentsOfProjectRequest { search?: string } -export interface GetAllEnvironmentsOfProjectResponse { - items: { +export interface GetAllEnvironmentsOfProjectResponse + extends Page<{ id: string name: string description: string | null @@ -66,21 +68,7 @@ export interface GetAllEnvironmentsOfProjectResponse { email: string profilePictureUrl: string | null } - }[] - metadata: { - page: number - perPage: number - pageCount: number - totalCount: number - links: { - self: string - first: string - previous: string | null - next: string | null - last: string - } - } -} + }> {} export interface DeleteEnvironmentRequest { id: string diff --git a/packages/api-client/tests/environment.spec.ts b/packages/api-client/tests/environment.spec.ts index f4395749..25f30cb1 100644 --- a/packages/api-client/tests/environment.spec.ts +++ b/packages/api-client/tests/environment.spec.ts @@ -76,35 +76,30 @@ describe('Get Environments Tests', () => { }) it('should return a list of environments', async () => { - try { - const environments = - await EnvironmentController.getAllEnvironmentsOfProject( - { - projectId - }, - { - 'x-e2e-user-email': email - } - ) - - expect(environments.items).toHaveLength(2) - expect(environments.items[0].name).toBe('Default') - expect(environments.metadata.totalCount).toEqual(2) - expect(environments.metadata.links.self).toBe( - `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` - ) - expect(environments.metadata.links.first).toBe( - `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` - ) - expect(environments.metadata.links.previous).toBeNull() - expect(environments.metadata.links.next).toBeNull() - expect(environments.metadata.links.last).toBe( - `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + const environments = + await EnvironmentController.getAllEnvironmentsOfProject( + { + projectId + }, + { + 'x-e2e-user-email': email + } ) - } catch (error) { - console.error(error) - process.exit(1) - } + + expect(environments.items).toHaveLength(2) + expect(environments.items[0].name).toBe('Default') + expect(environments.metadata.totalCount).toEqual(2) + expect(environments.metadata.links.self).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(environments.metadata.links.first).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(environments.metadata.links.previous).toBeNull() + expect(environments.metadata.links.next).toBeNull() + expect(environments.metadata.links.last).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) }) it('should be able to fetch environment by ID', async () => { @@ -202,43 +197,38 @@ describe('Get Environments Tests', () => { } )) as any - try { - await EnvironmentController.deleteEnvironment( + await EnvironmentController.deleteEnvironment( + { + id: createEnvironmentResponse.id + }, + { + 'x-e2e-user-email': email + } + ) + + // Check if the environment is deleted + const environments = + await EnvironmentController.getAllEnvironmentsOfProject( { - id: createEnvironmentResponse.id + projectId }, { 'x-e2e-user-email': email } ) - // Check if the environment is deleted - const environments = - await EnvironmentController.getAllEnvironmentsOfProject( - { - projectId - }, - { - 'x-e2e-user-email': email - } - ) - - expect(environments.items).toHaveLength(2) - expect(environments.metadata.totalCount).toEqual(2) - expect(environments.metadata.links.self).toBe( - `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` - ) - expect(environments.metadata.links.first).toBe( - `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` - ) - expect(environments.metadata.links.previous).toBeNull() - expect(environments.metadata.links.next).toBeNull() - expect(environments.metadata.links.last).toBe( - `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` - ) - } catch (error) { - console.error(error) - process.exit(1) - } + expect(environments.items).toHaveLength(2) + expect(environments.metadata.totalCount).toEqual(2) + expect(environments.metadata.links.self).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(environments.metadata.links.first).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(environments.metadata.links.previous).toBeNull() + expect(environments.metadata.links.next).toBeNull() + expect(environments.metadata.links.last).toBe( + `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` + ) }) }) From 745f99f0eec6cc68695e95a1b1524921c9fb5060 Mon Sep 17 00:00:00 2001 From: muntaxir4 Date: Sun, 28 Jul 2024 17:30:44 +0530 Subject: [PATCH 4/7] Improve e2e test and remove number conversions --- .../src/environment/environment.e2e.spec.ts | 19 ++++++++++++++++++- .../service/environment.service.ts | 6 +++--- packages/api-client/tests/environment.spec.ts | 7 +++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/apps/api/src/environment/environment.e2e.spec.ts b/apps/api/src/environment/environment.e2e.spec.ts index 02279063..9d49bfe9 100644 --- a/apps/api/src/environment/environment.e2e.spec.ts +++ b/apps/api/src/environment/environment.e2e.spec.ts @@ -27,6 +27,7 @@ import { EventService } from '../event/service/event.service' import { EnvironmentService } from './service/environment.service' import { UserModule } from '../user/user.module' import { UserService } from '../user/service/user.service' +import { QueryTransformPipe } from '../common/query.transform.pipe' describe('Environment Controller Tests', () => { let app: NestFastifyApplication @@ -64,6 +65,8 @@ describe('Environment Controller Tests', () => { environmentService = moduleRef.get(EnvironmentService) userService = moduleRef.get(UserService) + app.useGlobalPipes(new QueryTransformPipe()) + await app.init() await app.getHttpAdapter().getInstance().ready() }) @@ -399,13 +402,27 @@ describe('Environment Controller Tests', () => { it('should be able to fetch all environments of a project', async () => { const response = await app.inject({ method: 'GET', - url: `/environment/all/${project1.id}`, + url: `/environment/all/${project1.id}?page=0&limit=10`, headers: { 'x-e2e-user-email': user1.email } }) expect(response.statusCode).toBe(200) + //check metadata + const metadata = response.json().metadata + expect(metadata.totalCount).toEqual(2) + expect(metadata.links.self).toBe( + `/environment/all/${project1.id}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(metadata.links.first).toBe( + `/environment/all/${project1.id}?page=0&limit=10&sort=name&order=asc&search=` + ) + expect(metadata.links.previous).toBeNull() + expect(metadata.links.next).toBeNull() + expect(metadata.links.last).toBe( + `/environment/all/${project1.id}?page=0&limit=10&sort=name&order=asc&search=` + ) }) it('should not be able to fetch all environments of a project that does not exist', async () => { diff --git a/apps/api/src/environment/service/environment.service.ts b/apps/api/src/environment/service/environment.service.ts index 367f141a..199ab3f9 100644 --- a/apps/api/src/environment/service/environment.service.ts +++ b/apps/api/src/environment/service/environment.service.ts @@ -196,7 +196,7 @@ export class EnvironmentService { } }, skip: page * limit, - take: Number(limit), + take: limit, orderBy: { [sort]: order } @@ -211,8 +211,8 @@ export class EnvironmentService { } }) const metadata = paginate(totalCount, `/environment/all/${projectId}`, { - page: Number(page), - limit: Number(limit), + page, + limit, sort, order, search diff --git a/packages/api-client/tests/environment.spec.ts b/packages/api-client/tests/environment.spec.ts index 25f30cb1..14676c6e 100644 --- a/packages/api-client/tests/environment.spec.ts +++ b/packages/api-client/tests/environment.spec.ts @@ -79,15 +79,18 @@ describe('Get Environments Tests', () => { const environments = await EnvironmentController.getAllEnvironmentsOfProject( { - projectId + projectId, + page: 0, + limit: 10 }, { 'x-e2e-user-email': email } ) - expect(environments.items).toHaveLength(2) expect(environments.items[0].name).toBe('Default') + + //check metadata expect(environments.metadata.totalCount).toEqual(2) expect(environments.metadata.links.self).toBe( `/environment/all/${projectId}?page=0&limit=10&sort=name&order=asc&search=` From 92db4de38ff31fa89a15079eaf96701e897e6a6c Mon Sep 17 00:00:00 2001 From: muntaxir4 Date: Mon, 29 Jul 2024 00:30:48 +0530 Subject: [PATCH 5/7] Default page number to 0 from 1 --- apps/api/src/environment/controller/environment.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/environment/controller/environment.controller.ts b/apps/api/src/environment/controller/environment.controller.ts index f0f09f52..31d5be19 100644 --- a/apps/api/src/environment/controller/environment.controller.ts +++ b/apps/api/src/environment/controller/environment.controller.ts @@ -57,7 +57,7 @@ export class EnvironmentController { async getEnvironmentsOfProject( @CurrentUser() user: User, @Param('projectId') projectId: string, - @Query('page') page: number = 1, + @Query('page') page: number = 0, @Query('limit') limit: number = 10, @Query('sort') sort: string = 'name', @Query('order') order: string = 'asc', From 6c67b15950d077f1cade05287c5ab0e7265dde64 Mon Sep 17 00:00:00 2001 From: muntaxir4 Date: Mon, 29 Jul 2024 02:39:59 +0530 Subject: [PATCH 6/7] Return empty object for paginate at few cases --- apps/api/src/common/paginate.spec.ts | 19 +++++++++++++++---- apps/api/src/common/paginate.ts | 5 +++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/api/src/common/paginate.spec.ts b/apps/api/src/common/paginate.spec.ts index 6269f9e2..f59c7f96 100644 --- a/apps/api/src/common/paginate.spec.ts +++ b/apps/api/src/common/paginate.spec.ts @@ -81,13 +81,24 @@ describe('paginate', () => { expect(result.links.last).toEqual('/items?page=0&limit=10') }) - it('should not be able to paginate when limit is 0 or undefined', () => { + it('should return empty object when page is greater than maximum page limit', () => { + const totalCount = 4 + const relativeUrl = '/items' + const query = { page: 3, limit: 2 } + + const result = paginate(totalCount, relativeUrl, query) + + expect(result).toBeDefined() + expect(result).toEqual({}) + }) + + it('should return empty object when limit is 0 or undefined', () => { const totalCount = 10 const relativeUrl = '/items' const query = { page: 0, limit: 0 } + const result = paginate(totalCount, relativeUrl, query) - expect(() => paginate(totalCount, relativeUrl, query)).toThrow( - 'Limit is required' - ) + expect(result).toBeDefined() + expect(result).toEqual({}) }) }) diff --git a/apps/api/src/common/paginate.ts b/apps/api/src/common/paginate.ts index 18a2243e..b25f43c3 100644 --- a/apps/api/src/common/paginate.ts +++ b/apps/api/src/common/paginate.ts @@ -33,8 +33,7 @@ export const paginate = ( query: QueryOptions, defaultQuery?: Record ) => { - //query.limit cannot be 0 or undefined - if (!query.limit) throw new Error('Limit is required') + if (!query.limit) return {} as PaginatedMetadata let defaultQueryStr = '' if (defaultQuery) { //sorting entries to make sure the order is consistent and predictable during tests @@ -56,6 +55,8 @@ export const paginate = ( metadata.pageCount = Math.ceil(totalCount / query.limit) metadata.totalCount = totalCount + if (query.page >= metadata.pageCount) return {} as PaginatedMetadata + //create links from relativeUrl , defalutQueryStr and query of type QueryOptions metadata.links = { self: `${relativeUrl}?${defaultQueryStr + getQueryString(query)}`, From edf3ff4a06a2ef8cbf17c7a5ddec46285c978bbc Mon Sep 17 00:00:00 2001 From: muntaxir4 Date: Mon, 29 Jul 2024 02:52:48 +0530 Subject: [PATCH 7/7] Improve descriptions test cases --- apps/api/src/common/paginate.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/src/common/paginate.spec.ts b/apps/api/src/common/paginate.spec.ts index f59c7f96..6c06b844 100644 --- a/apps/api/src/common/paginate.spec.ts +++ b/apps/api/src/common/paginate.spec.ts @@ -81,7 +81,7 @@ describe('paginate', () => { expect(result.links.last).toEqual('/items?page=0&limit=10') }) - it('should return empty object when page is greater than maximum page limit', () => { + it('should receive empty object when page is greater than maximum page limit', () => { const totalCount = 4 const relativeUrl = '/items' const query = { page: 3, limit: 2 } @@ -92,7 +92,7 @@ describe('paginate', () => { expect(result).toEqual({}) }) - it('should return empty object when limit is 0 or undefined', () => { + it('should receive empty object when limit is 0 or undefined', () => { const totalCount = 10 const relativeUrl = '/items' const query = { page: 0, limit: 0 }