made tests work again
This commit is contained in:
parent
5510249813
commit
db6c2bfd8f
2 changed files with 9 additions and 19 deletions
|
@ -15,11 +15,9 @@ func TestCreateUser(t *testing.T) {
|
||||||
|
|
||||||
// Our dummy user for testing
|
// Our dummy user for testing
|
||||||
dummyuser := User{
|
dummyuser := User{
|
||||||
Name: "noooem, dief",
|
|
||||||
Username: "testuu",
|
Username: "testuu",
|
||||||
Password: "1234",
|
Password: "1234",
|
||||||
Email: "noone@example.com",
|
Email: "noone@example.com",
|
||||||
IsAdmin: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete every preexisting user to have a fresh start
|
// Delete every preexisting user to have a fresh start
|
||||||
|
@ -35,33 +33,29 @@ func TestCreateUser(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new user
|
// Create a new user
|
||||||
createdUser, err := CreateUser(dummyuser, &doer)
|
createdUser, err := CreateUser(dummyuser)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Create a second new user
|
// Create a second new user
|
||||||
createdUser2, err := CreateUser(User{Username: dummyuser.Username + "2", Email: dummyuser.Email + "m", Password: dummyuser.Password}, &doer)
|
createdUser2, err := CreateUser(User{Username: dummyuser.Username + "2", Email: dummyuser.Email + "m", Password: dummyuser.Password})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Check if it fails to create the same user again
|
// Check if it fails to create the same user again
|
||||||
_, err = CreateUser(dummyuser, &doer)
|
_, err = CreateUser(dummyuser)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
// Check if it fails to create a user with just the same username
|
// Check if it fails to create a user with just the same username
|
||||||
_, err = CreateUser(User{Username: dummyuser.Username, Password: "fsdf"}, &doer)
|
_, err = CreateUser(User{Username: dummyuser.Username, Password: "fsdf"})
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.True(t, IsErrUsernameExists(err))
|
assert.True(t, IsErrUsernameExists(err))
|
||||||
|
|
||||||
// Check if it fails to create one with the same email
|
// Check if it fails to create one with the same email
|
||||||
_, err = CreateUser(User{Username: "noone", Password: "1234", Email: dummyuser.Email}, &doer)
|
_, err = CreateUser(User{Username: "noone", Password: "1234", Email: dummyuser.Email})
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.True(t, IsErrUserEmailExists(err))
|
assert.True(t, IsErrUserEmailExists(err))
|
||||||
|
|
||||||
// Check if it fails to create a user without password and username
|
// Check if it fails to create a user without password and username
|
||||||
_, err = CreateUser(User{}, &doer)
|
_, err = CreateUser(User{})
|
||||||
assert.Error(t, err)
|
|
||||||
assert.True(t, IsErrNoUsernamePassword(err))
|
|
||||||
|
|
||||||
_, err = CreateUser(User{Name: "blub"}, &doer)
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.True(t, IsErrNoUsernamePassword(err))
|
assert.True(t, IsErrNoUsernamePassword(err))
|
||||||
|
|
||||||
|
@ -83,7 +77,7 @@ func TestCreateUser(t *testing.T) {
|
||||||
// Check the user credentials
|
// Check the user credentials
|
||||||
user, err := CheckUserCredentials(&UserLogin{"testuu", "1234"})
|
user, err := CheckUserCredentials(&UserLogin{"testuu", "1234"})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, dummyuser.Name, user.Name)
|
assert.Equal(t, "testuu", user.Username)
|
||||||
|
|
||||||
// Check wrong password (should also fail)
|
// Check wrong password (should also fail)
|
||||||
_, err = CheckUserCredentials(&UserLogin{"testuu", "12345"})
|
_, err = CheckUserCredentials(&UserLogin{"testuu", "12345"})
|
||||||
|
@ -95,15 +89,13 @@ func TestCreateUser(t *testing.T) {
|
||||||
assert.True(t, IsErrUserDoesNotExist(err))
|
assert.True(t, IsErrUserDoesNotExist(err))
|
||||||
|
|
||||||
// Update the user
|
// Update the user
|
||||||
newname := "Test_te"
|
uuser, err := UpdateUser(User{ID: theuser.ID, Password: "444444"})
|
||||||
uuser, err := UpdateUser(User{ID: theuser.ID, Name: newname, Password: "444444"}, &doer)
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, newname, uuser.Name)
|
|
||||||
assert.Equal(t, theuser.Password, uuser.Password) // Password should not change
|
assert.Equal(t, theuser.Password, uuser.Password) // Password should not change
|
||||||
assert.Equal(t, theuser.Username, uuser.Username) // Username should not change either
|
assert.Equal(t, theuser.Username, uuser.Username) // Username should not change either
|
||||||
|
|
||||||
// Try updating one which does not exist
|
// Try updating one which does not exist
|
||||||
_, err = UpdateUser(User{ID: 99999, Username: "dg"}, &doer)
|
_, err = UpdateUser(User{ID: 99999, Username: "dg"})
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.True(t, IsErrUserDoesNotExist(err))
|
assert.True(t, IsErrUserDoesNotExist(err))
|
||||||
|
|
||||||
|
@ -115,7 +107,6 @@ func TestCreateUser(t *testing.T) {
|
||||||
// Check if it was changed
|
// Check if it was changed
|
||||||
user, err = CheckUserCredentials(&UserLogin{theuser.Username, newpassword})
|
user, err = CheckUserCredentials(&UserLogin{theuser.Username, newpassword})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, newname, user.Name)
|
|
||||||
|
|
||||||
// Check if the searchterm works
|
// Check if the searchterm works
|
||||||
all, err := ListUsers("test")
|
all, err := ListUsers("test")
|
||||||
|
|
|
@ -8,7 +8,6 @@ func ListUsers(searchterm string) (users []User, err error) {
|
||||||
} else {
|
} else {
|
||||||
err = x.
|
err = x.
|
||||||
Where("username LIKE ?", "%"+searchterm+"%").
|
Where("username LIKE ?", "%"+searchterm+"%").
|
||||||
Or("name LIKE ?", "%"+searchterm+"%").
|
|
||||||
Find(&users)
|
Find(&users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue