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.

37 lines
1.1 KiB

  1. // Copyright 2017 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. "bytes"
  7. "encoding/json"
  8. "fmt"
  9. "net/http"
  10. "testing"
  11. "code.gitea.io/gitea/models"
  12. api "code.gitea.io/sdk/gitea"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestAPITeam(t *testing.T) {
  16. prepareTestEnv(t)
  17. teamUser := models.AssertExistsAndLoadBean(t, &models.TeamUser{}).(*models.TeamUser)
  18. team := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamUser.TeamID}).(*models.Team)
  19. user := models.AssertExistsAndLoadBean(t, &models.User{ID: teamUser.UID}).(*models.User)
  20. session := loginUser(t, user.Name, "password")
  21. url := fmt.Sprintf("/api/v1/teams/%d", teamUser.TeamID)
  22. req := NewRequest(t, "GET", url)
  23. resp := session.MakeRequest(t, req)
  24. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  25. var apiTeam api.Team
  26. decoder := json.NewDecoder(bytes.NewBuffer(resp.Body))
  27. assert.NoError(t, decoder.Decode(&apiTeam))
  28. assert.EqualValues(t, team.ID, apiTeam.ID)
  29. assert.Equal(t, team.Name, apiTeam.Name)
  30. }