2018-12-09 11:19:50 +09: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 23:12:17 +09:00
|
|
|
"code.gitea.io/gitea/models"
|
2019-05-11 19:21:34 +09:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2019-01-24 23:12:17 +09:00
|
|
|
|
2018-12-09 11:19:50 +09:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserOrgs(t *testing.T) {
|
2019-11-26 08:21:37 +09:00
|
|
|
defer prepareTestEnv(t)()
|
2018-12-09 11:19:50 +09:00
|
|
|
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 23:12:17 +09:00
|
|
|
user3 := models.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
|
|
|
|
|
2018-12-09 11:19:50 +09:00
|
|
|
DecodeJSON(t, resp, &orgs)
|
|
|
|
|
|
|
|
assert.Equal(t, []*api.Organization{
|
|
|
|
{
|
|
|
|
ID: 3,
|
2019-01-24 23:12:17 +09:00
|
|
|
UserName: user3.Name,
|
|
|
|
FullName: user3.FullName,
|
|
|
|
AvatarURL: user3.AvatarLink(),
|
2018-12-09 11:19:50 +09:00
|
|
|
Description: "",
|
|
|
|
Website: "",
|
|
|
|
Location: "",
|
2019-05-31 02:57:55 +09:00
|
|
|
Visibility: "public",
|
2018-12-09 11:19:50 +09:00
|
|
|
},
|
|
|
|
}, orgs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMyOrgs(t *testing.T) {
|
2019-11-26 08:21:37 +09:00
|
|
|
defer prepareTestEnv(t)()
|
2018-12-09 11:19:50 +09:00
|
|
|
|
|
|
|
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 23:12:17 +09:00
|
|
|
user3 := models.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
|
2018-12-09 11:19:50 +09:00
|
|
|
|
|
|
|
assert.Equal(t, []*api.Organization{
|
|
|
|
{
|
|
|
|
ID: 3,
|
2019-01-24 23:12:17 +09:00
|
|
|
UserName: user3.Name,
|
|
|
|
FullName: user3.FullName,
|
|
|
|
AvatarURL: user3.AvatarLink(),
|
2018-12-09 11:19:50 +09:00
|
|
|
Description: "",
|
|
|
|
Website: "",
|
|
|
|
Location: "",
|
2019-05-31 02:57:55 +09:00
|
|
|
Visibility: "public",
|
2018-12-09 11:19:50 +09:00
|
|
|
},
|
|
|
|
}, orgs)
|
|
|
|
}
|