2020-10-17 12:23:08 +08:00
|
|
|
// Copyright 2020 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 convert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-05-12 12:13:42 +08:00
|
|
|
|
2020-10-17 12:23:08 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUser_ToUser(t *testing.T) {
|
2021-05-12 12:13:42 +08:00
|
|
|
assert.NoError(t, models.PrepareTestDatabase())
|
2020-10-17 12:23:08 +08:00
|
|
|
|
|
|
|
user1 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
|
|
|
|
|
2021-03-28 00:45:26 +08:00
|
|
|
apiUser := toUser(user1, true, true)
|
2020-10-17 12:23:08 +08:00
|
|
|
assert.True(t, apiUser.IsAdmin)
|
|
|
|
|
|
|
|
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User)
|
|
|
|
|
2021-03-28 00:45:26 +08:00
|
|
|
apiUser = toUser(user2, true, true)
|
2020-10-17 12:23:08 +08:00
|
|
|
assert.False(t, apiUser.IsAdmin)
|
|
|
|
|
2021-03-28 00:45:26 +08:00
|
|
|
apiUser = toUser(user1, false, false)
|
2020-10-17 12:23:08 +08:00
|
|
|
assert.False(t, apiUser.IsAdmin)
|
|
|
|
}
|