@@ -44,7 +44,7 @@ describe("wrangler workflows", () => {
4444 ) ;
4545 } ;
4646
47- const mockPatchRequest = async ( expectedInstance : string ) => {
47+ const mockChangeStatusRequest = async ( expectedInstance : string ) => {
4848 msw . use (
4949 http . patch (
5050 `*/accounts/:accountId/workflows/some-workflow/instances/:instanceId/status` ,
@@ -62,6 +62,28 @@ describe("wrangler workflows", () => {
6262 ) ;
6363 } ;
6464
65+ const mockSendEventRequest = async (
66+ expectedInstance : string ,
67+ event : string
68+ ) => {
69+ msw . use (
70+ http . post (
71+ `*/accounts/:accountId/workflows/some-workflow/instances/:instanceId/events/:event` ,
72+ async ( { params } ) => {
73+ expect ( params . instanceId ) . toEqual ( expectedInstance ) ;
74+ expect ( params . event ) . toEqual ( event ) ;
75+ return HttpResponse . json ( {
76+ success : true ,
77+ errors : [ ] ,
78+ messages : [ ] ,
79+ result : { } ,
80+ } ) ;
81+ } ,
82+ { once : true }
83+ )
84+ ) ;
85+ } ;
86+
6587 const mockDeleteWorkflowRequest = async ( workflowName : string ) => {
6688 msw . use (
6789 http . delete (
@@ -145,19 +167,19 @@ describe("wrangler workflows", () => {
145167 await runWrangler ( `workflows instances` ) ;
146168 await endEventLoop ( ) ;
147169
148- expect ( std . out ) . toMatchInlineSnapshot (
149- `
170+ expect ( std . out ) . toMatchInlineSnapshot ( `
150171 "wrangler workflows instances
151172
152173 Manage Workflow instances
153174
154175 COMMANDS
155- wrangler workflows instances list <name> Instance related commands (list, describe, terminate, pause, resume)
156- wrangler workflows instances describe <name> [id] Describe a workflow instance - see its logs, retries and errors
157- wrangler workflows instances terminate <name> <id> Terminate a workflow instance
158- wrangler workflows instances restart <name> <id> Restart a workflow instance
159- wrangler workflows instances pause <name> <id> Pause a workflow instance
160- wrangler workflows instances resume <name> <id> Resume a workflow instance
176+ wrangler workflows instances list <name> Instance related commands (list, describe, terminate, pause, resume)
177+ wrangler workflows instances describe <name> [id] Describe a workflow instance - see its logs, retries and errors
178+ wrangler workflows instances send-event <name> <id> Send an event to a workflow instance
179+ wrangler workflows instances terminate <name> <id> Terminate a workflow instance
180+ wrangler workflows instances restart <name> <id> Restart a workflow instance
181+ wrangler workflows instances pause <name> <id> Pause a workflow instance
182+ wrangler workflows instances resume <name> <id> Resume a workflow instance
161183
162184 GLOBAL FLAGS
163185 -c, --config Path to Wrangler configuration file [string]
@@ -166,8 +188,7 @@ describe("wrangler workflows", () => {
166188 --env-file Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files [array]
167189 -h, --help Show help [boolean]
168190 -v, --version Show version number [boolean]"
169- `
170- ) ;
191+ ` ) ;
171192 } ) ;
172193 } ) ;
173194
@@ -480,6 +501,45 @@ describe("wrangler workflows", () => {
480501 } ) ;
481502 } ) ;
482503
504+ describe ( "instances send-event" , ( ) => {
505+ const mockInstances : Instance [ ] = [
506+ {
507+ id : "foo" ,
508+ created_on : mockCreateDate . toISOString ( ) ,
509+ modified_on : mockModifiedDate . toISOString ( ) ,
510+ workflow_id : "b" ,
511+ version_id : "c" ,
512+ status : "running" ,
513+ } ,
514+ ] ;
515+
516+ it ( "should send an event without payload to the bar instance given a name" , async ( ) => {
517+ writeWranglerConfig ( ) ;
518+ await mockGetInstances ( mockInstances ) ;
519+ await mockSendEventRequest ( "bar" , "my-event" ) ;
520+
521+ await runWrangler (
522+ "workflows instances send-event some-workflow bar --type my-event"
523+ ) ;
524+ expect ( std . info ) . toMatchInlineSnapshot (
525+ `"📤 The event with type \\"my-event\\" was sent to the instance \\"bar\\" from some-workflow"`
526+ ) ;
527+ } ) ;
528+
529+ it ( "should send an event with payload to the bar instance given a name" , async ( ) => {
530+ writeWranglerConfig ( ) ;
531+ await mockGetInstances ( mockInstances ) ;
532+ await mockSendEventRequest ( "bar" , "my-event" ) ;
533+
534+ await runWrangler (
535+ `workflows instances send-event some-workflow bar --type my-event --payload '{"key": "value"}'`
536+ ) ;
537+ expect ( std . info ) . toMatchInlineSnapshot (
538+ `"📤 The event with type \\"my-event\\" and payload \\"{\\"key\\": \\"value\\"}\\" was sent to the instance \\"bar\\" from some-workflow"`
539+ ) ;
540+ } ) ;
541+ } ) ;
542+
483543 describe ( "instances pause" , ( ) => {
484544 const mockInstances : Instance [ ] = [
485545 {
@@ -503,7 +563,7 @@ describe("wrangler workflows", () => {
503563 it ( "should get and pause the bar instance given a name" , async ( ) => {
504564 writeWranglerConfig ( ) ;
505565 await mockGetInstances ( mockInstances ) ;
506- await mockPatchRequest ( "bar" ) ;
566+ await mockChangeStatusRequest ( "bar" ) ;
507567
508568 await runWrangler ( `workflows instances pause some-workflow bar` ) ;
509569 expect ( std . info ) . toMatchInlineSnapshot (
@@ -535,7 +595,7 @@ describe("wrangler workflows", () => {
535595 it ( "should get and resume the bar instance given a name" , async ( ) => {
536596 writeWranglerConfig ( ) ;
537597 await mockGetInstances ( mockInstances ) ;
538- await mockPatchRequest ( "bar" ) ;
598+ await mockChangeStatusRequest ( "bar" ) ;
539599
540600 await runWrangler ( `workflows instances resume some-workflow bar` ) ;
541601 expect ( std . info ) . toMatchInlineSnapshot (
@@ -567,7 +627,7 @@ describe("wrangler workflows", () => {
567627 it ( "should get and terminate the bar instance given a name" , async ( ) => {
568628 writeWranglerConfig ( ) ;
569629 await mockGetInstances ( mockInstances ) ;
570- await mockPatchRequest ( "bar" ) ;
630+ await mockChangeStatusRequest ( "bar" ) ;
571631
572632 await runWrangler ( `workflows instances terminate some-workflow bar` ) ;
573633 expect ( std . info ) . toMatchInlineSnapshot (
@@ -599,7 +659,7 @@ describe("wrangler workflows", () => {
599659 it ( "should get and restart the bar instance given a name" , async ( ) => {
600660 writeWranglerConfig ( ) ;
601661 await mockGetInstances ( mockInstances ) ;
602- await mockPatchRequest ( "bar" ) ;
662+ await mockChangeStatusRequest ( "bar" ) ;
603663
604664 await runWrangler ( `workflows instances restart some-workflow bar` ) ;
605665 expect ( std . info ) . toMatchInlineSnapshot (
0 commit comments