From 634c6552aeddd4381ab8533e178c4ab5ba59fd68 Mon Sep 17 00:00:00 2001 From: "jiho.park" Date: Mon, 29 Jan 2024 20:02:33 +0900 Subject: [PATCH] feat: unit-test offset pagination get datas --- spec/pagination/pagination.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/pagination/pagination.spec.ts b/spec/pagination/pagination.spec.ts index 0c200d9..8444add 100644 --- a/spec/pagination/pagination.spec.ts +++ b/spec/pagination/pagination.spec.ts @@ -443,5 +443,24 @@ describe('Pagination', () => { } = await request(app.getHttpServer()).get(`/${PaginationType.OFFSET}`).query({ name: 'name-1' }).expect(HttpStatus.OK); expect(metadata.total).toEqual(1); }); + + it('should be able to get all data', async () => { + const { body: firstResponseBody } = await request(app.getHttpServer()).get(`/${PaginationType.OFFSET}`).expect(HttpStatus.OK); + const { body: nextResponseBody } = await request(app.getHttpServer()) + .get(`/${PaginationType.OFFSET}`) + .query({ + nextCursor: firstResponseBody.metadata.nextCursor, + offset: firstResponseBody.metadata.offset, + }) + .expect(HttpStatus.OK); + + const entities = await service.repository.find({ order: { id: 'DESC' } }); + expect((firstResponseBody.data as Array<{ name: string }>).map(({ name }) => name)).toEqual( + entities.slice(0, 20).map(({ name }) => name), + ); + expect((nextResponseBody.data as Array<{ name: string }>).map(({ name }) => name)).toEqual( + entities.slice(20, 40).map(({ name }) => name), + ); + }); }); });