1- // Copyright IBM Corp. 2019. All Rights Reserved.
1+ // Copyright IBM Corp. 2019,2020 . All Rights Reserved.
22// Node module: @loopback /rest
33// This file is licensed under the MIT License.
44// License text available at https://opensource.org/licenses/MIT
@@ -15,6 +15,7 @@ import {
1515 ShotRequestOptions ,
1616 stubExpressContext ,
1717} from '@loopback/testlab' ;
18+ import msgpack from 'msgpack' ;
1819import {
1920 createResolvedRoute ,
2021 JsonBodyParser ,
@@ -256,6 +257,47 @@ describe('operationArgsParser', () => {
256257 expect ( args ) . to . eql ( [ { key1 : [ 'value1' , 'value2' ] } ] ) ;
257258 } ) ;
258259
260+ it ( 'parses body parameter for MessagePack data' , async ( ) => {
261+ const contentTypes = [
262+ 'application/msgpack' ,
263+ 'application/x-msgpack' ,
264+ 'application/subtype+msgpack' ,
265+ ] ;
266+
267+ for ( const contentType of contentTypes ) {
268+ const req = givenRequest ( {
269+ url : '/' ,
270+ headers : {
271+ 'Content-Type' : contentType ,
272+ } ,
273+ payload : msgpack . pack ( {
274+ data : 'hello world' ,
275+ } ) ,
276+ } ) ;
277+
278+ const spec = givenOperationWithRequestBody ( {
279+ description : 'data' ,
280+ content : {
281+ [ contentType ] : {
282+ schema : {
283+ type : 'object' ,
284+ properties : {
285+ data : {
286+ type : 'string' ,
287+ } ,
288+ } ,
289+ } ,
290+ } ,
291+ } ,
292+ } ) ;
293+ const route = givenResolvedRoute ( spec ) ;
294+
295+ const args = await parseOperationArgs ( req , route , requestBodyParser ) ;
296+
297+ expect ( args ) . to . eql ( { data : 'hello world' } ) ;
298+ }
299+ } ) ;
300+
259301 it ( 'parses body parameter for text data' , async ( ) => {
260302 const req = givenRequest ( {
261303 url : '/' ,
0 commit comments