mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-08-24 00:21:48 +02:00
Fix https://github.com/go-gitea/gitea/pull/29874#discussion_r1542227686 - The migration of v292 will miss many projects. These projects will have no default board. This PR introduced a new migration number and removed v292 migration. - This PR also added the missed transactions on project-related operations. - Only `SetDefaultBoard` will remove duplicated defaults but not in `GetDefaultBoard` (cherry picked from commit 40cdc84b368cce8328b4b49ea5ecf1c5fa040300)
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package project
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetDefaultBoard(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
projectWithoutDefault, err := GetProjectByID(db.DefaultContext, 5)
|
|
assert.NoError(t, err)
|
|
|
|
// check if default board was added
|
|
board, err := projectWithoutDefault.getDefaultBoard(db.DefaultContext)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(5), board.ProjectID)
|
|
assert.Equal(t, "Uncategorized", board.Title)
|
|
|
|
projectWithMultipleDefaults, err := GetProjectByID(db.DefaultContext, 6)
|
|
assert.NoError(t, err)
|
|
|
|
// check if multiple defaults were removed
|
|
board, err = projectWithMultipleDefaults.getDefaultBoard(db.DefaultContext)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(6), board.ProjectID)
|
|
assert.Equal(t, int64(9), board.ID)
|
|
|
|
// set 8 as default board
|
|
assert.NoError(t, SetDefaultBoard(db.DefaultContext, board.ProjectID, 8))
|
|
|
|
// then 9 will become a non-default board
|
|
board, err = GetBoard(db.DefaultContext, 9)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, int64(6), board.ProjectID)
|
|
assert.False(t, board.Default)
|
|
}
|