2018-07-18 05:23:58 +08:00
|
|
|
// Copyright 2018 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 models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-11-12 22:36:47 +08:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 17:49:20 +08:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-17 20:34:35 +08:00
|
|
|
|
2018-07-18 05:23:58 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateIssueDependency(t *testing.T) {
|
|
|
|
// Prepare
|
2021-11-12 22:36:47 +08:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2018-07-18 05:23:58 +08:00
|
|
|
|
2021-11-24 17:49:20 +08:00
|
|
|
user1, err := user_model.GetUserByID(1)
|
2018-07-18 05:23:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
issue1, err := GetIssueByID(1)
|
|
|
|
assert.NoError(t, err)
|
2018-12-13 23:55:43 +08:00
|
|
|
|
2018-07-18 05:23:58 +08:00
|
|
|
issue2, err := GetIssueByID(2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Create a dependency and check if it was successful
|
|
|
|
err = CreateIssueDependency(user1, issue1, issue2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Do it again to see if it will check if the dependency already exists
|
|
|
|
err = CreateIssueDependency(user1, issue1, issue2)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrDependencyExists(err))
|
|
|
|
|
|
|
|
// Check for circular dependencies
|
|
|
|
err = CreateIssueDependency(user1, issue2, issue1)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrCircularDependency(err))
|
|
|
|
|
2021-11-16 16:53:21 +08:00
|
|
|
_ = unittest.AssertExistsAndLoadBean(t, &Comment{Type: CommentTypeAddDependency, PosterID: user1.ID, IssueID: issue1.ID})
|
2018-07-18 05:23:58 +08:00
|
|
|
|
|
|
|
// Check if dependencies left is correct
|
|
|
|
left, err := IssueNoDependenciesLeft(issue1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, left)
|
|
|
|
|
|
|
|
// Close #2 and check again
|
2022-03-29 22:57:33 +08:00
|
|
|
_, err = ChangeIssueStatus(issue2, user1, true)
|
2018-07-18 05:23:58 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
left, err = IssueNoDependenciesLeft(issue1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, left)
|
|
|
|
|
|
|
|
// Test removing the dependency
|
|
|
|
err = RemoveIssueDependency(user1, issue1, issue2, DependencyTypeBlockedBy)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|