2020-08-17 08:37:38 +05:30
|
|
|
// Copyright 2020 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.
|
|
|
|
|
2022-03-29 19:46:31 +05:30
|
|
|
package project
|
2020-08-17 08:37:38 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2020-08-17 08:37:38 +05:30
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsProjectTypeValid(t *testing.T) {
|
2022-03-29 19:46:31 +05:30
|
|
|
const UnknownType Type = 15
|
2020-08-17 08:37:38 +05:30
|
|
|
|
2021-03-15 00:22:12 +05:30
|
|
|
cases := []struct {
|
2022-03-29 19:46:31 +05:30
|
|
|
typ Type
|
2020-08-17 08:37:38 +05:30
|
|
|
valid bool
|
|
|
|
}{
|
2022-03-29 19:46:31 +05:30
|
|
|
{TypeIndividual, false},
|
|
|
|
{TypeRepository, true},
|
|
|
|
{TypeOrganization, false},
|
2020-08-17 08:37:38 +05:30
|
|
|
{UnknownType, false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range cases {
|
2022-03-29 19:46:31 +05:30
|
|
|
assert.Equal(t, v.valid, IsTypeValid(v.typ))
|
2020-08-17 08:37:38 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetProjects(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2020-08-17 08:37:38 +05:30
|
|
|
|
2022-03-29 19:46:31 +05:30
|
|
|
projects, _, err := GetProjects(SearchOptions{RepoID: 1})
|
2020-08-17 08:37:38 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// 1 value for this repo exists in the fixtures
|
|
|
|
assert.Len(t, projects, 1)
|
|
|
|
|
2022-03-29 19:46:31 +05:30
|
|
|
projects, _, err = GetProjects(SearchOptions{RepoID: 3})
|
2020-08-17 08:37:38 +05:30
|
|
|
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 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2020-08-17 08:37:38 +05:30
|
|
|
|
|
|
|
project := &Project{
|
2022-03-29 19:46:31 +05:30
|
|
|
Type: TypeRepository,
|
|
|
|
BoardType: BoardTypeBasicKanban,
|
2020-08-17 08:37:38 +05:30
|
|
|
Title: "New Project",
|
|
|
|
RepoID: 1,
|
|
|
|
CreatedUnix: timeutil.TimeStampNow(),
|
|
|
|
CreatorID: 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NoError(t, NewProject(project))
|
|
|
|
|
|
|
|
_, err := GetProjectByID(project.ID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Update project
|
|
|
|
project.Title = "Updated title"
|
|
|
|
assert.NoError(t, UpdateProject(project))
|
|
|
|
|
|
|
|
projectFromDB, err := GetProjectByID(project.ID)
|
|
|
|
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
|
|
|
|
projectFromDB, err = GetProjectByID(project.ID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.True(t, projectFromDB.IsClosed)
|
|
|
|
}
|