@@ -32,8 +32,13 @@ import { FULL_ENDPOINT, MINIMAL_V2_ENDPOINT, FULL_OPTIONS, FULL_TRIGGER } from "
3232import { onInit } from "../../../src/v2/core" ;
3333import { Handler } from "express" ;
3434
35- function request ( args : { data ?: any , auth ?: Record < string , string > , headers ?: Record < string , string > , method ?: MockRequest [ "method" ] } ) : any {
36- let headers : Record < string , string > = { }
35+ function request ( args : {
36+ data ?: any ;
37+ auth ?: Record < string , string > ;
38+ headers ?: Record < string , string > ;
39+ method ?: MockRequest [ "method" ] ;
40+ } ) : any {
41+ let headers : Record < string , string > = { } ;
3742 if ( args . method !== "POST" ) {
3843 headers [ "content-type" ] = "application/json" ;
3944 }
@@ -191,7 +196,7 @@ describe("onRequest", () => {
191196 res . send ( "Works" ) ;
192197 } ) ;
193198
194- const req = request ( { headers : { origin : "example.com" } } ) ;
199+ const req = request ( { headers : { origin : "example.com" } } ) ;
195200 const resp = await runHandler ( func , req ) ;
196201 expect ( resp . body ) . to . equal ( "Works" ) ;
197202 } ) ;
@@ -208,9 +213,9 @@ describe("onRequest", () => {
208213 origin : "example.com" ,
209214 } ,
210215 method : "OPTIONS" ,
211- } )
216+ } ) ;
212217
213- const resp = await runHandler ( func , req as any ) ;
218+ const resp = await runHandler ( func , req ) ;
214219 expect ( resp . status ) . to . equal ( 204 ) ;
215220 expect ( resp . body ) . to . be . undefined ;
216221 expect ( resp . headers ) . to . deep . equal ( {
@@ -237,7 +242,7 @@ describe("onRequest", () => {
237242 method : "OPTIONS" ,
238243 } ) ;
239244
240- const resp = await runHandler ( func , req as any ) ;
245+ const resp = await runHandler ( func , req ) ;
241246 expect ( resp . status ) . to . equal ( 204 ) ;
242247 expect ( resp . body ) . to . be . undefined ;
243248 expect ( resp . headers ) . to . deep . equal ( {
@@ -266,7 +271,7 @@ describe("onRequest", () => {
266271 method : "OPTIONS" ,
267272 } ) ;
268273
269- const resp = await runHandler ( func , req as any ) ;
274+ const resp = await runHandler ( func , req ) ;
270275 expect ( resp . status ) . to . equal ( 200 ) ;
271276 expect ( resp . body ) . to . be . equal ( "Good" ) ;
272277 expect ( resp . headers ) . to . deep . equal ( { } ) ;
@@ -289,7 +294,7 @@ describe("onRequest", () => {
289294 let hello ;
290295 onInit ( ( ) => ( hello = "world" ) ) ;
291296 expect ( hello ) . to . be . undefined ;
292- await runHandler ( func , req as any ) ;
297+ await runHandler ( func , req ) ;
293298 expect ( hello ) . to . equal ( "world" ) ;
294299 } ) ;
295300} ) ;
@@ -404,9 +409,9 @@ describe("onCall", () => {
404409 it ( "should be an express handler" , async ( ) => {
405410 const func = https . onCall ( ( ) => 42 ) ;
406411
407- const req = request ( { headers : { origin : "example.com" } } ) ;
412+ const req = request ( { headers : { origin : "example.com" } } ) ;
408413
409- const resp = await runHandler ( func , req as any ) ;
414+ const resp = await runHandler ( func , req ) ;
410415 expect ( resp . body ) . to . deep . equal ( JSON . stringify ( { result : 42 } ) ) ;
411416 } ) ;
412417
@@ -424,7 +429,7 @@ describe("onCall", () => {
424429 method : "OPTIONS" ,
425430 } ) ;
426431
427- const resp = await runHandler ( func , req as any ) ;
432+ const resp = await runHandler ( func , req ) ;
428433 expect ( resp . status ) . to . equal ( 204 ) ;
429434 expect ( resp . body ) . to . be . undefined ;
430435 expect ( resp . headers ) . to . deep . equal ( {
@@ -450,7 +455,7 @@ describe("onCall", () => {
450455 method : "OPTIONS" ,
451456 } ) ;
452457
453- const response = await runHandler ( func , req as any ) ;
458+ const response = await runHandler ( func , req ) ;
454459
455460 expect ( response . status ) . to . equal ( 204 ) ;
456461 expect ( response . body ) . to . be . undefined ;
@@ -466,7 +471,7 @@ describe("onCall", () => {
466471
467472 it ( "adds CORS headers" , async ( ) => {
468473 const func = https . onCall ( ( ) => 42 ) ;
469- const req = request ( { headers : { origin : "example.com" } } )
474+ const req = request ( { headers : { origin : "example.com" } } ) ;
470475 const response = await runHandler ( func , req ) ;
471476
472477 expect ( response . status ) . to . equal ( 200 ) ;
@@ -488,16 +493,15 @@ describe("onCall", () => {
488493 it ( "calls init function" , async ( ) => {
489494 const func = https . onCall ( ( ) => 42 ) ;
490495
491- const req = request ( { headers : { origin : "example.com" } } ) ;
496+ const req = request ( { headers : { origin : "example.com" } } ) ;
492497 let hello ;
493498 onInit ( ( ) => ( hello = "world" ) ) ;
494499 expect ( hello ) . to . be . undefined ;
495- await runHandler ( func , req as any ) ;
500+ await runHandler ( func , req ) ;
496501 expect ( hello ) . to . equal ( "world" ) ;
497502 } ) ;
498503
499504 describe ( "authPolicy" , ( ) => {
500-
501505 before ( ( ) => {
502506 sinon . stub ( debug , "isDebugFeatureEnabled" ) . withArgs ( "skipTokenVerification" ) . returns ( true ) ;
503507 } ) ;
@@ -514,7 +518,7 @@ describe("onCall", () => {
514518 ( ) => 42
515519 ) ;
516520
517- const authResp = await runHandler ( func , request ( { auth : { sub : "inlined" } } ) ) ;
521+ const authResp = await runHandler ( func , request ( { auth : { sub : "inlined" } } ) ) ;
518522 expect ( authResp . status ) . to . equal ( 200 ) ;
519523
520524 const anonResp = await runHandler ( func , request ( { } ) ) ;
@@ -543,7 +547,7 @@ describe("onCall", () => {
543547 { fn : specificValue , auth : { meaning : "42" } , status : 200 } ,
544548 { fn : specificValue , auth : { meaning : "43" } , status : 403 } ,
545549 { fn : specificValue , auth : { order : "66" } , status : 403 } ,
546- { fn : specificValue , status : 403 } ,
550+ { fn : specificValue , status : 403 } ,
547551 ] ;
548552 for ( const test of cases ) {
549553 const resp = await runHandler ( test . fn , request ( { auth : test . auth } ) ) ;
@@ -579,14 +583,13 @@ describe("onCallGenkit", () => {
579583 flow . run . withArgs ( "answer" ) . returns ( 42 ) ;
580584 flow . stream . onCall ( 0 ) . throws ( "Unexpected stream" ) ;
581585
582- const f = https . onCallGenkit ( flow ) ;
586+ const f = https . onCallGenkit ( flow ) ;
583587
584588 const req = request ( { data : "answer" } ) ;
585589 const res = await runHandler ( f , req ) ;
586- expect ( JSON . parse ( res . body ) ) . to . deep . equal ( { " result" : 42 } ) ;
590+ expect ( JSON . parse ( res . body ) ) . to . deep . equal ( { result : 42 } ) ;
587591 } ) ;
588592
589-
590593 it ( "Streams with SSE requests" , async ( ) => {
591594 const flow = {
592595 __action : {
@@ -597,8 +600,10 @@ describe("onCallGenkit", () => {
597600 } ;
598601 flow . run . onFirstCall ( ) . throws ( ) ;
599602 flow . stream . withArgs ( "answer" ) . returns ( {
600- stream : ( async function * ( ) {
603+ stream : ( async function * ( ) {
604+ await Promise . resolve ( ) ;
601605 yield 1 ;
606+ await Promise . resolve ( ) ;
602607 yield 2 ;
603608 } ) ( ) ,
604609 output : Promise . resolve ( 42 ) ,
@@ -607,12 +612,13 @@ describe("onCallGenkit", () => {
607612
608613 const f = https . onCallGenkit ( flow ) ;
609614
610- const req = request ( { data : "answer" , headers : { accept : "text/event-stream" } } ) ;
615+ const req = request ( { data : "answer" , headers : { accept : "text/event-stream" } } ) ;
611616 const res = await runHandler ( f , req ) ;
612- expect ( res . body ) . to . equal ( [ 'data: {"message":1}' , 'data: {"message":2}' , 'data: {"result":42}' , '' ] . join ( "\n" ) ) ;
617+ expect ( res . body ) . to . equal (
618+ [ 'data: {"message":1}' , 'data: {"message":2}' , 'data: {"result":42}' , "" ] . join ( "\n" )
619+ ) ;
613620 } ) ;
614621
615-
616622 // TODO: Once genkit 1.0.0-rc.4 is released, add a type checking test that succeeds by compiling correctly.
617623 // It should create a genkit resource and then call onCallGenkit with it. If the compiler fails, our typing
618624 // needs to be updated.
0 commit comments