2024-03-27 21:54:32 +01:00
|
|
|
// 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
|
2024-04-26 16:07:23 +02:00
|
|
|
board, err := projectWithoutDefault.GetDefaultBoard(db.DefaultContext)
|
2024-03-27 21:54:32 +01:00
|
|
|
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
|
2024-04-26 16:07:23 +02:00
|
|
|
board, err = projectWithMultipleDefaults.GetDefaultBoard(db.DefaultContext)
|
2024-03-27 21:54:32 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(6), board.ProjectID)
|
2024-03-28 17:14:30 +01:00
|
|
|
assert.Equal(t, int64(9), board.ID)
|
2024-03-27 21:54:32 +01:00
|
|
|
|
2024-03-28 17:14:30 +01:00
|
|
|
// set 8 as default board
|
|
|
|
assert.NoError(t, SetDefaultBoard(db.DefaultContext, board.ProjectID, 8))
|
|
|
|
|
|
|
|
// then 9 will become a non-default board
|
2024-03-27 21:54:32 +01:00
|
|
|
board, err = GetBoard(db.DefaultContext, 9)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(6), board.ProjectID)
|
|
|
|
assert.False(t, board.Default)
|
|
|
|
}
|