code.gitea.io/gitea@v1.21.7/tests/integration/api_issue_templates_test.go (about) 1 // Copyright 2024 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package integration 5 6 import ( 7 "net/http" 8 "net/url" 9 "testing" 10 11 repo_model "code.gitea.io/gitea/models/repo" 12 "code.gitea.io/gitea/models/unittest" 13 user_model "code.gitea.io/gitea/models/user" 14 api "code.gitea.io/gitea/modules/structs" 15 16 "github.com/stretchr/testify/assert" 17 ) 18 19 func TestAPIIssueTemplateList(t *testing.T) { 20 onGiteaRun(t, func(*testing.T, *url.URL) { 21 var issueTemplates []*api.IssueTemplate 22 23 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"}) 24 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "repo1"}) 25 26 // no issue template 27 req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/issue_templates") 28 resp := MakeRequest(t, req, http.StatusOK) 29 issueTemplates = nil 30 DecodeJSON(t, resp, &issueTemplates) 31 assert.Empty(t, issueTemplates) 32 33 // one correct issue template and some incorrect issue templates 34 err := createOrReplaceFileInBranch(user, repo, ".gitea/ISSUE_TEMPLATE/tmpl-ok.md", repo.DefaultBranch, `---- 35 name: foo 36 about: bar 37 ---- 38 `) 39 assert.NoError(t, err) 40 41 err = createOrReplaceFileInBranch(user, repo, ".gitea/ISSUE_TEMPLATE/tmpl-err1.yml", repo.DefaultBranch, `name: '`) 42 assert.NoError(t, err) 43 44 err = createOrReplaceFileInBranch(user, repo, ".gitea/ISSUE_TEMPLATE/tmpl-err2.yml", repo.DefaultBranch, `other: `) 45 assert.NoError(t, err) 46 47 req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/issue_templates") 48 resp = MakeRequest(t, req, http.StatusOK) 49 issueTemplates = nil 50 DecodeJSON(t, resp, &issueTemplates) 51 assert.Len(t, issueTemplates, 1) 52 assert.Equal(t, "foo", issueTemplates[0].Name) 53 assert.Equal(t, "error occurs when parsing issue template: count=2", resp.Header().Get("X-Gitea-Warning")) 54 }) 55 }