2020-10-17 06:23:08 +02:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-10-17 06:23:08 +02:00
|
|
|
|
|
|
|
package convert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-11-12 15:36:47 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-06-26 21:53:14 +02:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2021-05-12 06:13:42 +02:00
|
|
|
|
2020-10-17 06:23:08 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUser_ToUser(t *testing.T) {
|
2021-11-12 15:36:47 +01:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2020-10-17 06:23:08 +02:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1, IsAdmin: true})
|
2020-10-17 06:23:08 +02:00
|
|
|
|
2021-03-27 17:45:26 +01:00
|
|
|
apiUser := toUser(user1, true, true)
|
2020-10-17 06:23:08 +02:00
|
|
|
assert.True(t, apiUser.IsAdmin)
|
2021-10-25 07:01:16 +02:00
|
|
|
assert.Contains(t, apiUser.AvatarURL, "://")
|
2020-10-17 06:23:08 +02:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2, IsAdmin: false})
|
2020-10-17 06:23:08 +02:00
|
|
|
|
2021-03-27 17:45:26 +01:00
|
|
|
apiUser = toUser(user2, true, true)
|
2020-10-17 06:23:08 +02:00
|
|
|
assert.False(t, apiUser.IsAdmin)
|
|
|
|
|
2021-03-27 17:45:26 +01:00
|
|
|
apiUser = toUser(user1, false, false)
|
2020-10-17 06:23:08 +02:00
|
|
|
assert.False(t, apiUser.IsAdmin)
|
2021-06-26 21:53:14 +02:00
|
|
|
assert.EqualValues(t, api.VisibleTypePublic.String(), apiUser.Visibility)
|
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
user31 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate})
|
2021-06-26 21:53:14 +02:00
|
|
|
|
|
|
|
apiUser = toUser(user31, true, true)
|
|
|
|
assert.False(t, apiUser.IsAdmin)
|
|
|
|
assert.EqualValues(t, api.VisibleTypePrivate.String(), apiUser.Visibility)
|
2020-10-17 06:23:08 +02:00
|
|
|
}
|