@@ -119,6 +119,24 @@ describe("run", () => {
119119 )
120120 } )
121121
122+ test ( "fails when deleteOldComment and onlyCreateComment are both true" , async ( ) => {
123+ mockConfig . deleteOldComment = true
124+ mockConfig . onlyCreateComment = true
125+ const { core} = await runMain ( )
126+ expect ( core . setFailed ) . toHaveBeenCalledWith (
127+ "delete and only_create cannot be both set to true" ,
128+ )
129+ } )
130+
131+ test ( "fails when deleteOldComment and hideOldComment are both true" , async ( ) => {
132+ mockConfig . deleteOldComment = true
133+ mockConfig . hideOldComment = true
134+ const { core} = await runMain ( )
135+ expect ( core . setFailed ) . toHaveBeenCalledWith (
136+ "delete and hide cannot be both set to true" ,
137+ )
138+ } )
139+
122140 test ( "fails when onlyCreateComment and onlyUpdateComment are both true" , async ( ) => {
123141 mockConfig . onlyCreateComment = true
124142 mockConfig . onlyUpdateComment = true
@@ -137,7 +155,7 @@ describe("run", () => {
137155 )
138156 } )
139157
140- test ( "deletes previous comment when deleteOldComment is true and previous exists" , async ( ) => {
158+ test ( "deletes previous comment when deleteOldComment is true and previous comment exists" , async ( ) => {
141159 mockConfig . deleteOldComment = true
142160 const previous = { id : "existing-id" , body : "old body" }
143161 const { comment, core} = await runMain ( ( { comment} ) => {
@@ -146,19 +164,41 @@ describe("run", () => {
146164 expect ( core . setOutput ) . toHaveBeenCalledWith ( "previous_comment_id" , "existing-id" )
147165 expect ( comment . deleteComment ) . toHaveBeenCalledWith ( expect . anything ( ) , "existing-id" )
148166 expect ( comment . createComment ) . not . toHaveBeenCalled ( )
167+ expect ( comment . updateComment ) . not . toHaveBeenCalled ( )
149168 } )
150169
151170 test ( "skips delete when deleteOldComment is true but no previous comment exists" , async ( ) => {
152171 mockConfig . deleteOldComment = true
153172 const { comment, core} = await runMain ( )
154173 expect ( core . setOutput ) . toHaveBeenCalledWith ( "previous_comment_id" , undefined )
155174 expect ( comment . deleteComment ) . not . toHaveBeenCalled ( )
175+ expect ( comment . createComment ) . not . toHaveBeenCalled ( )
176+ expect ( comment . updateComment ) . not . toHaveBeenCalled ( )
156177 } )
157178
158- test ( "skips creating comment when onlyUpdateComment is true and no previous exists" , async ( ) => {
179+ test ( "Updates previous comment when onlyUpdateComment is true and previous comment exists" , async ( ) => {
180+ mockConfig . onlyUpdateComment = true
181+ const previous = { id : "existing-id" , body : "old body" }
182+ const { comment, core} = await runMain ( ( { comment} ) => {
183+ vi . mocked ( comment . findPreviousComment ) . mockResolvedValue ( previous as any )
184+ vi . mocked ( comment . getBodyOf ) . mockReturnValue ( "previous body content" )
185+ } )
186+ expect ( comment . updateComment ) . toHaveBeenCalledWith (
187+ expect . anything ( ) ,
188+ "existing-id" ,
189+ "test body" ,
190+ "" ,
191+ "previous body content" ,
192+ )
193+ expect ( comment . createComment ) . not . toHaveBeenCalled ( )
194+ expect ( core . setOutput ) . toHaveBeenCalledWith ( "previous_comment_id" , "existing-id" )
195+ } )
196+
197+ test ( "skips creating comment when onlyUpdateComment is true and no previous comment exists" , async ( ) => {
159198 mockConfig . onlyUpdateComment = true
160199 const { comment} = await runMain ( )
161200 expect ( comment . createComment ) . not . toHaveBeenCalled ( )
201+ expect ( comment . updateComment ) . not . toHaveBeenCalled ( )
162202 } )
163203
164204 test ( "creates comment when no previous comment exists" , async ( ) => {
@@ -173,7 +213,7 @@ describe("run", () => {
173213 expect ( core . setOutput ) . toHaveBeenCalledWith ( "created_comment_id" , 456 )
174214 } )
175215
176- test ( "skips update when onlyCreateComment is true and previous exists" , async ( ) => {
216+ test ( "skips update when onlyCreateComment is true and previous comment exists" , async ( ) => {
177217 mockConfig . onlyCreateComment = true
178218 const previous = { id : "existing-id" , body : "old body" }
179219 const { comment} = await runMain ( ( { comment} ) => {
@@ -197,6 +237,14 @@ describe("run", () => {
197237 expect ( comment . updateComment ) . not . toHaveBeenCalled ( )
198238 } )
199239
240+ test ( "skips when hideOldComment is true and no previous comment exists" , async ( ) => {
241+ mockConfig . hideOldComment = true
242+ const { comment} = await runMain ( )
243+ expect ( comment . minimizeComment ) . not . toHaveBeenCalled ( )
244+ expect ( comment . createComment ) . not . toHaveBeenCalled ( )
245+ expect ( comment . updateComment ) . not . toHaveBeenCalled ( )
246+ } )
247+
200248 test ( "skips update when skipUnchanged is true and body is unchanged" , async ( ) => {
201249 mockConfig . skipUnchanged = true
202250 const previous = { id : "existing-id" , body : "old body" }
0 commit comments