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.

api_label_templates_test.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "fmt"
  6. "net/http"
  7. "net/url"
  8. "strings"
  9. "testing"
  10. repo_module "code.gitea.io/gitea/modules/repository"
  11. api "code.gitea.io/gitea/modules/structs"
  12. "code.gitea.io/gitea/tests"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestAPIListLabelTemplates(t *testing.T) {
  16. defer tests.PrepareTestEnv(t)()
  17. req := NewRequest(t, "GET", "/api/v1/label/templates")
  18. resp := MakeRequest(t, req, http.StatusOK)
  19. var templateList []string
  20. DecodeJSON(t, resp, &templateList)
  21. for i := range repo_module.LabelTemplateFiles {
  22. assert.Equal(t, repo_module.LabelTemplateFiles[i].DisplayName, templateList[i])
  23. }
  24. }
  25. func TestAPIGetLabelTemplateInfo(t *testing.T) {
  26. defer tests.PrepareTestEnv(t)()
  27. // If Gitea has for some reason no Label templates, we need to skip this test
  28. if len(repo_module.LabelTemplateFiles) == 0 {
  29. return
  30. }
  31. // Use the first template for the test
  32. templateName := repo_module.LabelTemplateFiles[0].DisplayName
  33. urlStr := fmt.Sprintf("/api/v1/label/templates/%s", url.PathEscape(templateName))
  34. req := NewRequest(t, "GET", urlStr)
  35. resp := MakeRequest(t, req, http.StatusOK)
  36. var templateInfo []api.LabelTemplate
  37. DecodeJSON(t, resp, &templateInfo)
  38. labels, err := repo_module.LoadTemplateLabelsByDisplayName(templateName)
  39. assert.NoError(t, err)
  40. for i := range labels {
  41. assert.Equal(t, strings.TrimLeft(labels[i].Color, "#"), templateInfo[i].Color)
  42. assert.Equal(t, labels[i].Description, templateInfo[i].Description)
  43. assert.Equal(t, labels[i].Exclusive, templateInfo[i].Exclusive)
  44. assert.Equal(t, labels[i].Name, templateInfo[i].Name)
  45. }
  46. }