@@ -637,7 +637,7 @@ export function runTests(env, host) {
637
637
} )
638
638
} )
639
639
640
- describe ( `custom type` , ( ) => {
640
+ describe ( `custom type (using 'custom/type' payload) ` , ( ) => {
641
641
const body = JSON . stringify ( {
642
642
content : `test-string` ,
643
643
} )
@@ -682,6 +682,55 @@ export function runTests(env, host) {
682
682
` )
683
683
} )
684
684
} )
685
+
686
+ describe ( `'application/json' payload` , ( ) => {
687
+ const body = JSON . stringify ( {
688
+ content : `test-string` ,
689
+ } )
690
+ it ( `on default config` , async ( ) => {
691
+ const result = await fetch ( `${ host } /api/config/defaults` , {
692
+ method : `POST` ,
693
+ body,
694
+ headers : {
695
+ "content-type" : "application/json" ,
696
+ } ,
697
+ } )
698
+
699
+ expect ( result . status ) . toBe ( 200 )
700
+ const responseBody = await result . json ( )
701
+
702
+ // default config will use default config for "application/json" type
703
+ expect ( responseBody ) . toMatchInlineSnapshot ( `
704
+ Object {
705
+ "body": "{ content: 'test-string' }",
706
+ }
707
+ ` )
708
+ } )
709
+
710
+ it ( `on { bodyParser: { raw: { type: "*/*" }}}` , async ( ) => {
711
+ const result = await fetch (
712
+ `${ host } /api/config/body-parser-raw-type` ,
713
+ {
714
+ method : `POST` ,
715
+ body,
716
+ headers : {
717
+ "content-type" : "application/json" ,
718
+ } ,
719
+ }
720
+ )
721
+
722
+ expect ( result . status ) . toBe ( 200 )
723
+ const responseBody = await result . json ( )
724
+
725
+ // despite application/json payload, we get
726
+ // expected Buffer
727
+ expect ( responseBody ) . toMatchInlineSnapshot ( `
728
+ Object {
729
+ "body": "<Buffer 7b 22 63 6f 6e 74 65 6e 74 22 3a 22 74 65 73 74 2d 73 74 72 69 6e 67 22 7d>",
730
+ }
731
+ ` )
732
+ } )
733
+ } )
685
734
} )
686
735
687
736
describe ( `urlencoded` , ( ) => {
0 commit comments