@@ -4,6 +4,8 @@ import MockAdapter from 'axios-mock-adapter'
44import PostProxy from '../core/PostPorxy'
55import type { ValidatorType } from '../core/Validator'
66import Validator from '../core/Validator'
7+ import BaseTransformer from '../core/BaseTransformer'
8+ import PaginationTransformer from '../core/PaginationTransformer'
79
810let proxy : PostProxy
911let mockAdapter
@@ -17,15 +19,47 @@ describe('BaseProxy', () => {
1719 proxy = new PostProxy ( )
1820 mockAdapter = new MockAdapter ( axios )
1921 } )
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+
2058 it ( 'will fetch all records' , async ( ) => {
2159 const items = [ { first_name : 'Chantouch' , last_name : 'Sek' } ]
2260 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 )
2963 } )
3064
3165 it ( 'will fetch all records with query params' , async ( ) => {
0 commit comments