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_repo_git_notes_test.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "net/http"
  6. "net/url"
  7. "testing"
  8. auth_model "code.gitea.io/gitea/models/auth"
  9. "code.gitea.io/gitea/models/unittest"
  10. user_model "code.gitea.io/gitea/models/user"
  11. api "code.gitea.io/gitea/modules/structs"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestAPIReposGitNotes(t *testing.T) {
  15. onGiteaRun(t, func(*testing.T, *url.URL) {
  16. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
  17. // Login as User2.
  18. session := loginUser(t, user.Name)
  19. token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
  20. // check invalid requests
  21. req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/12345?token=%s", user.Name, token)
  22. MakeRequest(t, req, http.StatusNotFound)
  23. req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/..?token=%s", user.Name, token)
  24. MakeRequest(t, req, http.StatusUnprocessableEntity)
  25. // check valid request
  26. req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/notes/65f1bf27bc3bf70f64657658635e66094edbcb4d?token=%s", user.Name, token)
  27. resp := MakeRequest(t, req, http.StatusOK)
  28. var apiData api.Note
  29. DecodeJSON(t, resp, &apiData)
  30. assert.Equal(t, "This is a test note\n", apiData.Message)
  31. assert.NotEmpty(t, apiData.Commit.Files)
  32. assert.NotNil(t, apiData.Commit.RepoCommit.Verification)
  33. })
  34. }