A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB

  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/modules/timeutil"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestIsProjectTypeValid(t *testing.T) {
  11. const UnknownType ProjectType = 15
  12. cases := []struct {
  13. typ ProjectType
  14. valid bool
  15. }{
  16. {ProjectTypeIndividual, false},
  17. {ProjectTypeRepository, true},
  18. {ProjectTypeOrganization, false},
  19. {UnknownType, false},
  20. }
  21. for _, v := range cases {
  22. assert.Equal(t, v.valid, IsProjectTypeValid(v.typ))
  23. }
  24. }
  25. func TestGetProjects(t *testing.T) {
  26. assert.NoError(t, PrepareTestDatabase())
  27. projects, _, err := GetProjects(ProjectSearchOptions{RepoID: 1})
  28. assert.NoError(t, err)
  29. // 1 value for this repo exists in the fixtures
  30. assert.Len(t, projects, 1)
  31. projects, _, err = GetProjects(ProjectSearchOptions{RepoID: 3})
  32. assert.NoError(t, err)
  33. // 1 value for this repo exists in the fixtures
  34. assert.Len(t, projects, 1)
  35. }
  36. func TestProject(t *testing.T) {
  37. assert.NoError(t, PrepareTestDatabase())
  38. project := &Project{
  39. Type: ProjectTypeRepository,
  40. BoardType: ProjectBoardTypeBasicKanban,
  41. Title: "New Project",
  42. RepoID: 1,
  43. CreatedUnix: timeutil.TimeStampNow(),
  44. CreatorID: 2,
  45. }
  46. assert.NoError(t, NewProject(project))
  47. _, err := GetProjectByID(project.ID)
  48. assert.NoError(t, err)
  49. // Update project
  50. project.Title = "Updated title"
  51. assert.NoError(t, UpdateProject(project))
  52. projectFromDB, err := GetProjectByID(project.ID)
  53. assert.NoError(t, err)
  54. assert.Equal(t, project.Title, projectFromDB.Title)
  55. assert.NoError(t, ChangeProjectStatus(project, true))
  56. // Retrieve from DB afresh to check if it is truly closed
  57. projectFromDB, err = GetProjectByID(project.ID)
  58. assert.NoError(t, err)
  59. assert.True(t, projectFromDB.IsClosed)
  60. }