@@ -776,6 +776,64 @@ describe('osprey method handler', function () {
776776 } )
777777 } )
778778
779+ describe ( 'json api' , function ( ) {
780+ var JSON_SCHEMA = '{"properties":{"x":{"type":"string"}},"required":["x"]}'
781+ it ( 'should reject invalid request bodies' , function ( ) {
782+ var app = router ( )
783+
784+ app . post ( '/' , handler ( {
785+ body : {
786+ 'application/vnd.api+json' : {
787+ schema : JSON_SCHEMA
788+ }
789+ }
790+ } ) )
791+
792+ return popsicle . default ( {
793+ url : '/' ,
794+ method : 'post' ,
795+ body : 'foobar' ,
796+ headers : {
797+ 'Content-Type' : 'application/vnd.api+json'
798+ }
799+ } )
800+ . use ( server ( createServer ( app ) ) )
801+ . then ( function ( res ) {
802+ expect ( res . status ) . to . equal ( 400 )
803+ } )
804+ } )
805+
806+ it ( 'should parse valid json' , function ( ) {
807+ var app = router ( )
808+
809+ app . post ( '/' , handler ( {
810+ body : {
811+ 'application/vnd.api+json' : {
812+ type : JSON_SCHEMA
813+ }
814+ }
815+ } , '/' , 'POST' , { RAMLVersion : 'RAML10' } ) , function ( req , res ) {
816+ expect ( req . body ) . to . deep . equal ( [ true , false ] )
817+
818+ res . end ( 'success' )
819+ } )
820+
821+ return popsicle . default ( {
822+ url : '/' ,
823+ method : 'post' ,
824+ body : [ true , false ] ,
825+ headers : {
826+ 'Content-Type' : 'application/vnd.api+json'
827+ }
828+ } )
829+ . use ( server ( createServer ( app ) ) )
830+ . then ( function ( res ) {
831+ expect ( res . body ) . to . equal ( 'success' )
832+ expect ( res . status ) . to . equal ( 200 )
833+ } )
834+ } )
835+ } )
836+
779837 describe ( 'json' , function ( ) {
780838 var JSON_SCHEMA = '{"properties":{"x":{"type":"string"}},"required":["x"]}'
781839
0 commit comments