1
- import FormData from '@tim-lai/isomorphic-form-data'
2
1
import fetchMock from 'fetch-mock'
2
+ import FormData from '../src/internal/form-data-monkey-patch'
3
3
import { buildRequest } from '../src/execute'
4
4
import sampleMultipartOpenApi2 from './data/sample-multipart-oas2'
5
5
import sampleMultipartOpenApi3 from './data/sample-multipart-oas3'
@@ -52,16 +52,15 @@ describe('buildRequest - openapi 2.0', () => {
52
52
test . skip ( 'should (Live) POST multipart-formdata with entry item entries' , ( ) => {
53
53
return fetch ( 'http://localhost:3300/api/v1/formdata' , { // eslint-disable-line no-undef
54
54
method : 'POST' ,
55
- body : req . body . stream , // per formdata-node docs
56
- headers : req . body . headers // per formdata-node docs
55
+ body : req . body
57
56
} )
58
57
. then ( ( res ) => {
59
58
return res . json ( )
60
59
} )
61
60
. then ( ( json ) => {
62
- expect ( json . email . length ) . toEqual ( 2 )
63
- expect ( json . email [ 0 ] ) . toEqual ( 'person1' )
64
- expect ( json . email [ 1 ] ) . toEqual ( 'person2' )
61
+ expect ( json . data . email . length ) . toEqual ( 2 )
62
+ expect ( json . data . email [ 0 ] ) . toEqual ( 'person1' )
63
+ expect ( json . data . email [ 1 ] ) . toEqual ( 'person2' )
65
64
} )
66
65
} )
67
66
@@ -84,8 +83,7 @@ describe('buildRequest - openapi 2.0', () => {
84
83
85
84
return fetch ( 'http://localhost:3300/api/v1/formdata' , { // eslint-disable-line no-undef
86
85
method : 'POST' ,
87
- body : req . body . stream , // per formdata-node docs
88
- headers : req . body . headers // per formdata-node docs
86
+ body : req . body ,
89
87
} )
90
88
. then ( ( res ) => {
91
89
return res . json ( )
@@ -94,10 +92,10 @@ describe('buildRequest - openapi 2.0', () => {
94
92
expect ( json . data . email . length ) . toEqual ( 2 )
95
93
expect ( json . data . email [ 0 ] ) . toEqual ( 'person1' )
96
94
expect ( json . data . email [ 1 ] ) . toEqual ( 'person2' )
97
- // duck typing that fetch received a formdata-node Stream instead of plain object
95
+ // duck typing that fetch received a FormData instance instead of plain object
98
96
const lastOptions = fetchMock . lastOptions ( )
99
97
expect ( lastOptions . body . readable ) . toEqual ( true )
100
- expect ( lastOptions . body . _readableState ) . toBeDefined ( )
98
+ // expect(lastOptions.body._streams ).toBeDefined()
101
99
} )
102
100
} )
103
101
} )
@@ -139,16 +137,15 @@ describe('buildRequest - openapi 3.0', () => {
139
137
test . skip ( 'should (Live) POST multipart-formdata with entry item entries' , ( ) => {
140
138
return fetch ( 'http://localhost:3300/api/v1/formdata' , { // eslint-disable-line no-undef
141
139
method : 'POST' ,
142
- body : req . body . stream , // per formdata-node docs
143
- headers : req . body . headers // per formdata-node docs
140
+ body : req . body
144
141
} )
145
142
. then ( ( res ) => {
146
143
return res . json ( )
147
144
} )
148
145
. then ( ( json ) => {
149
- expect ( json . email . length ) . toEqual ( 2 )
150
- expect ( json . email [ 0 ] ) . toEqual ( 'person1' )
151
- expect ( json . email [ 1 ] ) . toEqual ( 'person2' )
146
+ expect ( json . data . email . length ) . toEqual ( 2 )
147
+ expect ( json . data . email [ 0 ] ) . toEqual ( 'person1' )
148
+ expect ( json . data . email [ 1 ] ) . toEqual ( 'person2' )
152
149
} )
153
150
} )
154
151
@@ -171,8 +168,7 @@ describe('buildRequest - openapi 3.0', () => {
171
168
172
169
return fetch ( 'http://localhost:3300/api/v1/formdata' , { // eslint-disable-line no-undef
173
170
method : 'POST' ,
174
- body : req . body . stream , // per formdata-node docs
175
- headers : req . body . headers // per formdata-node docs
171
+ body : req . body ,
176
172
} )
177
173
. then ( ( res ) => {
178
174
return res . json ( )
@@ -181,10 +177,10 @@ describe('buildRequest - openapi 3.0', () => {
181
177
expect ( json . data . email . length ) . toEqual ( 2 )
182
178
expect ( json . data . email [ 0 ] ) . toEqual ( 'person1' )
183
179
expect ( json . data . email [ 1 ] ) . toEqual ( 'person2' )
184
- // duck typing that fetch received a formdata-node Stream instead of plain object
180
+ // duck typing that fetch received a FormData instance instead of plain object
185
181
const lastOptions = fetchMock . lastOptions ( )
186
182
expect ( lastOptions . body . readable ) . toEqual ( true )
187
- expect ( lastOptions . body . _readableState ) . toBeDefined ( )
183
+ // expect(lastOptions.body._streams ).toBeDefined()
188
184
} )
189
185
} )
190
186
} )
0 commit comments