mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
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.
40 lines
1.2 KiB
40 lines
1.2 KiB
4 years ago
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||
2 years ago
|
// SPDX-License-Identifier: MIT
|
||
4 years ago
|
|
||
|
package convert
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
3 years ago
|
api "code.gitea.io/gitea/modules/structs"
|
||
4 years ago
|
|
||
4 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestUser_ToUser(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
4 years ago
|
|
||
2 years ago
|
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1, IsAdmin: true})
|
||
4 years ago
|
|
||
4 years ago
|
apiUser := toUser(user1, true, true)
|
||
4 years ago
|
assert.True(t, apiUser.IsAdmin)
|
||
3 years ago
|
assert.Contains(t, apiUser.AvatarURL, "://")
|
||
4 years ago
|
|
||
2 years ago
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2, IsAdmin: false})
|
||
4 years ago
|
|
||
4 years ago
|
apiUser = toUser(user2, true, true)
|
||
4 years ago
|
assert.False(t, apiUser.IsAdmin)
|
||
|
|
||
4 years ago
|
apiUser = toUser(user1, false, false)
|
||
4 years ago
|
assert.False(t, apiUser.IsAdmin)
|
||
3 years ago
|
assert.EqualValues(t, api.VisibleTypePublic.String(), apiUser.Visibility)
|
||
|
|
||
2 years ago
|
user31 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate})
|
||
3 years ago
|
|
||
|
apiUser = toUser(user31, true, true)
|
||
|
assert.False(t, apiUser.IsAdmin)
|
||
|
assert.EqualValues(t, api.VisibleTypePrivate.String(), apiUser.Visibility)
|
||
4 years ago
|
}
|