예제 #1
0
func (suite *MoveAtTurnQueryTestSuite) TestHasResult() {
	var (
		gameId              game.Id         = 5
		turnNumber          game.TurnNumber = 9
		hasResult, noResult *moveAtTurnQuery
	)

	hasResult = MoveAtTurnQuery(gameId, turnNumber).(*moveAtTurnQuery)
	hasResult.Result = game.AlgebraicMove("Be5")
	hasResult.Answered = true

	noResult = MoveAtTurnQuery(gameId, turnNumber).(*moveAtTurnQuery)
	noResult.Result = game.AlgebraicMove("")
	noResult.Answered = false

	assert := assert.New(suite.T())
	assert.Equal(true, hasResult.hasResult())
	assert.Equal(false, noResult.hasResult())
}
예제 #2
0
func (suite *IntegrationTestSuite) TestGameFlow() {
	assert := assert.New(suite.T())
	var (
		ok     bool
		msg    string
		gameId game.Id
	)

	// Create Game
	ok, msg = suite.Commands.ExecCommand(
		commands.CreateGame, suite.whiteId, map[string]interface{}{
			"color": game.White,
		},
	)
	assert.Equal(true, ok, msg)

	time.Sleep(100 * time.Millisecond)

	userGames := suite.Queries.UserGames(suite.whiteId)
	assert.Equal(1, len(userGames))

	gameId = userGames[0]

	// Join Game
	ok, msg = suite.Commands.ExecCommand(
		commands.JoinGame, suite.blackId, map[string]interface{}{
			"gameId": gameId,
		},
	)
	assert.Equal(true, ok, msg)

	time.Sleep(100 * time.Millisecond)

	userGames = suite.Queries.UserGames(suite.blackId)
	assert.Equal(1, len(userGames))

	gameInfo, _ := suite.Queries.GameInformation(gameId)
	assert.Equal(queries.GameStatusStarted, gameInfo.GameStatus)

	// Make Move
	ok, msg = suite.Commands.ExecCommand(
		commands.Move, suite.whiteId, map[string]interface{}{
			"gameId": gameId,
			"move":   game.AlgebraicMove("Pb2-b4"),
		},
	)
	assert.Equal(true, ok, msg)

	time.Sleep(100 * time.Millisecond)

	gameHistory, ok := suite.Queries.GameHistory(gameId)
	assert.Equal(true, ok)

	assert.Equal(2, len(gameHistory))
}