2020-08-16 22:07:38 -05:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-08-16 22:07:38 -05:00
|
|
|
|
2022-03-29 09:16:31 -05:00
|
|
|
package project
|
2020-08-16 22:07:38 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-05-20 09:08:52 -05:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-11-12 09:36:47 -05:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2020-08-16 22:07:38 -05:00
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsProjectTypeValid(t *testing.T) {
|
2022-03-29 09:16:31 -05:00
|
|
|
const UnknownType Type = 15
|
2020-08-16 22:07:38 -05:00
|
|
|
|
2021-03-14 13:52:12 -05:00
|
|
|
cases := []struct {
|
2022-03-29 09:16:31 -05:00
|
|
|
typ Type
|
2020-08-16 22:07:38 -05:00
|
|
|
valid bool
|
|
|
|
}{
|
2023-03-17 08:07:23 -05:00
|
|
|
{TypeIndividual, true},
|
2022-03-29 09:16:31 -05:00
|
|
|
{TypeRepository, true},
|
2023-01-20 06:42:33 -05:00
|
|
|
{TypeOrganization, true},
|
2020-08-16 22:07:38 -05:00
|
|
|
{UnknownType, false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range cases {
|
2022-03-29 09:16:31 -05:00
|
|
|
assert.Equal(t, v.valid, IsTypeValid(v.typ))
|
2020-08-16 22:07:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetProjects(t *testing.T) {
|
2021-11-12 09:36:47 -05:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2020-08-16 22:07:38 -05:00
|
|
|
|
2023-01-20 06:42:33 -05:00
|
|
|
projects, _, err := FindProjects(db.DefaultContext, SearchOptions{RepoID: 1})
|
2020-08-16 22:07:38 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// 1 value for this repo exists in the fixtures
|
|
|
|
assert.Len(t, projects, 1)
|
|
|
|
|
2023-01-20 06:42:33 -05:00
|
|
|
projects, _, err = FindProjects(db.DefaultContext, SearchOptions{RepoID: 3})
|
2020-08-16 22:07:38 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// 1 value for this repo exists in the fixtures
|
|
|
|
assert.Len(t, projects, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProject(t *testing.T) {
|
2021-11-12 09:36:47 -05:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2020-08-16 22:07:38 -05:00
|
|
|
|
|
|
|
project := &Project{
|
2022-03-29 09:16:31 -05:00
|
|
|
Type: TypeRepository,
|
|
|
|
BoardType: BoardTypeBasicKanban,
|
2023-02-11 03:12:41 -05:00
|
|
|
CardType: CardTypeTextOnly,
|
2020-08-16 22:07:38 -05:00
|
|
|
Title: "New Project",
|
|
|
|
RepoID: 1,
|
|
|
|
CreatedUnix: timeutil.TimeStampNow(),
|
|
|
|
CreatorID: 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, NewProject(project))
|
|
|
|
|
2022-05-20 09:08:52 -05:00
|
|
|
_, err := GetProjectByID(db.DefaultContext, project.ID)
|
2020-08-16 22:07:38 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Update project
|
|
|
|
project.Title = "Updated title"
|
2022-05-20 09:08:52 -05:00
|
|
|
assert.NoError(t, UpdateProject(db.DefaultContext, project))
|
2020-08-16 22:07:38 -05:00
|
|
|
|
2022-05-20 09:08:52 -05:00
|
|
|
projectFromDB, err := GetProjectByID(db.DefaultContext, project.ID)
|
2020-08-16 22:07:38 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, project.Title, projectFromDB.Title)
|
|
|
|
|
|
|
|
assert.NoError(t, ChangeProjectStatus(project, true))
|
|
|
|
|
|
|
|
// Retrieve from DB afresh to check if it is truly closed
|
2022-05-20 09:08:52 -05:00
|
|
|
projectFromDB, err = GetProjectByID(db.DefaultContext, project.ID)
|
2020-08-16 22:07:38 -05:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.True(t, projectFromDB.IsClosed)
|
|
|
|
}
|