Skip to content

Commit b2cbc8f

Browse files
committed
feat: unit tests
1 parent b6005bb commit b2cbc8f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/utils/query.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ describe('encodePaginationTokens', () => {
3838
expect(response.previous).toEqual(bsonUrlEncoding.encode(['Test', '456']));
3939
});
4040

41+
it('encodes tokens when cursor is a plain object that lacks _id', () => {
42+
const params = {
43+
paginatedField: 'name',
44+
};
45+
46+
const response = {
47+
results: [],
48+
previous: { name: 'Alpha' }, // ⬅️ no _id
49+
hasPrevious: false,
50+
next: { name: 'Beta' }, // ⬅️ no _id
51+
hasNext: false,
52+
} as any;
53+
54+
encodePaginationTokens(params, response);
55+
56+
expect(response.previous).toEqual(bsonUrlEncoding.encode('Alpha'));
57+
expect(response.next).toEqual(bsonUrlEncoding.encode('Beta'));
58+
});
59+
60+
4161
describe('generateCursorQuery', () => {
4262
it('generates an empty cursor query when no next or previous cursor is provided', () => {
4363
const params = {

0 commit comments

Comments
 (0)