mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-25 03:00:04 +02:00
Move issue label operations to issue service package (#8553)
* Move issue label operations to issue service package * fix test * fix fmt
This commit is contained in:
parent
240f46a422
commit
280f4bebbf
7 changed files with 168 additions and 138 deletions
|
@ -84,53 +84,6 @@ func TestGetParticipantsByIssueID(t *testing.T) {
|
|||
checkParticipants(1, []int{5})
|
||||
}
|
||||
|
||||
func TestIssue_AddLabel(t *testing.T) {
|
||||
var tests = []struct {
|
||||
issueID int64
|
||||
labelID int64
|
||||
doerID int64
|
||||
}{
|
||||
{1, 2, 2}, // non-pull-request, not-already-added label
|
||||
{1, 1, 2}, // non-pull-request, already-added label
|
||||
{2, 2, 2}, // pull-request, not-already-added label
|
||||
{2, 1, 2}, // pull-request, already-added label
|
||||
}
|
||||
for _, test := range tests {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
issue := AssertExistsAndLoadBean(t, &Issue{ID: test.issueID}).(*Issue)
|
||||
label := AssertExistsAndLoadBean(t, &Label{ID: test.labelID}).(*Label)
|
||||
doer := AssertExistsAndLoadBean(t, &User{ID: test.doerID}).(*User)
|
||||
assert.NoError(t, issue.AddLabel(doer, label))
|
||||
AssertExistsAndLoadBean(t, &IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue_AddLabels(t *testing.T) {
|
||||
var tests = []struct {
|
||||
issueID int64
|
||||
labelIDs []int64
|
||||
doerID int64
|
||||
}{
|
||||
{1, []int64{1, 2}, 2}, // non-pull-request
|
||||
{1, []int64{}, 2}, // non-pull-request, empty
|
||||
{2, []int64{1, 2}, 2}, // pull-request
|
||||
{2, []int64{}, 1}, // pull-request, empty
|
||||
}
|
||||
for _, test := range tests {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
issue := AssertExistsAndLoadBean(t, &Issue{ID: test.issueID}).(*Issue)
|
||||
labels := make([]*Label, len(test.labelIDs))
|
||||
for i, labelID := range test.labelIDs {
|
||||
labels[i] = AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
|
||||
}
|
||||
doer := AssertExistsAndLoadBean(t, &User{ID: test.doerID}).(*User)
|
||||
assert.NoError(t, issue.AddLabels(doer, labels))
|
||||
for _, labelID := range test.labelIDs {
|
||||
AssertExistsAndLoadBean(t, &IssueLabel{IssueID: test.issueID, LabelID: labelID})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue_ClearLabels(t *testing.T) {
|
||||
var tests = []struct {
|
||||
issueID int64
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue