1
1
import { describe , expect , it } from 'vitest' ;
2
2
3
- import { getId , PotentialIds } from '~/utils' ;
3
+ import { getId , isPaginated , PotentialIds } from '~/utils' ;
4
4
5
5
describe ( 'getId()' , ( ) => {
6
6
it ( 'should return "id" property from item' , ( ) => {
@@ -27,3 +27,93 @@ describe('getId()', () => {
27
27
expect ( ( ) => getId ( item as PotentialIds ) ) . toThrow ( 'Unable to retrieve id from item' ) ;
28
28
} ) ;
29
29
} ) ;
30
+
31
+ describe ( 'isPaginated()' , ( ) => {
32
+ it ( 'should return true when total, limit, skip and data array are present' , ( ) => {
33
+ // given
34
+ const response = {
35
+ total : 100 ,
36
+ limit : 10 ,
37
+ skip : 20 ,
38
+ data : [ ] ,
39
+ } ;
40
+
41
+ // then
42
+ expect ( isPaginated < typeof response > ( response ) ) . toBe ( true ) ;
43
+ } ) ;
44
+
45
+ it ( 'should return true when total, limit and skip is "0"' , ( ) => {
46
+ // given
47
+ const response = {
48
+ total : 0 ,
49
+ limit : 0 ,
50
+ skip : 0 ,
51
+ data : [ ] ,
52
+ } ;
53
+
54
+ // then
55
+ expect ( isPaginated < typeof response > ( response ) ) . toBe ( true ) ;
56
+ } ) ;
57
+
58
+ it ( 'should return true when skip is a string' , ( ) => {
59
+ // given
60
+ const response = {
61
+ total : 100 ,
62
+ limit : 10 ,
63
+ skip : '20' ,
64
+ data : [ ] ,
65
+ } ;
66
+
67
+ // then
68
+ expect ( isPaginated < typeof response > ( response ) ) . toBe ( true ) ;
69
+ } ) ;
70
+
71
+ it ( 'should return false when total is missing' , ( ) => {
72
+ // given
73
+ const response = {
74
+ limit : 10 ,
75
+ skip : 20 ,
76
+ data : [ ] ,
77
+ } ;
78
+
79
+ // then
80
+ expect ( isPaginated < typeof response > ( response ) ) . toBe ( false ) ;
81
+ } ) ;
82
+
83
+ it ( 'should return false when limit is missing' , ( ) => {
84
+ // given
85
+ const response = {
86
+ total : 100 ,
87
+ skip : 20 ,
88
+ data : [ ] ,
89
+ } ;
90
+
91
+ // then
92
+ expect ( isPaginated < typeof response > ( response ) ) . toBe ( false ) ;
93
+ } ) ;
94
+
95
+ it ( 'should return false when skip is missing' , ( ) => {
96
+ // given
97
+ const response = {
98
+ total : 100 ,
99
+ limit : 10 ,
100
+ data : [ ] ,
101
+ } ;
102
+
103
+ // then
104
+ expect ( isPaginated < typeof response > ( response ) ) . toBe ( false ) ;
105
+ } ) ;
106
+
107
+ it ( 'should return false when data is no array' , ( ) => {
108
+ // given
109
+ const response = {
110
+ total : 100 ,
111
+ limit : 10 ,
112
+ skip : 20 ,
113
+ data : { } ,
114
+ } ;
115
+
116
+ // then
117
+ expect ( isPaginated < typeof response > ( response ) ) . toBe ( false ) ;
118
+ } ) ;
119
+ } ) ;
0 commit comments