@@ -27,6 +27,36 @@ describe('Test the HTTPTransport', function () {
27
27
. then ( res => expect ( res ) . toEqual ( { text : 'Hello, world' } ) )
28
28
} )
29
29
30
+ xit ( 'should check the action function of an HTTP transport (multipart/form-data)' , function ( ) {
31
+ const url = 'http://www.example.com/'
32
+ const link = new document . Link ( url , 'get' , 'multipart/form-data' )
33
+ const transport = new transports . HTTPTransport ( testUtils . mockedFetch ( '{"text": "Hello, world"}' , 'application/json' ) )
34
+
35
+ return transport . action ( link , decoders )
36
+ . then ( res => expect ( res ) . toEqual ( { text : 'Hello, world' } ) )
37
+ } )
38
+
39
+ it ( 'should check the action function of an HTTP transport (application/x-www-form-urlencoded)' , function ( ) {
40
+ const url = 'http://www.example.com/'
41
+ const fields = [ new document . Field ( 'firstField' , true , 'form' ) , new document . Field ( 'secondField' , true , 'form' ) ]
42
+ const link = new document . Link ( url , 'post' , 'application/x-www-form-urlencoded' , fields )
43
+ const transport = new transports . HTTPTransport ( null , testUtils . echo )
44
+ const params = {
45
+ firstField : 'hello' ,
46
+ secondField : 'world'
47
+ }
48
+
49
+ return transport . action ( link , decoders , params )
50
+ . then ( res => expect ( res ) . toEqual ( {
51
+ url : 'http://www.example.com/' ,
52
+ method : 'POST' ,
53
+ headers : {
54
+ 'Content-Type' : 'application/x-www-form-urlencoded'
55
+ } ,
56
+ body : 'firstField=hello&secondField=world'
57
+ } ) )
58
+ } )
59
+
30
60
it ( 'should check the action function of an HTTP transport (network fail)' , function ( ) {
31
61
const url = 'http://www.example.com/'
32
62
const link = new document . Link ( url , 'get' )
@@ -42,7 +72,7 @@ describe('Test the HTTPTransport', function () {
42
72
it ( 'should check the action function of an HTTP transport (json) with query params' , function ( ) {
43
73
const url = 'http://www.example.com/'
44
74
const fields = [ new document . Field ( 'page' , false , 'query' ) ]
45
- const link = new document . Link ( url , 'get' , fields )
75
+ const link = new document . Link ( url , 'get' , 'application/json' , fields )
46
76
const transport = new transports . HTTPTransport ( null , testUtils . echo )
47
77
const params = {
48
78
page : 23
@@ -57,7 +87,7 @@ describe('Test the HTTPTransport', function () {
57
87
it ( 'should check the action function of an HTTP transport (json) with path params' , function ( ) {
58
88
const url = 'http://www.example.com/{user}/'
59
89
const fields = [ new document . Field ( 'user' , true , 'path' ) ]
60
- const link = new document . Link ( url , 'get' , fields )
90
+ const link = new document . Link ( url , 'get' , 'application/json' , fields )
61
91
const transport = new transports . HTTPTransport ( null , testUtils . echo )
62
92
const params = {
63
93
user : 23
@@ -107,37 +137,37 @@ describe('Test the HTTPTransport', function () {
107
137
it ( 'should check the action function of an HTTP transport (json) with post request and form parameters' , function ( ) {
108
138
const url = 'http://www.example.com/'
109
139
const fields = [ new document . Field ( 'hello' , true , 'form' ) ]
110
- const link = new document . Link ( url , 'post' , fields )
140
+ const link = new document . Link ( url , 'post' , 'application/json' , fields )
111
141
const transport = new transports . HTTPTransport ( null , testUtils . echo )
112
142
const params = {
113
143
hello : 'world'
114
144
}
115
145
116
146
return transport . action ( link , decoders , params )
117
147
. then ( ( res ) => {
118
- expect ( res ) . toEqual ( { url : 'http://www.example.com/' , method : 'POST' , headers : { 'Content-Type' : 'application/json' } , body : { hello : 'world' } } )
148
+ expect ( res ) . toEqual ( { url : 'http://www.example.com/' , method : 'POST' , headers : { 'Content-Type' : 'application/json' } , body : JSON . stringify ( { hello : 'world' } ) } )
119
149
} )
120
150
} )
121
151
122
152
it ( 'should check the action function of an HTTP transport (json) with post request and a body parameter' , function ( ) {
123
153
const url = 'http://www.example.com/'
124
154
const fields = [ new document . Field ( 'hello' , true , 'body' ) ]
125
- const link = new document . Link ( url , 'post' , fields )
155
+ const link = new document . Link ( url , 'post' , 'application/json' , fields )
126
156
const transport = new transports . HTTPTransport ( null , testUtils . echo )
127
157
const params = {
128
158
hello : 'world'
129
159
}
130
160
131
161
return transport . action ( link , decoders , params )
132
162
. then ( ( res ) => {
133
- expect ( res ) . toEqual ( { url : 'http://www.example.com/' , method : 'POST' , headers : { 'Content-Type' : 'application/json' } , body : 'world' } )
163
+ expect ( res ) . toEqual ( { url : 'http://www.example.com/' , method : 'POST' , headers : { 'Content-Type' : 'application/json' } , body : JSON . stringify ( 'world' ) } )
134
164
} )
135
165
} )
136
166
137
167
it ( 'should check the action function of an HTTP transport (json) with missing optional query params' , function ( ) {
138
168
const url = 'http://www.example.com/'
139
169
const fields = [ new document . Field ( 'page' , false , 'query' ) ]
140
- const link = new document . Link ( url , 'get' , fields )
170
+ const link = new document . Link ( url , 'get' , 'application/json' , fields )
141
171
const transport = new transports . HTTPTransport ( null , testUtils . echo )
142
172
const params = { }
143
173
@@ -150,7 +180,7 @@ describe('Test the HTTPTransport', function () {
150
180
it ( 'should check the action function of an HTTP transport (json) with missing required parameter' , function ( ) {
151
181
const url = 'http://www.example.com/{user}/'
152
182
const fields = [ new document . Field ( 'user' , true , 'path' ) ]
153
- const link = new document . Link ( url , 'get' , fields )
183
+ const link = new document . Link ( url , 'get' , 'application/json' , fields )
154
184
const transport = new transports . HTTPTransport ( null , testUtils . echo )
155
185
const params = { }
156
186
0 commit comments