File tree Expand file tree Collapse file tree 4 files changed +47
-5
lines changed Expand file tree Collapse file tree 4 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,36 @@ describe('public APIs', () => {
192
192
) ;
193
193
} ) ;
194
194
195
+ if ( ! [ 'HEAD' ] . includes ( method . toUpperCase ( ) ) ) {
196
+ it ( 'should support body' , async ( ) => {
197
+ await fn ( mockAmplifyInstance , {
198
+ apiName : 'restApi1' ,
199
+ path : '/items' ,
200
+ options : {
201
+ body : {
202
+ message : 'body' ,
203
+ } ,
204
+ } ,
205
+ } ) . response ;
206
+ expect ( mockAuthenticatedHandler ) . toHaveBeenCalledWith (
207
+ {
208
+ url : new URL (
209
+ 'https://123.execute-api.us-west-2.amazonaws.com/development/items' ,
210
+ ) ,
211
+ method,
212
+ headers : {
213
+ 'content-type' : 'application/json; charset=UTF-8' ,
214
+ } ,
215
+ body : '{"message":"body"}' ,
216
+ } ,
217
+ expect . objectContaining ( {
218
+ region : 'us-west-2' ,
219
+ service : 'execute-api' ,
220
+ } ) ,
221
+ ) ;
222
+ } ) ;
223
+ }
224
+
195
225
it ( 'should support path parameters' , async ( ) => {
196
226
await fn ( mockAmplifyInstance , {
197
227
apiName : 'restApi1' ,
Original file line number Diff line number Diff line change @@ -6,14 +6,14 @@ export type GetInput = ApiInput<RestApiOptionsBase>;
6
6
export type PostInput = ApiInput < RestApiOptionsBase > ;
7
7
export type PutInput = ApiInput < RestApiOptionsBase > ;
8
8
export type PatchInput = ApiInput < RestApiOptionsBase > ;
9
- export type DeleteInput = ApiInput < Omit < RestApiOptionsBase , 'body' > > ;
9
+ export type DeleteInput = ApiInput < RestApiOptionsBase > ;
10
10
export type HeadInput = ApiInput < Omit < RestApiOptionsBase , 'body' > > ;
11
11
12
12
export type GetOperation = Operation < RestApiResponse > ;
13
13
export type PostOperation = Operation < RestApiResponse > ;
14
14
export type PutOperation = Operation < RestApiResponse > ;
15
15
export type PatchOperation = Operation < RestApiResponse > ;
16
- export type DeleteOperation = Operation < Omit < RestApiResponse , 'body' > > ;
16
+ export type DeleteOperation = Operation < RestApiResponse > ;
17
17
export type HeadOperation = Operation < Omit < RestApiResponse , 'body' > > ;
18
18
19
19
/**
Original file line number Diff line number Diff line change @@ -108,15 +108,27 @@ describe(fetchTransferHandler.name, () => {
108
108
expect ( mockBody . json ) . toHaveBeenCalledTimes ( 1 ) ; // test caching
109
109
} ) ;
110
110
111
- test . each ( [ 'GET' , 'HEAD' , 'DELETE' ] ) (
111
+ test . each ( [ 'GET' , 'HEAD' ] ) (
112
112
'should ignore request payload for %s request' ,
113
113
async method => {
114
114
await fetchTransferHandler (
115
115
{ ...mockRequest , method, body : 'Mock Body' } ,
116
116
{ } ,
117
117
) ;
118
118
expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 ) ;
119
- expect ( mockFetch . mock . calls [ 0 ] [ 0 ] . body ) . toBeUndefined ( ) ;
119
+ expect ( mockFetch . mock . calls [ 0 ] [ 1 ] . body ) . toBeUndefined ( ) ;
120
+ } ,
121
+ ) ;
122
+
123
+ test . each ( [ 'POST' , 'PUT' , 'DELETE' , 'PATCH' ] ) (
124
+ 'should include request payload for %s request' ,
125
+ async method => {
126
+ await fetchTransferHandler (
127
+ { ...mockRequest , method, body : 'Mock Body' } ,
128
+ { } ,
129
+ ) ;
130
+ expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 ) ;
131
+ expect ( mockFetch . mock . calls [ 0 ] [ 1 ] . body ) . toBe ( 'Mock Body' ) ;
120
132
} ,
121
133
) ;
122
134
} ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { withMemoization } from '../utils/memoization';
8
8
import { AmplifyErrorCode } from '../../types' ;
9
9
10
10
const shouldSendBody = ( method : string ) =>
11
- ! [ 'HEAD' , 'GET' , 'DELETE' ] . includes ( method . toUpperCase ( ) ) ;
11
+ ! [ 'HEAD' , 'GET' ] . includes ( method . toUpperCase ( ) ) ;
12
12
13
13
// TODO[AllanZhengYP]: we need to provide isCanceledError utility
14
14
export const fetchTransferHandler : TransferHandler <
You can’t perform that action at this time.
0 commit comments