@@ -312,6 +312,58 @@ describe("OrchestrationContext.sendEvent", () => {
312312 // No data should be set (or empty)
313313 expect ( sendEvent ?. getData ( ) ?. getValue ( ) ?? "" ) . toEqual ( "" ) ;
314314 } ) ;
315+
316+ it ( "should fail the orchestration when eventName is empty" , async ( ) => {
317+ const orchestrator : TOrchestrator = async ( ctx : OrchestrationContext ) => {
318+ ctx . sendEvent ( "target-instance-id" , "" , { data : "value" } ) ;
319+ return "done" ;
320+ } ;
321+
322+ const registry = new Registry ( ) ;
323+ const name = registry . addOrchestrator ( orchestrator ) ;
324+ const newEvents = [
325+ newOrchestratorStartedEvent ( ) ,
326+ newExecutionStartedEvent ( name , TEST_INSTANCE_ID ) ,
327+ ] ;
328+ const executor = new OrchestrationExecutor ( registry ) ;
329+ const result = await executor . execute ( TEST_INSTANCE_ID , [ ] , newEvents ) ;
330+
331+ // The orchestration should fail because sendEvent throws on empty eventName
332+ expect ( result . actions . length ) . toEqual ( 1 ) ;
333+ const completeAction = result . actions [ 0 ] . getCompleteorchestration ( ) ;
334+ expect ( completeAction ?. getOrchestrationstatus ( ) ) . toEqual (
335+ pb . OrchestrationStatus . ORCHESTRATION_STATUS_FAILED ,
336+ ) ;
337+ expect ( completeAction ?. getFailuredetails ( ) ?. getErrormessage ( ) ) . toContain (
338+ "'eventName' is required and cannot be empty" ,
339+ ) ;
340+ } ) ;
341+
342+ it ( "should fail the orchestration when instanceId is empty" , async ( ) => {
343+ const orchestrator : TOrchestrator = async ( ctx : OrchestrationContext ) => {
344+ ctx . sendEvent ( "" , "my-event" , { data : "value" } ) ;
345+ return "done" ;
346+ } ;
347+
348+ const registry = new Registry ( ) ;
349+ const name = registry . addOrchestrator ( orchestrator ) ;
350+ const newEvents = [
351+ newOrchestratorStartedEvent ( ) ,
352+ newExecutionStartedEvent ( name , TEST_INSTANCE_ID ) ,
353+ ] ;
354+ const executor = new OrchestrationExecutor ( registry ) ;
355+ const result = await executor . execute ( TEST_INSTANCE_ID , [ ] , newEvents ) ;
356+
357+ // The orchestration should fail because sendEvent throws on empty instanceId
358+ expect ( result . actions . length ) . toEqual ( 1 ) ;
359+ const completeAction = result . actions [ 0 ] . getCompleteorchestration ( ) ;
360+ expect ( completeAction ?. getOrchestrationstatus ( ) ) . toEqual (
361+ pb . OrchestrationStatus . ORCHESTRATION_STATUS_FAILED ,
362+ ) ;
363+ expect ( completeAction ?. getFailuredetails ( ) ?. getErrormessage ( ) ) . toContain (
364+ "'instanceId' is required and cannot be empty" ,
365+ ) ;
366+ } ) ;
315367} ) ;
316368
317369describe ( "OrchestrationContext.newGuid" , ( ) => {
0 commit comments