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_org_test.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.
  4. package integrations
  5. import (
  6. "net/http"
  7. "strings"
  8. "testing"
  9. "code.gitea.io/gitea/models"
  10. api "code.gitea.io/sdk/gitea"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestAPIOrg(t *testing.T) {
  14. prepareTestEnv(t)
  15. session := loginUser(t, "user1")
  16. token := getTokenForLoggedInUser(t, session)
  17. var org = api.CreateOrgOption{
  18. UserName: "user1_org",
  19. FullName: "User1's organization",
  20. Description: "This organization created by user1",
  21. Website: "https://try.gitea.io",
  22. Location: "Shanghai",
  23. }
  24. req := NewRequestWithJSON(t, "POST", "/api/v1/orgs?token="+token, &org)
  25. resp := session.MakeRequest(t, req, http.StatusCreated)
  26. var apiOrg api.Organization
  27. DecodeJSON(t, resp, &apiOrg)
  28. assert.Equal(t, org.UserName, apiOrg.UserName)
  29. assert.Equal(t, org.FullName, apiOrg.FullName)
  30. assert.Equal(t, org.Description, apiOrg.Description)
  31. assert.Equal(t, org.Website, apiOrg.Website)
  32. assert.Equal(t, org.Location, apiOrg.Location)
  33. models.AssertExistsAndLoadBean(t, &models.User{
  34. Name: org.UserName,
  35. LowerName: strings.ToLower(org.UserName),
  36. FullName: org.FullName,
  37. })
  38. }