From db6c2bfd8fa2a1562c1a48a0091c5ba940e5933b Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 10 Jun 2018 11:41:10 +0200 Subject: [PATCH] made tests work again --- models/user_test.go | 27 +++++++++------------------ models/users_list.go | 1 - 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/models/user_test.go b/models/user_test.go index 34e01022..f606fe58 100644 --- a/models/user_test.go +++ b/models/user_test.go @@ -15,11 +15,9 @@ func TestCreateUser(t *testing.T) { // Our dummy user for testing dummyuser := User{ - Name: "noooem, dief", Username: "testuu", Password: "1234", Email: "noone@example.com", - IsAdmin: true, } // Delete every preexisting user to have a fresh start @@ -35,33 +33,29 @@ func TestCreateUser(t *testing.T) { } // Create a new user - createdUser, err := CreateUser(dummyuser, &doer) + createdUser, err := CreateUser(dummyuser) assert.NoError(t, err) // 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) // Check if it fails to create the same user again - _, err = CreateUser(dummyuser, &doer) + _, err = CreateUser(dummyuser) assert.Error(t, err) // 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.True(t, IsErrUsernameExists(err)) // 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.True(t, IsErrUserEmailExists(err)) // Check if it fails to create a user without password and username - _, err = CreateUser(User{}, &doer) - assert.Error(t, err) - assert.True(t, IsErrNoUsernamePassword(err)) - - _, err = CreateUser(User{Name: "blub"}, &doer) + _, err = CreateUser(User{}) assert.Error(t, err) assert.True(t, IsErrNoUsernamePassword(err)) @@ -83,7 +77,7 @@ func TestCreateUser(t *testing.T) { // Check the user credentials user, err := CheckUserCredentials(&UserLogin{"testuu", "1234"}) assert.NoError(t, err) - assert.Equal(t, dummyuser.Name, user.Name) + assert.Equal(t, "testuu", user.Username) // Check wrong password (should also fail) _, err = CheckUserCredentials(&UserLogin{"testuu", "12345"}) @@ -95,15 +89,13 @@ func TestCreateUser(t *testing.T) { assert.True(t, IsErrUserDoesNotExist(err)) // Update the user - newname := "Test_te" - uuser, err := UpdateUser(User{ID: theuser.ID, Name: newname, Password: "444444"}, &doer) + uuser, err := UpdateUser(User{ID: theuser.ID, Password: "444444"}) 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.Username, uuser.Username) // Username should not change either // 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.True(t, IsErrUserDoesNotExist(err)) @@ -115,7 +107,6 @@ func TestCreateUser(t *testing.T) { // Check if it was changed user, err = CheckUserCredentials(&UserLogin{theuser.Username, newpassword}) assert.NoError(t, err) - assert.Equal(t, newname, user.Name) // Check if the searchterm works all, err := ListUsers("test") diff --git a/models/users_list.go b/models/users_list.go index 6bf4d5f9..bc91ea9f 100644 --- a/models/users_list.go +++ b/models/users_list.go @@ -8,7 +8,6 @@ func ListUsers(searchterm string) (users []User, err error) { } else { err = x. Where("username LIKE ?", "%"+searchterm+"%"). - Or("name LIKE ?", "%"+searchterm+"%"). Find(&users) }