2019-10-19 18:48:29 +09:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package issue
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-11-12 23:36:47 +09:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 18:49:20 +09:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-17 21:34:35 +09:00
|
|
|
|
2019-10-19 18:48:29 +09:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIssue_AddLabels(t *testing.T) {
|
2022-01-21 02:46:10 +09:00
|
|
|
tests := []struct {
|
2019-10-19 18:48:29 +09:00
|
|
|
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 {
|
2021-11-12 23:36:47 +09:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 17:53:21 +09:00
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
|
2019-10-19 18:48:29 +09:00
|
|
|
labels := make([]*models.Label, len(test.labelIDs))
|
|
|
|
for i, labelID := range test.labelIDs {
|
2021-11-16 17:53:21 +09:00
|
|
|
labels[i] = unittest.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
|
2019-10-19 18:48:29 +09:00
|
|
|
}
|
2021-11-24 18:49:20 +09:00
|
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User)
|
2019-10-19 18:48:29 +09:00
|
|
|
assert.NoError(t, AddLabels(issue, doer, labels))
|
|
|
|
for _, labelID := range test.labelIDs {
|
2021-11-16 17:53:21 +09:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
|
2019-10-19 18:48:29 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssue_AddLabel(t *testing.T) {
|
2022-01-21 02:46:10 +09:00
|
|
|
tests := []struct {
|
2019-10-19 18:48:29 +09:00
|
|
|
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 {
|
2021-11-12 23:36:47 +09:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 17:53:21 +09:00
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
|
|
|
|
label := unittest.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
|
2021-11-24 18:49:20 +09:00
|
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User)
|
2019-10-19 18:48:29 +09:00
|
|
|
assert.NoError(t, AddLabel(issue, doer, label))
|
2021-11-16 17:53:21 +09:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
|
2019-10-19 18:48:29 +09:00
|
|
|
}
|
|
|
|
}
|