@@ -41,9 +41,12 @@ describe('CloudEvent Function', () => {
41
41
42
42
let receivedCloudEvent : functions . CloudEvent < unknown > | null ;
43
43
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
+ ) ;
47
50
} ) ;
48
51
49
52
beforeEach ( ( ) => {
@@ -288,11 +291,39 @@ describe('CloudEvent Function', () => {
288
291
const testPayload = 'a test string' ;
289
292
290
293
// 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
+ ) ;
296
327
297
328
// invoke the function with a CloudEvent with a string payload
298
329
const server = getTestServer ( 'testTypedCloudEvent' ) ;
@@ -305,6 +336,7 @@ describe('CloudEvent Function', () => {
305
336
. expect ( 204 ) ;
306
337
} ) ;
307
338
339
+
308
340
it ( 'returns a 500 if the function throws an exception' , async ( ) => {
309
341
functions . cloudEvent ( 'testTypedCloudEvent' , ( ) => {
310
342
throw 'I crashed' ;
0 commit comments