@@ -154,21 +154,125 @@ describe('params reached to function', () => {
154154 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
155155
156156 log ( 'invoke mirror' )
157- const customHeader = nanoid ( ) ;
158- const validRegion = FunctionRegion . ApNortheast1 ;
157+ const customHeader = nanoid ( )
158+ const validRegion = FunctionRegion . ApNortheast1
159159
160160 const { data, error } = await fclient . invoke < MirrorResponse > ( 'mirror' , {
161161 headers : {
162162 'custom-header' : customHeader ,
163163 Authorization : `Bearer ${ apiKey } ` ,
164164 } ,
165- region : validRegion
165+ region : validRegion ,
166166 } )
167167
168168 log ( 'assert no error' )
169- expect ( data ) . not . toBeNull ( )
169+ const expected = {
170+ url : 'http://localhost:8000/mirror' ,
171+ method : 'POST' ,
172+ headers : data ?. headers ?? [ ] ,
173+ body : '' ,
174+ }
175+ expect ( data ) . toEqual ( expected )
176+ attach (
177+ 'check headers from function' ,
178+ `expected to include: ${ [ 'custom-header' , customHeader ] } \n actual: ${ JSON . stringify (
179+ data ?. headers
180+ ) } `,
181+ ContentType . TEXT
182+ )
183+ console . log ( data ?. headers )
184+ expect (
185+ ( data ?. headers as [ Array < string > ] ) . filter ( ( [ k , v ] ) => k === 'x-region' && v === validRegion )
186+ . length > 0
187+ ) . toBe ( true )
188+ } )
189+
190+ test ( 'invoke with region overrides region in the client' , async ( ) => {
191+ /**
192+ * @feature headers
193+ */
194+ log ( 'create FunctionsClient' )
195+ const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
196+ region : FunctionRegion . ApNortheast1 ,
197+ } )
198+
199+ log ( 'invoke mirror' )
200+ const customHeader = nanoid ( )
201+ const validRegion = FunctionRegion . ApSoutheast1
202+
203+ const { data, error } = await fclient . invoke < MirrorResponse > ( 'mirror' , {
204+ headers : {
205+ 'custom-header' : customHeader ,
206+ Authorization : `Bearer ${ apiKey } ` ,
207+ } ,
208+ region : validRegion ,
209+ } )
210+
211+ log ( 'assert no error' )
212+ const expected = {
213+ url : 'http://localhost:8000/mirror' ,
214+ method : 'POST' ,
215+ headers : data ?. headers ?? [ ] ,
216+ body : '' ,
217+ }
218+ expect ( data ) . toEqual ( expected )
219+ attach (
220+ 'check headers from function' ,
221+ `expected to include: ${ [ 'custom-header' , customHeader ] } \n actual: ${ JSON . stringify (
222+ data ?. headers
223+ ) } `,
224+ ContentType . TEXT
225+ )
226+ console . log ( data ?. headers )
227+ expect (
228+ ( data ?. headers as [ Array < string > ] ) . filter ( ( [ k , v ] ) => k === 'x-region' && v === validRegion )
229+ . length > 0
230+ ) . toBe ( true )
231+ } )
232+
233+ test ( 'invoke with region overrides region in the client' , async ( ) => {
234+ /**
235+ * @feature headers
236+ */
237+ log ( 'create FunctionsClient' )
238+ const validRegion = FunctionRegion . ApSoutheast1
239+ const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` , {
240+ region : validRegion ,
241+ } )
242+
243+ log ( 'invoke mirror' )
244+ const customHeader = nanoid ( )
245+
246+ const { data, error } = await fclient . invoke < MirrorResponse > ( 'mirror' , {
247+ headers : {
248+ 'custom-header' : customHeader ,
249+ Authorization : `Bearer ${ apiKey } ` ,
250+ } ,
251+ } )
252+
253+ log ( 'assert no error' )
254+ const expected = {
255+ url : 'http://localhost:8000/mirror' ,
256+ method : 'POST' ,
257+ headers : data ?. headers ?? [ ] ,
258+ body : '' ,
259+ }
260+ expect ( data ) . toEqual ( expected )
261+ attach (
262+ 'check headers from function' ,
263+ `expected to include: ${ [ 'custom-header' , customHeader ] } \n actual: ${ JSON . stringify (
264+ data ?. headers
265+ ) } `,
266+ ContentType . TEXT
267+ )
268+ console . log ( data ?. headers )
269+ expect (
270+ ( data ?. headers as [ Array < string > ] ) . filter ( ( [ k , v ] ) => k === 'x-region' && v === validRegion )
271+ . length > 0
272+ ) . toBe ( true )
170273 } )
171274
275+ // todo: update test to check for the correct header value
172276 test ( 'invoke mirror with invoke header and valid region' , async ( ) => {
173277 /**
174278 * @feature headers
@@ -177,15 +281,15 @@ describe('params reached to function', () => {
177281 const fclient = new FunctionsClient ( `http://localhost:${ relay . container . getMappedPort ( 8081 ) } ` )
178282
179283 log ( 'invoke mirror' )
180- const customHeader = nanoid ( ) ;
181- const validRegion = FunctionRegion . EuWest1 ;
284+ const customHeader = nanoid ( )
285+ const validRegion = FunctionRegion . EuWest1
182286
183287 const { data, error } = await fclient . invoke < MirrorResponse > ( 'mirror' , {
184288 headers : {
185289 'custom-header' : customHeader ,
186290 Authorization : `Bearer ${ apiKey } ` ,
187- 'x-region' : validRegion
188- }
291+ 'x-region' : validRegion ,
292+ } ,
189293 } )
190294
191295 log ( 'assert no error' )
0 commit comments