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)
|
|
|
|
}
|
2021-09-13 22:16:13 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-09-13 22:21:31 +01:00
|
|
|
err = th.store.User().DeleteByUsername(user.Username)
|
|
|
|
require.NoError(t, err)
|
2021-09-13 22:16:13 +01:00
|
|
|
|
2021-09-13 22:21:31 +01:00
|
|
|
_, err = th.store.Game().GetMember(game.ID, user.ID)
|
|
|
|
require.Error(t, err)
|
2021-09-13 22:16:13 +01:00
|
|
|
}
|