2018-12-09 05:19:50 +03:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.package models
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2019-01-24 17:12:17 +03:00
|
|
|
"code.gitea.io/gitea/models"
|
2018-12-09 05:19:50 +03:00
|
|
|
api "code.gitea.io/sdk/gitea"
|
2019-01-24 17:12:17 +03:00
|
|
|
|
2018-12-09 05:19:50 +03:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserOrgs(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
|
|
|
adminUsername := "user1"
|
|
|
|
normalUsername := "user2"
|
|
|
|
session := loginUser(t, adminUsername)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/users/%s/orgs?token=%s", normalUsername, token)
|
|
|
|
req := NewRequest(t, "GET", urlStr)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var orgs []*api.Organization
|
2019-01-24 17:12:17 +03:00
|
|
|
user3 := models.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
|
|
|
|
|
2018-12-09 05:19:50 +03:00
|
|
|
DecodeJSON(t, resp, &orgs)
|
|
|
|
|
|
|
|
assert.Equal(t, []*api.Organization{
|
|
|
|
{
|
|
|
|
ID: 3,
|
2019-01-24 17:12:17 +03:00
|
|
|
UserName: user3.Name,
|
|
|
|
FullName: user3.FullName,
|
|
|
|
AvatarURL: user3.AvatarLink(),
|
2018-12-09 05:19:50 +03:00
|
|
|
Description: "",
|
|
|
|
Website: "",
|
|
|
|
Location: "",
|
|
|
|
},
|
|
|
|
}, orgs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMyOrgs(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
|
|
|
|
|
|
|
normalUsername := "user2"
|
|
|
|
session := loginUser(t, normalUsername)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
req := NewRequest(t, "GET", "/api/v1/user/orgs?token="+token)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var orgs []*api.Organization
|
|
|
|
DecodeJSON(t, resp, &orgs)
|
2019-01-24 17:12:17 +03:00
|
|
|
user3 := models.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
|
2018-12-09 05:19:50 +03:00
|
|
|
|
|
|
|
assert.Equal(t, []*api.Organization{
|
|
|
|
{
|
|
|
|
ID: 3,
|
2019-01-24 17:12:17 +03:00
|
|
|
UserName: user3.Name,
|
|
|
|
FullName: user3.FullName,
|
|
|
|
AvatarURL: user3.AvatarLink(),
|
2018-12-09 05:19:50 +03:00
|
|
|
Description: "",
|
|
|
|
Website: "",
|
|
|
|
Location: "",
|
|
|
|
},
|
|
|
|
}, orgs)
|
|
|
|
}
|