@@ -17,6 +17,10 @@ const {
1717const { mockClient} = require ( 'aws-sdk-client-mock' )
1818const { ServiceException} = require ( '@smithy/smithy-client' )
1919
20+ const standardHeaders = {
21+ 'x-correlation-id' : 'test-correlation-id' ,
22+ 'x-apigateway-event' : 'test-apigateway-event'
23+ }
2024class AccessDenied extends ServiceException {
2125 constructor ( options ) {
2226 super ( { ...options , name : 'AccessDenied' } )
@@ -66,37 +70,49 @@ describe('server', () => {
6670 ] ) ( 'Path %p should render correctly' , ( path , expectedStatus , expectedContentType ) => {
6771 return request ( app )
6872 . get ( path )
73+ . set ( standardHeaders )
6974 . expect ( expectedStatus )
7075 . expect ( 'Content-Type' , expectedContentType )
7176 } )
7277
7378 test ( 'Path "/cache" has Cache-Control set' , ( ) => {
74- return request ( app ) . get ( '/cache' ) . expect ( 'Cache-Control' , 's-maxage=60' )
79+ return request ( app )
80+ . get ( '/cache' )
81+ . set ( standardHeaders )
82+ . expect ( 'Cache-Control' , 's-maxage=60' )
7583 } )
7684
7785 test ( 'Path "/cache/:duration" has Cache-Control set correctly' , ( ) => {
78- return request ( app ) . get ( '/cache/123' ) . expect ( 'Cache-Control' , 's-maxage=123' )
86+ return request ( app )
87+ . get ( '/cache/123' )
88+ . set ( standardHeaders )
89+ . expect ( 'Cache-Control' , 's-maxage=123' )
7990 } )
8091
8192 test ( 'All responses have Server header set to "mrt ref app"' , ( ) => {
82- return request ( app ) . get ( '/' ) . expect ( 'Server' , 'mrt ref app' )
93+ return request ( app ) . get ( '/' ) . set ( standardHeaders ) . expect ( 'Server' , 'mrt ref app' )
8394 } )
8495
8596 test ( 'Path "/headers" echoes request headers' , async ( ) => {
86- const response = await request ( app ) . get ( '/headers' ) . set ( 'Random-Header' , 'random' )
97+ const response = await request ( app )
98+ . get ( '/headers' )
99+ . set ( standardHeaders )
100+ . set ( 'Random-Header' , 'random' )
87101
88102 expect ( response . body . headers [ 'random-header' ] ) . toBe ( 'random' )
89103 } )
90104
91105 test ( 'Path "/cookie" sets cookie' , ( ) => {
92106 return request ( app )
93107 . get ( '/cookie?name=test-cookie&value=test-value' )
108+ . set ( standardHeaders )
94109 . expect ( 'set-cookie' , 'test-cookie=test-value; Path=/' )
95110 } )
96111
97112 test ( 'Path "/set-response-headers" sets response header' , ( ) => {
98113 return request ( app )
99114 . get ( '/set-response-headers?header1=value1&header2=test-value' )
115+ . set ( standardHeaders )
100116 . expect ( 'header1' , 'value1' )
101117 . expect ( 'header2' , 'test-value' )
102118 } )
@@ -107,7 +123,7 @@ describe('server', () => {
107123 s3Mock . on ( GetObjectCommand ) . rejects ( new AccessDenied ( ) )
108124 logsMock . on ( CreateLogStreamCommand ) . rejects ( new AccessDeniedException ( ) )
109125 const params = `FunctionName=name&Bucket=bucket&Key=key&logGroupName=lgName`
110- const response = await request ( app ) . get ( `/isolation?${ params } ` )
126+ const response = await request ( app ) . get ( `/isolation?${ params } ` ) . set ( standardHeaders )
111127 expect ( response . body . origin ) . toBe ( true )
112128 expect ( response . body . storage ) . toBe ( true )
113129 expect ( response . body . logs ) . toBe ( true )
@@ -119,7 +135,7 @@ describe('server', () => {
119135 s3Mock . on ( GetObjectCommand ) . resolves ( )
120136 logsMock . on ( CreateLogStreamCommand ) . resolves ( )
121137 const params = `FunctionName=name&Bucket=bucket&Key=key&logGroupName=lgName`
122- const response = await request ( app ) . get ( `/isolation?${ params } ` )
138+ const response = await request ( app ) . get ( `/isolation?${ params } ` ) . set ( standardHeaders )
123139 expect ( response . body . origin ) . toBe ( false )
124140 expect ( response . body . storage ) . toBe ( false )
125141 expect ( response . body . logs ) . toBe ( false )
@@ -133,14 +149,14 @@ describe('server', () => {
133149 } )
134150
135151 test ( 'Path "/ssr-shared" serves the example.json file' , async ( ) => {
136- const response = await request ( app ) . get ( '/ssr-shared' )
152+ const response = await request ( app ) . get ( '/ssr-shared' ) . set ( standardHeaders )
137153 expect ( response . body . message ) . toBe (
138154 'This file is used in the E2E tests to verify that correct header values are set.'
139155 )
140156 } )
141157
142158 test ( 'Path "/streaming-large" returns streaming: false' , async ( ) => {
143- const response = await request ( app ) . get ( '/streaming-large' )
159+ const response = await request ( app ) . get ( '/streaming-large' ) . set ( standardHeaders )
144160 expect ( response . status ) . toBe ( 200 )
145161 expect ( response . body ) . toEqual ( { streaming : false } )
146162 } )
0 commit comments