-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.spec.ts
63 lines (56 loc) · 1.58 KB
/
utils.spec.ts
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
59
60
61
62
63
import { it, expect, describe } from "bun:test";
import { computePagination } from "./utils.js";
import { ZodError } from "zod";
describe('computePagination', () => {
it('returns correct pagination metadata for first page', () => {
const result = computePagination(1, 10, 100);
expect(result).toEqual({
previous_page: 1,
current_page: 1,
next_page: 2,
total_pages: 10,
});
});
it('returns correct pagination metadata for last page', () => {
const result = computePagination(10, 10, 100);
expect(result).toEqual({
previous_page: 9,
current_page: 10,
next_page: 10,
total_pages: 10,
});
});
it('returns correct pagination metadata for middle page', () => {
const result = computePagination(5, 10, 100);
expect(result).toEqual({
previous_page: 4,
current_page: 5,
next_page: 6,
total_pages: 10,
});
});
it('returns correct pagination metadata when total rows is 0', () => {
const result = computePagination(1, 10, 0);
expect(result).toEqual({
previous_page: 1,
current_page: 1,
next_page: 1,
total_pages: 1,
});
});
it('returns correct pagination metadata when total rows is not provided', () => {
const result = computePagination(1, 10);
expect(result).toEqual({
previous_page: 1,
current_page: 1,
next_page: 1,
total_pages: 1,
});
});
it('throws an error when current page is less than 1', () => {
expect(() => computePagination(0, 10, 100)).toThrowError(ZodError);
});
it('throws an error when rows per page is less than 1', () => {
expect(() => computePagination(1, 0, 100)).toThrowError(ZodError);
});
});