11use graph:: prelude:: serde_json;
22use graph:: prelude:: * ;
33use http:: StatusCode ;
4- use hyper:: { Body , Response } ;
4+ use hyper:: { header :: ACCESS_CONTROL_ALLOW_ORIGIN , Body , Response } ;
55
66/// Asserts that the response is a successful GraphQL response; returns its `"data"` field.
77pub fn assert_successful_response (
88 response : Response < Body > ,
99) -> serde_json:: Map < String , serde_json:: Value > {
1010 assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
11-
11+ assert_expected_headers ( & response ) ;
1212 futures03:: executor:: block_on (
1313 hyper:: body:: to_bytes ( response. into_body ( ) )
1414 . map_ok ( |chunk| {
@@ -35,7 +35,7 @@ pub fn assert_error_response(
3535 graphql_response : bool ,
3636) -> Vec < serde_json:: Value > {
3737 assert_eq ! ( response. status( ) , expected_status) ;
38-
38+ assert_expected_headers ( & response ) ;
3939 let body = String :: from_utf8 (
4040 futures03:: executor:: block_on ( hyper:: body:: to_bytes ( response. into_body ( ) ) )
4141 . unwrap ( )
@@ -59,3 +59,13 @@ pub fn assert_error_response(
5959 . expect ( "GraphQL \" errors\" field must be a vector" )
6060 . clone ( )
6161}
62+
63+ pub fn assert_expected_headers ( response : & Response < Body > ) {
64+ assert_eq ! (
65+ response
66+ . headers( )
67+ . get( ACCESS_CONTROL_ALLOW_ORIGIN )
68+ . expect( "Missing CORS Header" ) ,
69+ & "*"
70+ ) ;
71+ }
0 commit comments