2024-03-27 20:54:32 +00:00
|
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package v1_22 //nolint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/models/migrations/base"
|
|
|
|
"code.gitea.io/gitea/models/project"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_CheckProjectColumnsConsistency(t *testing.T) {
|
|
|
|
// Prepare and load the testing database
|
|
|
|
x, deferable := base.PrepareTestEnv(t, 0, new(project.Project), new(project.Board))
|
|
|
|
defer deferable()
|
|
|
|
if x == nil || t.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, CheckProjectColumnsConsistency(x))
|
|
|
|
|
|
|
|
// check if default board was added
|
|
|
|
var defaultBoard project.Board
|
|
|
|
has, err := x.Where("project_id=? AND `default` = ?", 1, true).Get(&defaultBoard)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, has)
|
|
|
|
assert.Equal(t, int64(1), defaultBoard.ProjectID)
|
|
|
|
assert.True(t, defaultBoard.Default)
|
|
|
|
|
2024-03-28 16:14:30 +00:00
|
|
|
// check if multiple defaults, previous were removed and last will be kept
|
2024-03-27 20:54:32 +00:00
|
|
|
expectDefaultBoard, err := project.GetBoard(db.DefaultContext, 2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(2), expectDefaultBoard.ProjectID)
|
2024-03-28 16:14:30 +00:00
|
|
|
assert.False(t, expectDefaultBoard.Default)
|
2024-03-27 20:54:32 +00:00
|
|
|
|
|
|
|
expectNonDefaultBoard, err := project.GetBoard(db.DefaultContext, 3)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(2), expectNonDefaultBoard.ProjectID)
|
2024-03-28 16:14:30 +00:00
|
|
|
assert.True(t, expectNonDefaultBoard.Default)
|
2024-03-27 20:54:32 +00:00
|
|
|
}
|