mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 22:29:07 +00:00
Add tests for albums, users, site_info models
This commit is contained in:
@@ -2,6 +2,7 @@ package models_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/photoview/photoview/api/graphql/models"
|
||||
"github.com/photoview/photoview/api/test_utils"
|
||||
@@ -13,13 +14,47 @@ func TestUserRegistrationAuthorization(t *testing.T) {
|
||||
|
||||
password := "1234"
|
||||
user, err := models.RegisterUser(db, "admin", &password, true)
|
||||
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
assert.NotNil(t, user)
|
||||
assert.EqualValues(t, "admin", user.Username)
|
||||
assert.NotNil(t, user.Password)
|
||||
assert.NotEqualValues(t, "1234", user.Password) // should be hashed
|
||||
assert.True(t, user.Admin)
|
||||
|
||||
user, err = models.AuthorizeUser(db, "admin", "1234")
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
assert.NotNil(t, user)
|
||||
assert.EqualValues(t, "admin", user.Username)
|
||||
|
||||
}
|
||||
|
||||
func TestAccessToken(t *testing.T) {
|
||||
db := test_utils.DatabaseTest(t)
|
||||
|
||||
pass := "<hashed_password>"
|
||||
user := models.User{
|
||||
Username: "user1",
|
||||
Password: &pass,
|
||||
Admin: false,
|
||||
}
|
||||
|
||||
if !assert.NoError(t, db.Save(&user).Error) {
|
||||
return
|
||||
}
|
||||
|
||||
access_token, err := user.GenerateAccessToken(db)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
assert.NotNil(t, access_token)
|
||||
assert.Equal(t, user.ID, access_token.UserID)
|
||||
assert.NotEmpty(t, access_token.Value)
|
||||
assert.True(t, access_token.Expire.After(time.Now()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user