forked from typicode/json-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
58 lines (51 loc) · 1.35 KB
/
Copy pathutils.js
File metadata and controls
58 lines (51 loc) · 1.35 KB
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
53
54
55
56
57
58
const assert = require('assert')
const utils = require('../../src/server/utils')
describe('utils', () => {
describe('getPage', () => {
const array = [1, 2, 3, 4, 5]
const perPage = 2
test('should return first page', () => {
assert.deepEqual(utils.getPage(array, 1, perPage), {
items: [1, 2],
current: 1,
first: 1,
next: 2,
last: 3
})
})
test('should return second page', () => {
assert.deepEqual(utils.getPage(array, 2, perPage), {
items: [3, 4],
current: 2,
first: 1,
prev: 1,
next: 3,
last: 3
})
})
test('should return third page (last)', () => {
assert.deepEqual(utils.getPage(array, 3, perPage), {
items: [5],
current: 3,
first: 1,
prev: 2,
last: 3
})
})
test('should return an empty array if page is greater than the last page', () => {
assert.deepEqual(utils.getPage(array, 99, perPage), {
items: []
})
})
test('should return the array if perPage is greater than the array size', () => {
assert.deepEqual(utils.getPage(array, 1, 99), {
items: array
})
})
test('should return an empty array if the array is empty', () => {
assert.deepEqual(utils.getPage([], 1, 1), {
items: []
})
})
})
})