@@ -81,3 +81,68 @@ func TestGetParticipantsByIssueID(t *testing.T) {
81
81
// Users 3 and 5 made actual comments (see fixtures/comment.yml)
82
82
checkParticipants (1 , []int {3 , 5 })
83
83
}
84
+
85
+ func TestIssue_AddLabel (t * testing.T ) {
86
+ var tests = []struct {
87
+ issueID int64
88
+ labelID int64
89
+ doerID int64
90
+ }{
91
+ {1 , 2 , 2 }, // non-pull-request, not-already-added label
92
+ {1 , 1 , 2 }, // non-pull-request, already-added label
93
+ {2 , 2 , 2 }, // pull-request, not-already-added label
94
+ {2 , 1 , 2 }, // pull-request, already-added label
95
+ }
96
+ for _ , test := range tests {
97
+ assert .NoError (t , PrepareTestDatabase ())
98
+ issue := AssertExistsAndLoadBean (t , & Issue {ID : test .issueID }).(* Issue )
99
+ label := AssertExistsAndLoadBean (t , & Label {ID : test .labelID }).(* Label )
100
+ doer := AssertExistsAndLoadBean (t , & User {ID : test .doerID }).(* User )
101
+ assert .NoError (t , issue .AddLabel (doer , label ))
102
+ AssertExistsAndLoadBean (t , & IssueLabel {IssueID : test .issueID , LabelID : test .labelID })
103
+ }
104
+ }
105
+
106
+ func TestIssue_AddLabels (t * testing.T ) {
107
+ var tests = []struct {
108
+ issueID int64
109
+ labelIDs []int64
110
+ doerID int64
111
+ }{
112
+ {1 , []int64 {1 , 2 }, 2 }, // non-pull-request
113
+ {1 , []int64 {}, 2 }, // non-pull-request, empty
114
+ {2 , []int64 {1 , 2 }, 2 }, // pull-request
115
+ {2 , []int64 {}, 1 }, // pull-request, empty
116
+ }
117
+ for _ , test := range tests {
118
+ assert .NoError (t , PrepareTestDatabase ())
119
+ issue := AssertExistsAndLoadBean (t , & Issue {ID : test .issueID }).(* Issue )
120
+ labels := make ([]* Label , len (test .labelIDs ))
121
+ for i , labelID := range test .labelIDs {
122
+ labels [i ] = AssertExistsAndLoadBean (t , & Label {ID : labelID }).(* Label )
123
+ }
124
+ doer := AssertExistsAndLoadBean (t , & User {ID : test .doerID }).(* User )
125
+ assert .NoError (t , issue .AddLabels (doer , labels ))
126
+ for _ , labelID := range test .labelIDs {
127
+ AssertExistsAndLoadBean (t , & IssueLabel {IssueID : test .issueID , LabelID : labelID })
128
+ }
129
+ }
130
+ }
131
+
132
+ func TestIssue_ClearLabels (t * testing.T ) {
133
+ var tests = []struct {
134
+ issueID int64
135
+ doerID int64
136
+ }{
137
+ {1 , 2 }, // non-pull-request, has labels
138
+ {2 , 2 }, // pull-request, has labels
139
+ {3 , 2 }, // pull-request, has no labels
140
+ }
141
+ for _ , test := range tests {
142
+ assert .NoError (t , PrepareTestDatabase ())
143
+ issue := AssertExistsAndLoadBean (t , & Issue {ID : test .issueID }).(* Issue )
144
+ doer := AssertExistsAndLoadBean (t , & User {ID : test .doerID }).(* User )
145
+ assert .NoError (t , issue .ClearLabels (doer ))
146
+ AssertNotExistsBean (t , & IssueLabel {IssueID : test .issueID })
147
+ }
148
+ }
0 commit comments