@@ -2724,13 +2724,22 @@ export function defineIntegrationTestSuiteApolloServerTests(
27242724 expect ( invalidRequestErrors ) . toHaveLength ( 0 ) ;
27252725 }
27262726
2727- function blocked ( res : Response ) {
2728- expect ( res . status ) . toBe ( 400 ) ;
2729- expect ( res . text ) . toMatch ( / T h i s o p e r a t i o n h a s b e e n b l o c k e d / ) ;
2730- expect ( invalidRequestErrors ) . toHaveLength ( 1 ) ;
2731- expect ( invalidRequestErrors . pop ( ) ?. message ) . toMatch (
2732- / T h i s o p e r a t i o n h a s b e e n b l o c k e d / ,
2733- ) ;
2727+ // When Apollo Server itself blocks a request, it returns status code 400
2728+ // with a particular message. With some web frameworks, a request without
2729+ // a parsable Content-Type will make it to our middleware and get blocked
2730+ // by us; with other frameworks (eg Fastify) the framework itself will
2731+ // block it earlier in some cases. This function is thus relaxed for the
2732+ // one particular case where Fastify returns a 415 earlier; we can relax
2733+ // it further if other integrations need it.
2734+ function blocked ( res : Response , statusCodes = [ 400 ] ) {
2735+ expect ( statusCodes ) . toContain ( res . status ) ;
2736+ if ( res . status === 400 ) {
2737+ expect ( res . text ) . toMatch ( / T h i s o p e r a t i o n h a s b e e n b l o c k e d / ) ;
2738+ expect ( invalidRequestErrors ) . toHaveLength ( 1 ) ;
2739+ expect ( invalidRequestErrors . pop ( ) ?. message ) . toMatch (
2740+ / T h i s o p e r a t i o n h a s b e e n b l o c k e d / ,
2741+ ) ;
2742+ }
27342743 }
27352744
27362745 it ( 'default' , async ( ) => {
@@ -2745,7 +2754,10 @@ export function defineIntegrationTestSuiteApolloServerTests(
27452754 ) ;
27462755
27472756 // POST without content-type is blocked.
2748- blocked ( await request ( url ) . post ( '/' ) . send ( JSON . stringify ( operation ) ) ) ;
2757+ blocked (
2758+ await request ( url ) . post ( '/' ) . send ( JSON . stringify ( operation ) ) ,
2759+ [ 400 , 415 ] ,
2760+ ) ;
27492761
27502762 // POST with text/plain is blocked.
27512763 blocked (
0 commit comments