@@ -11,6 +11,7 @@ describe("github_api_helpers.cjs", () => {
1111 let logGraphQLError ;
1212 let fetchAllRepoLabels ;
1313 let resolveTopLevelDiscussionCommentId ;
14+ let createDiscussionComment ;
1415 let mockGithub ;
1516
1617 beforeEach ( async ( ) => {
@@ -30,6 +31,7 @@ describe("github_api_helpers.cjs", () => {
3031 logGraphQLError = module . logGraphQLError ;
3132 fetchAllRepoLabels = module . fetchAllRepoLabels ;
3233 resolveTopLevelDiscussionCommentId = module . resolveTopLevelDiscussionCommentId ;
34+ createDiscussionComment = module . createDiscussionComment ;
3335 } ) ;
3436
3537 describe ( "getFileContent" , ( ) => {
@@ -418,4 +420,56 @@ describe("github_api_helpers.cjs", () => {
418420 expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "resolving top-level discussion comment" ) ) ;
419421 } ) ;
420422 } ) ;
423+
424+ describe ( "createDiscussionComment" , ( ) => {
425+ it ( "should create a top-level discussion comment when replyToId is omitted" , async ( ) => {
426+ const mockGraphql = vi . fn ( ) . mockResolvedValueOnce ( {
427+ addDiscussionComment : { comment : { id : "DC_1" , url : "https://github.com/o/r/discussions/1#discussioncomment-1" } } ,
428+ } ) ;
429+
430+ const result = await createDiscussionComment ( { graphql : mockGraphql } , "D_1" , "hello" ) ;
431+
432+ expect ( result ) . toEqual ( { id : "DC_1" , url : "https://github.com/o/r/discussions/1#discussioncomment-1" } ) ;
433+ expect ( mockGraphql ) . toHaveBeenCalledWith ( expect . stringContaining ( "addDiscussionComment" ) , {
434+ dId : "D_1" ,
435+ body : "hello" ,
436+ } ) ;
437+ expect ( String ( mockGraphql . mock . calls [ 0 ] [ 0 ] ) ) . not . toContain ( "$replyToId" ) ;
438+ } ) ;
439+
440+ it ( "should create a threaded discussion comment when replyToId is provided" , async ( ) => {
441+ const mockGraphql = vi . fn ( ) . mockResolvedValueOnce ( {
442+ addDiscussionComment : { comment : { id : "DC_2" , url : "https://github.com/o/r/discussions/1#discussioncomment-2" } } ,
443+ } ) ;
444+
445+ await createDiscussionComment ( { graphql : mockGraphql } , "D_1" , "reply" , "DC_parent" ) ;
446+
447+ expect ( mockGraphql ) . toHaveBeenCalledWith ( expect . stringContaining ( "$replyToId" ) , {
448+ dId : "D_1" ,
449+ body : "reply" ,
450+ replyToId : "DC_parent" ,
451+ } ) ;
452+ } ) ;
453+
454+ it ( "should treat null replyToId as omitted" , async ( ) => {
455+ const mockGraphql = vi . fn ( ) . mockResolvedValueOnce ( {
456+ addDiscussionComment : { comment : { id : "DC_3" , url : "https://github.com/o/r/discussions/1#discussioncomment-3" } } ,
457+ } ) ;
458+
459+ await createDiscussionComment ( { graphql : mockGraphql } , "D_1" , "top-level" , null ) ;
460+
461+ expect ( mockGraphql ) . toHaveBeenCalledWith ( expect . stringContaining ( "addDiscussionComment" ) , {
462+ dId : "D_1" ,
463+ body : "top-level" ,
464+ } ) ;
465+ expect ( String ( mockGraphql . mock . calls [ 0 ] [ 0 ] ) ) . not . toContain ( "$replyToId" ) ;
466+ } ) ;
467+
468+ it ( "should propagate graphql errors" , async ( ) => {
469+ const error = new Error ( "GraphQL failed" ) ;
470+ const mockGraphql = vi . fn ( ) . mockRejectedValueOnce ( error ) ;
471+
472+ await expect ( createDiscussionComment ( { graphql : mockGraphql } , "D_1" , "hello" ) ) . rejects . toThrow ( "GraphQL failed" ) ;
473+ } ) ;
474+ } ) ;
421475} ) ;
0 commit comments