Skip to content

Commit

Permalink
Merge pull request #433 from jiho-kr/feature/offset-pagination-unit-test
Browse files Browse the repository at this point in the history
feat: unit-test to fetch data with offset pagination
  • Loading branch information
jiho-kr authored Feb 2, 2024
2 parents 156268f + 634c655 commit 7c0333e
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 7c0333e

Please sign in to comment.