craban/server/services/store/user_test.go

68 lines
1.6 KiB
Go
Raw Normal View History

2021-09-11 22:50:53 +01:00
package store
import (
"testing"
2021-09-12 17:57:42 +01:00
"git.ctrlz.es/mgdelacroix/craban/model"
2021-09-11 22:50:53 +01:00
"github.com/stretchr/testify/require"
)
func TestCreateUser(t *testing.T) {
th, teardown := NewTestHelper(t)
defer teardown()
user := &model.User{
Name: "John",
Mail: "john_doe@example.com",
Username: "john_doe",
Password: "mysupersecret",
}
newUser, err := th.store.User().Create(user)
require.NoError(t, err)
require.NotZero(t, newUser.ID)
require.Equal(t, user.Name, newUser.Name)
require.Equal(t, user.Mail, newUser.Mail)
require.Equal(t, user.Username, newUser.Username)
require.Equal(t, user.Password, newUser.Password)
}
func TestGetByID(t *testing.T) {
th, teardown := NewTestHelper(t)
defer teardown()
user := th.NewUser()
user2, err := th.store.User().GetByID(user.ID)
require.NoError(t, err)
require.Equal(t, user.ID, user2.ID)
require.Equal(t, user.Name, user2.Name)
require.Equal(t, user.Mail, user2.Mail)
require.Equal(t, user.Username, user2.Username)
require.Equal(t, user.Password, user2.Password)
}
func TestDeleteUsername(t *testing.T) {
th, teardown := NewTestHelper(t)
defer teardown()
user := th.NewUser()
gameName := "awesome game"
game, err := th.store.Game().Create(gameName, user.ID)
require.NoError(t, err)
gameMember, err := th.store.Game().GetMember(game.ID, user.ID)
require.NoError(t, err)
require.NotZero(t, gameMember)
// ToDo: implement member deletion
/*
err = th.store.User().DeleteByUsername(user.Username)
require.NoError(t, err)
_, err = th.store.Game().GetMember(game.ID, user.ID)
require.Error(t, err)
*/
}