Skip to content

Commit

Permalink
feat: unit-test offset pagination get datas
Browse files Browse the repository at this point in the history
  • Loading branch information
jiho-kr committed Jan 29, 2024
1 parent de0b0b4 commit 634c655
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions spec/pagination/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
});
});
});

0 comments on commit 634c655

Please sign in to comment.