forked from SmartDropLabs/smartdrop-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagination.test.js
More file actions
52 lines (29 loc) · 793 Bytes
/
Copy pathpagination.test.js
File metadata and controls
52 lines (29 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { parsePagination } = require('../src/utils/paginate');
describe('parsePagination', () => {
test('page=0 should clamp to 1', () => {
const result = parsePagination({
page:'0'
});
expect(result.page).toBe(1);
});
test('limit=0 should use default limit', () => {
const result = parsePagination({
limit:'0'
});
expect(result.limit).toBe(20);
});
test('limit above max should clamp to 100', () => {
const result = parsePagination({
limit:'9999'
});
expect(result.limit).toBe(100);
});
test('non integer values should use defaults', () => {
const result = parsePagination({
page:'abc',
limit:'hello'
});
expect(result.page).toBe(1);
expect(result.limit).toBe(20);
});
});