@@ -41,9 +41,12 @@ describe('CloudEvent Function', () => {
4141
4242 let receivedCloudEvent : functions . CloudEvent < unknown > | null ;
4343 before ( ( ) => {
44- functions . cloudEvent ( 'testCloudEventFunction' , ce => {
45- receivedCloudEvent = ce ;
46- } ) ;
44+ functions . cloudEvent (
45+ 'testCloudEventFunction' ,
46+ ( ce : functions . CloudEvent < unknown > ) => {
47+ receivedCloudEvent = ce ;
48+ }
49+ ) ;
4750 } ) ;
4851
4952 beforeEach ( ( ) => {
@@ -288,11 +291,39 @@ describe('CloudEvent Function', () => {
288291 const testPayload = 'a test string' ;
289292
290293 // register a strongly typed CloudEvent function
291- functions . cloudEvent < string > ( 'testTypedCloudEvent' , ce => {
292- assert . deepStrictEqual ( ce . data , testPayload ) ;
293- // use a property that proves this is actually typed as a string
294- assert . deepStrictEqual ( ce . data . length , testPayload . length ) ;
295- } ) ;
294+ functions . cloudEvent < string > (
295+ 'testTypedCloudEvent' ,
296+ ( ce : functions . CloudEvent < string > ) => {
297+ assert . deepStrictEqual ( ce . data , testPayload ) ;
298+ // use a property that proves this is actually typed as a string
299+ assert . deepStrictEqual ( ce . data . length , testPayload . length ) ;
300+ }
301+ ) ;
302+
303+ // invoke the function with a CloudEvent with a string payload
304+ const server = getTestServer ( 'testTypedCloudEvent' ) ;
305+ await supertest ( server )
306+ . post ( '/' )
307+ . send ( {
308+ ...TEST_CLOUD_EVENT ,
309+ data : testPayload ,
310+ } )
311+ . expect ( 204 ) ;
312+ } ) ;
313+
314+ it ( 'allows customers to use a handler with callbacks for failure' , async ( ) => {
315+ const testPayload = 'a test string' ;
316+
317+ // register a strongly typed CloudEvent function
318+ functions . cloudEvent < string > (
319+ 'testTypedCloudEvent' ,
320+ ( ce : functions . CloudEvent < string > , callback ) => {
321+ assert . deepStrictEqual ( ce . data , testPayload ) ;
322+ // use a property that proves this is actually typed as a string
323+ assert . deepStrictEqual ( ce . data . length , testPayload . length ) ;
324+ callback ( ) ;
325+ }
326+ ) ;
296327
297328 // invoke the function with a CloudEvent with a string payload
298329 const server = getTestServer ( 'testTypedCloudEvent' ) ;
@@ -305,6 +336,7 @@ describe('CloudEvent Function', () => {
305336 . expect ( 204 ) ;
306337 } ) ;
307338
339+
308340 it ( 'returns a 500 if the function throws an exception' , async ( ) => {
309341 functions . cloudEvent ( 'testTypedCloudEvent' , ( ) => {
310342 throw 'I crashed' ;
0 commit comments