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.

70 lines
1.8 KiB

  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. "code.gitea.io/gitea/models"
  10. api "code.gitea.io/gitea/modules/structs"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestUserOrgs(t *testing.T) {
  14. defer prepareTestEnv(t)()
  15. adminUsername := "user1"
  16. normalUsername := "user2"
  17. session := loginUser(t, adminUsername)
  18. token := getTokenForLoggedInUser(t, session)
  19. urlStr := fmt.Sprintf("/api/v1/users/%s/orgs?token=%s", normalUsername, token)
  20. req := NewRequest(t, "GET", urlStr)
  21. resp := session.MakeRequest(t, req, http.StatusOK)
  22. var orgs []*api.Organization
  23. user3 := models.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
  24. DecodeJSON(t, resp, &orgs)
  25. assert.Equal(t, []*api.Organization{
  26. {
  27. ID: 3,
  28. UserName: user3.Name,
  29. FullName: user3.FullName,
  30. AvatarURL: user3.AvatarLink(),
  31. Description: "",
  32. Website: "",
  33. Location: "",
  34. Visibility: "public",
  35. },
  36. }, orgs)
  37. }
  38. func TestMyOrgs(t *testing.T) {
  39. defer prepareTestEnv(t)()
  40. normalUsername := "user2"
  41. session := loginUser(t, normalUsername)
  42. token := getTokenForLoggedInUser(t, session)
  43. req := NewRequest(t, "GET", "/api/v1/user/orgs?token="+token)
  44. resp := session.MakeRequest(t, req, http.StatusOK)
  45. var orgs []*api.Organization
  46. DecodeJSON(t, resp, &orgs)
  47. user3 := models.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
  48. assert.Equal(t, []*api.Organization{
  49. {
  50. ID: 3,
  51. UserName: user3.Name,
  52. FullName: user3.FullName,
  53. AvatarURL: user3.AvatarLink(),
  54. Description: "",
  55. Website: "",
  56. Location: "",
  57. Visibility: "public",
  58. },
  59. }, orgs)
  60. }