code.gitea.io/gitea@v1.22.3/tests/integration/api_repo_git_notes_test.go (about) 1 // Copyright 2021 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 auth_model "code.gitea.io/gitea/models/auth" 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 TestAPIReposGitNotes(t *testing.T) { 20 onGiteaRun(t, func(*testing.T, *url.URL) { 21 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) 22 // Login as User2. 23 session := loginUser(t, user.Name) 24 token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) 25 26 // check invalid requests 27 req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/12345", user.Name). 28 AddTokenAuth(token) 29 MakeRequest(t, req, http.StatusNotFound) 30 31 req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/..", user.Name). 32 AddTokenAuth(token) 33 MakeRequest(t, req, http.StatusUnprocessableEntity) 34 35 // check valid request 36 req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/65f1bf27bc3bf70f64657658635e66094edbcb4d", user.Name). 37 AddTokenAuth(token) 38 resp := MakeRequest(t, req, http.StatusOK) 39 40 var apiData api.Note 41 DecodeJSON(t, resp, &apiData) 42 assert.Equal(t, "This is a test note\n", apiData.Message) 43 assert.NotEmpty(t, apiData.Commit.Files) 44 assert.NotNil(t, apiData.Commit.RepoCommit.Verification) 45 }) 46 }