|
| 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 | + |
| 5 | +package integrations |
| 6 | + |
| 7 | +import ( |
| 8 | + "fmt" |
| 9 | + "net/http" |
| 10 | + "testing" |
| 11 | + |
| 12 | + api "code.gitea.io/sdk/gitea" |
| 13 | + "github.com/stretchr/testify/assert" |
| 14 | +) |
| 15 | + |
| 16 | +func TestUserOrgs(t *testing.T) { |
| 17 | + prepareTestEnv(t) |
| 18 | + adminUsername := "user1" |
| 19 | + normalUsername := "user2" |
| 20 | + session := loginUser(t, adminUsername) |
| 21 | + token := getTokenForLoggedInUser(t, session) |
| 22 | + urlStr := fmt.Sprintf("/api/v1/users/%s/orgs?token=%s", normalUsername, token) |
| 23 | + req := NewRequest(t, "GET", urlStr) |
| 24 | + resp := session.MakeRequest(t, req, http.StatusOK) |
| 25 | + var orgs []*api.Organization |
| 26 | + DecodeJSON(t, resp, &orgs) |
| 27 | + |
| 28 | + assert.Equal(t, []*api.Organization{ |
| 29 | + { |
| 30 | + ID: 3, |
| 31 | + UserName: "user3", |
| 32 | + FullName: "User Three", |
| 33 | + AvatarURL: "https://secure.gravatar.com/avatar/97d6d9441ff85fdc730e02a6068d267b?d=identicon", |
| 34 | + Description: "", |
| 35 | + Website: "", |
| 36 | + Location: "", |
| 37 | + }, |
| 38 | + }, orgs) |
| 39 | +} |
| 40 | + |
| 41 | +func TestMyOrgs(t *testing.T) { |
| 42 | + prepareTestEnv(t) |
| 43 | + |
| 44 | + normalUsername := "user2" |
| 45 | + session := loginUser(t, normalUsername) |
| 46 | + token := getTokenForLoggedInUser(t, session) |
| 47 | + req := NewRequest(t, "GET", "/api/v1/user/orgs?token="+token) |
| 48 | + resp := session.MakeRequest(t, req, http.StatusOK) |
| 49 | + var orgs []*api.Organization |
| 50 | + DecodeJSON(t, resp, &orgs) |
| 51 | + |
| 52 | + assert.Equal(t, []*api.Organization{ |
| 53 | + { |
| 54 | + ID: 3, |
| 55 | + UserName: "user3", |
| 56 | + FullName: "User Three", |
| 57 | + AvatarURL: "https://secure.gravatar.com/avatar/97d6d9441ff85fdc730e02a6068d267b?d=identicon", |
| 58 | + Description: "", |
| 59 | + Website: "", |
| 60 | + Location: "", |
| 61 | + }, |
| 62 | + }, orgs) |
| 63 | +} |
0 commit comments