You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

api_user_orgs_test.go 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2018 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.package models
  4. package integrations
  5. import (
  6. "fmt"
  7. "net/http"
  8. "testing"
  9. api "code.gitea.io/sdk/gitea"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestUserOrgs(t *testing.T) {
  13. prepareTestEnv(t)
  14. adminUsername := "user1"
  15. normalUsername := "user2"
  16. session := loginUser(t, adminUsername)
  17. token := getTokenForLoggedInUser(t, session)
  18. urlStr := fmt.Sprintf("/api/v1/users/%s/orgs?token=%s", normalUsername, token)
  19. req := NewRequest(t, "GET", urlStr)
  20. resp := session.MakeRequest(t, req, http.StatusOK)
  21. var orgs []*api.Organization
  22. DecodeJSON(t, resp, &orgs)
  23. assert.Equal(t, []*api.Organization{
  24. {
  25. ID: 3,
  26. UserName: "user3",
  27. FullName: "User Three",
  28. AvatarURL: "https://secure.gravatar.com/avatar/97d6d9441ff85fdc730e02a6068d267b?d=identicon",
  29. Description: "",
  30. Website: "",
  31. Location: "",
  32. },
  33. }, orgs)
  34. }
  35. func TestMyOrgs(t *testing.T) {
  36. prepareTestEnv(t)
  37. normalUsername := "user2"
  38. session := loginUser(t, normalUsername)
  39. token := getTokenForLoggedInUser(t, session)
  40. req := NewRequest(t, "GET", "/api/v1/user/orgs?token="+token)
  41. resp := session.MakeRequest(t, req, http.StatusOK)
  42. var orgs []*api.Organization
  43. DecodeJSON(t, resp, &orgs)
  44. assert.Equal(t, []*api.Organization{
  45. {
  46. ID: 3,
  47. UserName: "user3",
  48. FullName: "User Three",
  49. AvatarURL: "https://secure.gravatar.com/avatar/97d6d9441ff85fdc730e02a6068d267b?d=identicon",
  50. Description: "",
  51. Website: "",
  52. Location: "",
  53. },
  54. }, orgs)
  55. }