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', () => {
192192 ) ;
193193 } ) ;
194194
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+
195225 it ( 'should support path parameters' , async ( ) => {
196226 await fn ( mockAmplifyInstance , {
197227 apiName : 'restApi1' ,
Original file line number Diff line number Diff line change @@ -6,14 +6,14 @@ export type GetInput = ApiInput<RestApiOptionsBase>;
66export type PostInput = ApiInput < RestApiOptionsBase > ;
77export type PutInput = ApiInput < RestApiOptionsBase > ;
88export type PatchInput = ApiInput < RestApiOptionsBase > ;
9- export type DeleteInput = ApiInput < Omit < RestApiOptionsBase , 'body' > > ;
9+ export type DeleteInput = ApiInput < RestApiOptionsBase > ;
1010export type HeadInput = ApiInput < Omit < RestApiOptionsBase , 'body' > > ;
1111
1212export type GetOperation = Operation < RestApiResponse > ;
1313export type PostOperation = Operation < RestApiResponse > ;
1414export type PutOperation = Operation < RestApiResponse > ;
1515export type PatchOperation = Operation < RestApiResponse > ;
16- export type DeleteOperation = Operation < Omit < RestApiResponse , 'body' > > ;
16+ export type DeleteOperation = Operation < RestApiResponse > ;
1717export type HeadOperation = Operation < Omit < RestApiResponse , 'body' > > ;
1818
1919/**
Original file line number Diff line number Diff line change @@ -108,15 +108,27 @@ describe(fetchTransferHandler.name, () => {
108108 expect ( mockBody . json ) . toHaveBeenCalledTimes ( 1 ) ; // test caching
109109 } ) ;
110110
111- test . each ( [ 'GET' , 'HEAD' , 'DELETE' ] ) (
111+ test . each ( [ 'GET' , 'HEAD' ] ) (
112112 'should ignore request payload for %s request' ,
113113 async method => {
114114 await fetchTransferHandler (
115115 { ...mockRequest , method, body : 'Mock Body' } ,
116116 { } ,
117117 ) ;
118118 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' ) ;
120132 } ,
121133 ) ;
122134} ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { withMemoization } from '../utils/memoization';
88import { AmplifyErrorCode } from '../../types' ;
99
1010const shouldSendBody = ( method : string ) =>
11- ! [ 'HEAD' , 'GET' , 'DELETE' ] . includes ( method . toUpperCase ( ) ) ;
11+ ! [ 'HEAD' , 'GET' ] . includes ( method . toUpperCase ( ) ) ;
1212
1313// TODO[AllanZhengYP]: we need to provide isCanceledError utility
1414export const fetchTransferHandler : TransferHandler <
You can’t perform that action at this time.
0 commit comments