46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.ctrlz.es/mgdelacroix/craban/model"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreateGame(t *testing.T) {
|
|
th, teardown := NewTestHelper(t)
|
|
defer teardown()
|
|
|
|
user := th.NewUser()
|
|
gameName := "Awesome Game"
|
|
|
|
var game *model.Game
|
|
var gameMember *model.GameMember
|
|
var err error
|
|
|
|
t.Run("should correctly create a game", func(t *testing.T) {
|
|
game, err = th.store.Game().Create(gameName, user.ID)
|
|
require.NoError(t, err)
|
|
require.NotZero(t, game.ID)
|
|
require.Equal(t, gameName, game.Name)
|
|
require.Equal(t, user.ID, game.UserID)
|
|
})
|
|
|
|
t.Run("should correctly fetch game members", func(t *testing.T) {
|
|
gameMembers, err := th.store.Game().GetMembers(game.ID)
|
|
require.NoError(t, err)
|
|
require.Len(t, gameMembers, 1)
|
|
require.Equal(t, game.ID, gameMembers[0].GameID)
|
|
require.Equal(t, user.ID, gameMembers[0].UserID)
|
|
require.Equal(t, model.RoleGameMaster, gameMembers[0].Role)
|
|
})
|
|
|
|
t.Run("should correctly fetch member for user", func(t *testing.T) {
|
|
gameMember, err = th.store.Game().GetMember(game.ID, user.ID)
|
|
require.NoError(t, err)
|
|
require.Equal(t, game.ID, gameMember.GameID)
|
|
require.Equal(t, user.ID, gameMember.UserID)
|
|
require.Equal(t, model.RoleGameMaster, gameMember.Role)
|
|
})
|
|
}
|