11import { describe , expect , test , beforeEach } from "bun:test" ;
22import { CoderTaskAction } from "./action" ;
33import type { Octokit } from "./action" ;
4+ import { ActionOutputsSchema , type ActionOutputs } from "./schemas" ;
45import {
56 MockCoderClient ,
67 createMockOctokit ,
@@ -360,7 +361,7 @@ describe("CoderTaskAction", () => {
360361 // Execute
361362 const result = await action . run ( ) ;
362363
363- // Verify
364+ // Verify API calls
364365 expect ( coderClient . mockGetCoderUserByGithubID ) . toHaveBeenCalledWith ( 12345 ) ;
365366 expect ( coderClient . mockGetTask ) . toHaveBeenCalledWith (
366367 mockUser . username ,
@@ -372,9 +373,9 @@ describe("CoderTaskAction", () => {
372373 template_version_preset_id : undefined ,
373374 input : inputs . coderTaskPrompt ,
374375 } ) ;
375- expect ( result . coderUsername ) . toBe ( "testuser" ) ;
376- expect ( result . taskCreated ) . toBe ( true ) ;
377- expect ( result . taskUrl ) . toContain ( "/tasks/testuser/" ) ;
376+
377+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
378+ assertActionOutputs ( parsedResult , true ) ;
378379 } ) ;
379380
380381 test ( "sends prompt to existing task" , async ( ) => {
@@ -400,7 +401,7 @@ describe("CoderTaskAction", () => {
400401 // Execute
401402 const result = await action . run ( ) ;
402403
403- // Verify
404+ // Verify API calls
404405 expect ( coderClient . mockGetTask ) . toHaveBeenCalledWith (
405406 mockUser . username ,
406407 mockTask . name ,
@@ -411,7 +412,9 @@ describe("CoderTaskAction", () => {
411412 inputs . coderTaskPrompt ,
412413 ) ;
413414 expect ( coderClient . mockCreateTask ) . not . toHaveBeenCalled ( ) ;
414- expect ( result . taskCreated ) . toBe ( false ) ;
415+
416+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
417+ assertActionOutputs ( parsedResult ) ;
415418 } ) ;
416419
417420 test ( "errors without issue URL" , async ( ) => {
@@ -463,9 +466,12 @@ describe("CoderTaskAction", () => {
463466 ) ;
464467
465468 // Execute
466- await action . run ( ) ;
469+ const result = await action . run ( ) ;
470+
471+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
472+ assertActionOutputs ( parsedResult , true ) ;
467473
468- // Verify
474+ // Verify GitHub comment
469475 expect ( octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
470476 expect . objectContaining ( {
471477 owner : "owner" ,
@@ -517,9 +523,12 @@ describe("CoderTaskAction", () => {
517523 ) ;
518524
519525 // Execute
520- await action . run ( ) ;
526+ const result = await action . run ( ) ;
521527
522- // Verify
528+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
529+ assertActionOutputs ( parsedResult , true ) ;
530+
531+ // Verify GitHub comment update
523532 expect ( octokit . rest . issues . updateComment ) . toHaveBeenCalledWith (
524533 expect . objectContaining ( {
525534 owner : "owner" ,
@@ -676,7 +685,11 @@ describe("CoderTaskAction", () => {
676685 inputs ,
677686 ) ;
678687
679- await action . run ( ) ;
688+ const result = await action . run ( ) ;
689+
690+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
691+ assertActionOutputs ( parsedResult , true , "task-456" ) ;
692+
680693 expect ( octokit . rest . issues . createComment ) . toHaveBeenCalledWith (
681694 expect . objectContaining ( {
682695 owner : "different-owner" ,
@@ -716,7 +729,10 @@ describe("CoderTaskAction", () => {
716729 ) ;
717730
718731 // Execute
719- await action . run ( ) ;
732+ const result = await action . run ( ) ;
733+
734+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
735+ assertActionOutputs ( parsedResult , true ) ;
720736
721737 // Verify - should NOT have called comment APIs
722738 expect ( octokit . rest . issues . listComments ) . not . toHaveBeenCalled ( ) ;
@@ -753,7 +769,10 @@ describe("CoderTaskAction", () => {
753769 ) ;
754770
755771 // Execute
756- await action . run ( ) ;
772+ const result = await action . run ( ) ;
773+
774+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
775+ assertActionOutputs ( parsedResult , true ) ;
757776
758777 // Verify - should have called comment APIs
759778 expect ( octokit . rest . issues . listComments ) . toHaveBeenCalled ( ) ;
@@ -789,7 +808,10 @@ describe("CoderTaskAction", () => {
789808 ) ;
790809
791810 // Execute
792- await action . run ( ) ;
811+ const result = await action . run ( ) ;
812+
813+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
814+ assertActionOutputs ( parsedResult , true ) ;
793815
794816 // Verify - should have called comment APIs (default behavior)
795817 expect ( octokit . rest . issues . listComments ) . toHaveBeenCalled ( ) ;
@@ -821,7 +843,10 @@ describe("CoderTaskAction", () => {
821843 ) ;
822844
823845 // Execute
824- await action . run ( ) ;
846+ const result = await action . run ( ) ;
847+
848+ const parsedResult = ActionOutputsSchema . parse ( result ) ;
849+ assertActionOutputs ( parsedResult ) ;
825850
826851 // Verify - should NOT have called comment APIs
827852 expect ( octokit . rest . issues . listComments ) . not . toHaveBeenCalled ( ) ;
@@ -830,3 +855,16 @@ describe("CoderTaskAction", () => {
830855 } ) ;
831856 } ) ;
832857} ) ;
858+
859+ function assertActionOutputs (
860+ outputs : ActionOutputs ,
861+ create = false ,
862+ taskName = mockTask . name . toString ( ) ,
863+ ) {
864+ expect ( outputs . coderUsername ) . toBe ( mockUser . username ) ;
865+ expect ( outputs . taskCreated ) . toBe ( create ) ;
866+ expect ( outputs . taskUrl ) . toMatch (
867+ / ^ h t t p s : \/ \/ c o d e r \. t e s t \/ t a s k s \/ t e s t u s e r \/ [ a - f 0 - 9 - ] + $ / ,
868+ ) ;
869+ expect ( outputs . taskName ) . toBe ( taskName ) ;
870+ }
0 commit comments