@@ -4,6 +4,8 @@ import MockAdapter from 'axios-mock-adapter'
4
4
import PostProxy from '../core/PostPorxy'
5
5
import type { ValidatorType } from '../core/Validator'
6
6
import Validator from '../core/Validator'
7
+ import BaseTransformer from '../core/BaseTransformer'
8
+ import PaginationTransformer from '../core/PaginationTransformer'
7
9
8
10
let proxy : PostProxy
9
11
let mockAdapter
@@ -17,15 +19,47 @@ describe('BaseProxy', () => {
17
19
proxy = new PostProxy ( )
18
20
mockAdapter = new MockAdapter ( axios )
19
21
} )
22
+
23
+ it ( 'it should fetch items with pagination' , async ( ) => {
24
+ const items = {
25
+ data : [ { first_name : 'Chantouch' , last_name : 'Sek' } ] ,
26
+ pagination : { count : 1 , page : 1 , perPage : 20 } ,
27
+ }
28
+ mockAdapter . onGet ( '/posts' ) . reply ( 200 , items )
29
+ const { data, pagination = { } } = await proxy . removeParameters ( ) . all ( )
30
+ const all = {
31
+ items : BaseTransformer . fetchCollection ( data ) ,
32
+ pagination : PaginationTransformer . fetch ( pagination ) ,
33
+ }
34
+ expect ( all ) . toHaveProperty ( 'pagination' )
35
+ expect ( data ) . toEqual ( all . items )
36
+ expect ( all . pagination . page ) . toEqual ( 1 )
37
+ } )
38
+
39
+ it ( 'it should fetch items with meta that has pagination' , async ( ) => {
40
+ const items = {
41
+ data : [ { first_name : 'Chantouch' , last_name : 'Sek' } ] ,
42
+ meta : {
43
+ pagination : { count : 1 , current_page : 1 , perPage : 20 } ,
44
+ include : [ ] ,
45
+ } ,
46
+ }
47
+ mockAdapter . onGet ( '/posts' ) . reply ( 200 , items )
48
+ const { data, meta = { } } = await proxy . removeParameters ( ) . all ( )
49
+ const all = {
50
+ items : BaseTransformer . fetchCollection ( data ) ,
51
+ pagination : PaginationTransformer . fetch ( meta ) ,
52
+ }
53
+ expect ( meta ) . toHaveProperty ( 'pagination' )
54
+ expect ( data . length ) . toEqual ( 1 )
55
+ expect ( all . pagination . page ) . toEqual ( 1 )
56
+ } )
57
+
20
58
it ( 'will fetch all records' , async ( ) => {
21
59
const items = [ { first_name : 'Chantouch' , last_name : 'Sek' } ]
22
60
mockAdapter . onGet ( '/posts' ) . reply ( 200 , { data : items } )
23
- try {
24
- const { data } = await proxy . removeParameters ( ) . all ( )
25
- expect ( data ) . toEqual ( items )
26
- } catch ( e ) {
27
- console . log ( 'all:' , e )
28
- }
61
+ const { data } = await proxy . removeParameters ( ) . all ( )
62
+ expect ( data ) . toEqual ( items )
29
63
} )
30
64
31
65
it ( 'will fetch all records with query params' , async ( ) => {
0 commit comments