@@ -3,110 +3,105 @@ import { API_BASE_URL } from '../../src/constants'
33import forms from '../../src/forms'
44
55beforeEach ( ( ) => {
6- fetch . resetMocks ( )
7- fetch . mockResponse ( JSON . stringify ( { } ) )
6+ axios . reset ( )
7+ axios . onAny ( ) . reply ( 200 )
88} )
99
1010const http = clientConstructor ( {
1111 token : '123'
1212} )
1313const formsRequest = forms ( http )
1414
15- test ( 'get all forms has the correct method and path' , ( ) => {
16- formsRequest . list ( )
17-
18- const url = fetch . mock . calls [ 0 ] [ 0 ] . split ( '?' )
19- expect ( url [ 0 ] ) . toBe ( `${ API_BASE_URL } /forms` )
20- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'get' )
15+ test ( 'get all forms has the correct method and path' , async ( ) => {
16+ await formsRequest . list ( )
17+ expect ( axios . history . get [ 0 ] . url ) . toBe ( `${ API_BASE_URL } /forms` )
18+ expect ( axios . history . get [ 0 ] . method ) . toBe ( 'get' )
2119} )
2220
23- test ( 'paramters are sent correctly' , ( ) => {
24- formsRequest . list ( {
21+ test ( 'paramters are sent correctly' , async ( ) => {
22+ await formsRequest . list ( {
2523 page : 2 ,
2624 pageSize : 10 ,
2725 search : 'hola' ,
2826 workspaceId : 'abc'
2927 } )
30- const url = fetch . mock . calls [ 0 ] [ 0 ] . split ( '?' )
28+ const url = axios . history . get [ 0 ] . url . split ( '?' )
3129 const params = new URLSearchParams ( url [ 1 ] )
3230 expect ( params . get ( 'page' ) ) . toBe ( '2' )
33- expect ( params . get ( 'page ' ) ) . toBe ( '2 ' )
34- expect ( params . get ( 'page ' ) ) . toBe ( '2 ' )
35- expect ( params . get ( 'page ' ) ) . toBe ( '2 ' )
31+ expect ( params . get ( 'page_size ' ) ) . toBe ( '10 ' )
32+ expect ( params . get ( 'search ' ) ) . toBe ( 'hola ' )
33+ expect ( params . get ( 'workspace_id ' ) ) . toBe ( 'abc ' )
3634} )
3735
38- test ( 'getForm sends the correct UID' , ( ) => {
39- formsRequest . get ( { uid : 'abc123' } )
40- expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toBe ( `${ API_BASE_URL } /forms/abc123` )
36+ test ( 'getForm sends the correct UID' , async ( ) => {
37+ await formsRequest . get ( { uid : 'abc123' } )
38+ expect ( axios . history . get [ 0 ] . url ) . toBe ( `${ API_BASE_URL } /forms/abc123` )
4139} )
4240
43- test ( 'getForm sets get method' , ( ) => {
44- formsRequest . get ( { uid : 'abc123' } )
45- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'get' )
41+ test ( 'getForm sets get method' , async ( ) => {
42+ await formsRequest . get ( { uid : 'abc123' } )
43+ expect ( axios . history . get [ 0 ] . method ) . toBe ( 'get' )
4644} )
4745
48- test ( 'updateForm sends the correct UID and data' , ( ) => {
49- formsRequest . update ( {
46+ test ( 'updateForm sends the correct UID and data' , async ( ) => {
47+ await formsRequest . update ( {
5048 uid : 'abc123' ,
5149 data : {
5250 title : 'hola'
5351 }
5452 } )
55- const bodyParsed = JSON . parse ( fetch . mock . calls [ 0 ] [ 1 ] . body )
56- expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toBe ( `${ API_BASE_URL } /forms/abc123` )
53+ const bodyParsed = JSON . parse ( axios . history . patch [ 0 ] . data )
54+ expect ( axios . history . patch [ 0 ] . url ) . toBe ( `${ API_BASE_URL } /forms/abc123` )
5755 expect ( bodyParsed . title ) . toBe ( 'hola' )
5856} )
5957
60- test ( 'updateForm sets patch method in request by default' , ( ) => {
61- formsRequest . update ( {
58+ test ( 'updateForm sets patch method in request by default' , async ( ) => {
59+ await formsRequest . update ( {
6260 uid : 'abc123' ,
6361 data : {
6462 title : 'hola'
6563 }
6664 } )
67- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'patch' )
65+ expect ( axios . history . patch [ 0 ] . method ) . toBe ( 'patch' )
6866} )
6967
70- test ( 'updateForm sets put method in request when override option is set' , ( ) => {
71- formsRequest . update ( {
68+ test ( 'updateForm sets put method in request when override option is set' , async ( ) => {
69+ await formsRequest . update ( {
7270 uid : 'abc123' ,
7371 data : {
7472 title : 'hola'
7573 } ,
7674 override : true
7775 } )
78-
79- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'put' )
76+ expect ( axios . history . put [ 0 ] . method ) . toBe ( 'put' )
8077} )
8178
82- test ( 'deleteForm removes the correct uid form ' , ( ) => {
83- formsRequest . delete ( {
79+ test ( 'deleteForm removes the correct uid form ' , async ( ) => {
80+ await formsRequest . delete ( {
8481 uid : 'abc123'
8582 } )
86-
87- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'delete' )
88- expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toBe ( `${ API_BASE_URL } /forms/abc123` )
83+ expect ( axios . history . delete [ 0 ] . method ) . toBe ( 'delete' )
84+ expect ( axios . history . delete [ 0 ] . url ) . toBe ( `${ API_BASE_URL } /forms/abc123` )
8985} )
9086
91- test ( 'create form has the correct path and method ' , ( ) => {
92- formsRequest . create ( { } )
93-
94- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'post' )
95- expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toBe ( `${ API_BASE_URL } /forms` )
87+ test ( 'create form has the correct path and method ' , async ( ) => {
88+ await formsRequest . create ( { } )
89+ expect ( axios . history . post [ 0 ] . method ) . toBe ( 'post' )
90+ expect ( axios . history . post [ 0 ] . url ) . toBe ( `${ API_BASE_URL } /forms` )
9691} )
9792
98- test ( 'get messages has the correct path and method ' , ( ) => {
99- formsRequest . messages . get ( { uid : 'abc123' } )
93+ test ( 'get messages has the correct path and method ' , async ( ) => {
94+ await formsRequest . messages . get ( { uid : 'abc123' } )
10095
101- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'get' )
102- expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toBe ( `${ API_BASE_URL } /forms/abc123/messages` )
96+ expect ( axios . history . get [ 0 ] . method ) . toBe ( 'get' )
97+ expect ( axios . history . get [ 0 ] . url ) . toBe ( `${ API_BASE_URL } /forms/abc123/messages` )
10398} )
10499
105- test ( 'update messages has the correct path and method ' , ( ) => {
106- formsRequest . messages . update ( {
100+ test ( 'update messages has the correct path and method ' , async ( ) => {
101+ await formsRequest . messages . update ( {
107102 uid : 'abc123'
108103 } )
109104
110- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'put' )
111- expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toBe ( `${ API_BASE_URL } /forms/abc123/messages` )
105+ expect ( axios . history . put [ 0 ] . method ) . toBe ( 'put' )
106+ expect ( axios . history . put [ 0 ] . url ) . toBe ( `${ API_BASE_URL } /forms/abc123/messages` )
112107} )
0 commit comments