@@ -6,7 +6,9 @@ package mailer
6
6
7
7
import (
8
8
"bytes"
9
+ "fmt"
9
10
"html/template"
11
+ "strings"
10
12
"testing"
11
13
texttmpl "text/template"
12
14
@@ -15,7 +17,6 @@ import (
15
17
"code.gitea.io/gitea/models/unittest"
16
18
user_model "code.gitea.io/gitea/models/user"
17
19
"code.gitea.io/gitea/modules/setting"
18
-
19
20
"github.com/stretchr/testify/assert"
20
21
)
21
22
@@ -250,3 +251,115 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
250
251
}
251
252
}
252
253
}
254
+
255
+ func Test_createReference (t * testing.T ) {
256
+ _ , _ , issue , comment := prepareMailerTest (t )
257
+ _ , _ , pullIssue , _ := prepareMailerTest (t )
258
+ pullIssue .IsPull = true
259
+
260
+ type args struct {
261
+ issue * models.Issue
262
+ comment * models.Comment
263
+ actionType models.ActionType
264
+ }
265
+ tests := []struct {
266
+ name string
267
+ args args
268
+ prefix string
269
+ suffix string
270
+ }{
271
+ {
272
+ name : "Open Issue" ,
273
+ args : args {
274
+ issue : issue ,
275
+ actionType : models .ActionCreateIssue ,
276
+ },
277
+ prefix : fmt .Sprintf ("%s/issues/%d@%s" , issue .Repo .FullName (), issue .Index , setting .Domain ),
278
+ },
279
+ {
280
+ name : "Open Pull" ,
281
+ args : args {
282
+ issue : pullIssue ,
283
+ actionType : models .ActionCreatePullRequest ,
284
+ },
285
+ prefix : fmt .Sprintf ("%s/pulls/%d@%s" , issue .Repo .FullName (), issue .Index , setting .Domain ),
286
+ },
287
+ {
288
+ name : "Comment Issue" ,
289
+ args : args {
290
+ issue : issue ,
291
+ comment : comment ,
292
+ actionType : models .ActionCommentIssue ,
293
+ },
294
+ prefix : fmt .Sprintf ("%s/issues/%d/comment/%d@%s" , issue .Repo .FullName (), issue .Index , comment .ID , setting .Domain ),
295
+ },
296
+ {
297
+ name : "Comment Pull" ,
298
+ args : args {
299
+ issue : pullIssue ,
300
+ comment : comment ,
301
+ actionType : models .ActionCommentPull ,
302
+ },
303
+ prefix : fmt .Sprintf ("%s/pulls/%d/comment/%d@%s" , issue .Repo .FullName (), issue .Index , comment .ID , setting .Domain ),
304
+ },
305
+ {
306
+ name : "Close Issue" ,
307
+ args : args {
308
+ issue : issue ,
309
+ actionType : models .ActionCloseIssue ,
310
+ },
311
+ prefix : fmt .Sprintf ("%s/issues/%d/close/" , issue .Repo .FullName (), issue .Index ),
312
+ },
313
+ {
314
+ name : "Close Pull" ,
315
+ args : args {
316
+ issue : pullIssue ,
317
+ actionType : models .ActionClosePullRequest ,
318
+ },
319
+ prefix : fmt .Sprintf ("%s/pulls/%d/close/" , issue .Repo .FullName (), issue .Index ),
320
+ },
321
+ {
322
+ name : "Reopen Issue" ,
323
+ args : args {
324
+ issue : issue ,
325
+ actionType : models .ActionReopenIssue ,
326
+ },
327
+ prefix : fmt .Sprintf ("%s/issues/%d/reopen/" , issue .Repo .FullName (), issue .Index ),
328
+ },
329
+ {
330
+ name : "Reopen Pull" ,
331
+ args : args {
332
+ issue : pullIssue ,
333
+ actionType : models .ActionReopenPullRequest ,
334
+ },
335
+ prefix : fmt .Sprintf ("%s/pulls/%d/reopen/" , issue .Repo .FullName (), issue .Index ),
336
+ },
337
+ {
338
+ name : "Merge Pull" ,
339
+ args : args {
340
+ issue : pullIssue ,
341
+ actionType : models .ActionMergePullRequest ,
342
+ },
343
+ prefix : fmt .Sprintf ("%s/pulls/%d/merge/" , issue .Repo .FullName (), issue .Index ),
344
+ },
345
+ {
346
+ name : "Ready Pull" ,
347
+ args : args {
348
+ issue : pullIssue ,
349
+ actionType : models .ActionPullRequestReadyForReview ,
350
+ },
351
+ prefix : fmt .Sprintf ("%s/pulls/%d/ready/" , issue .Repo .FullName (), issue .Index ),
352
+ },
353
+ }
354
+ for _ , tt := range tests {
355
+ t .Run (tt .name , func (t * testing.T ) {
356
+ got := createReference (tt .args .issue , tt .args .comment , tt .args .actionType )
357
+ if ! strings .HasPrefix (got , tt .prefix ) {
358
+ t .Errorf ("createReference() = %v, want %v" , got , tt .prefix )
359
+ }
360
+ if ! strings .HasSuffix (got , tt .suffix ) {
361
+ t .Errorf ("createReference() = %v, want %v" , got , tt .prefix )
362
+ }
363
+ })
364
+ }
365
+ }
0 commit comments