@@ -3,110 +3,105 @@ import { API_BASE_URL } from '../../src/constants'
3
3
import forms from '../../src/forms'
4
4
5
5
beforeEach ( ( ) => {
6
- fetch . resetMocks ( )
7
- fetch . mockResponse ( JSON . stringify ( { } ) )
6
+ axios . reset ( )
7
+ axios . onAny ( ) . reply ( 200 )
8
8
} )
9
9
10
10
const http = clientConstructor ( {
11
11
token : '123'
12
12
} )
13
13
const formsRequest = forms ( http )
14
14
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' )
21
19
} )
22
20
23
- test ( 'paramters are sent correctly' , ( ) => {
24
- formsRequest . list ( {
21
+ test ( 'paramters are sent correctly' , async ( ) => {
22
+ await formsRequest . list ( {
25
23
page : 2 ,
26
24
pageSize : 10 ,
27
25
search : 'hola' ,
28
26
workspaceId : 'abc'
29
27
} )
30
- const url = fetch . mock . calls [ 0 ] [ 0 ] . split ( '?' )
28
+ const url = axios . history . get [ 0 ] . url . split ( '?' )
31
29
const params = new URLSearchParams ( url [ 1 ] )
32
30
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 ' )
36
34
} )
37
35
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` )
41
39
} )
42
40
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' )
46
44
} )
47
45
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 ( {
50
48
uid : 'abc123' ,
51
49
data : {
52
50
title : 'hola'
53
51
}
54
52
} )
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` )
57
55
expect ( bodyParsed . title ) . toBe ( 'hola' )
58
56
} )
59
57
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 ( {
62
60
uid : 'abc123' ,
63
61
data : {
64
62
title : 'hola'
65
63
}
66
64
} )
67
- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'patch' )
65
+ expect ( axios . history . patch [ 0 ] . method ) . toBe ( 'patch' )
68
66
} )
69
67
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 ( {
72
70
uid : 'abc123' ,
73
71
data : {
74
72
title : 'hola'
75
73
} ,
76
74
override : true
77
75
} )
78
-
79
- expect ( fetch . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( 'put' )
76
+ expect ( axios . history . put [ 0 ] . method ) . toBe ( 'put' )
80
77
} )
81
78
82
- test ( 'deleteForm removes the correct uid form ' , ( ) => {
83
- formsRequest . delete ( {
79
+ test ( 'deleteForm removes the correct uid form ' , async ( ) => {
80
+ await formsRequest . delete ( {
84
81
uid : 'abc123'
85
82
} )
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` )
89
85
} )
90
86
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` )
96
91
} )
97
92
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' } )
100
95
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` )
103
98
} )
104
99
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 ( {
107
102
uid : 'abc123'
108
103
} )
109
104
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` )
112
107
} )
0 commit comments