Ejemplo n.º 1
0
func TestDisconnectedFromServer(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()

	e := rpc.Event{
		Name:    rpc.DisconnectedFromServer,
		LobbyID: lobby.ID,
	}

	e.Handle(e, &struct{}{})
	assert.Equal(t, lobby.CurrentState(), models.LobbyStateEnded)
}
Ejemplo n.º 2
0
func TestPlayerConn(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	player := testhelpers.CreatePlayer()

	lobby.AddPlayer(player, 0, "")
	db.DB.Table("lobby_slots").Where("lobby_id = ? AND player_id = ?", lobby.ID, player.ID).UpdateColumn("in_game", false)
	e := rpc.Event{
		Name:     rpc.PlayerConnected,
		LobbyID:  lobby.ID,
		PlayerID: player.ID,
	}
	e.Handle(e, &struct{}{})

	var count int
	db.DB.Table("lobby_slots").Where("lobby_id = ? AND player_id = ? AND in_game = ?", lobby.ID, player.ID, true).Count(&count)
	assert.Equal(t, count, 1)
}
Ejemplo n.º 3
0
func TestMatchEnded(t *testing.T) {
	t.Parallel()
	lobby := testhelpers.CreateLobby()
	player := testhelpers.CreatePlayer()

	lobby.Type = models.LobbyTypeBball
	lobby.Save()
	lobby.AddPlayer(player, 0, "")

	e := rpc.Event{
		Name:    rpc.MatchEnded,
		LobbyID: lobby.ID,
	}

	e.Handle(e, &struct{}{})
	db.DB.Preload("Stats").First(player, player.ID)
	assert.Equal(t, player.Stats.PlayedBballCount, 1)

	lobby = testhelpers.CreateLobby()

	lobby.Type = models.LobbyTypeBball
	lobby.Save()
	lobby.AddPlayer(player, 0, "")

	e.LobbyID = lobby.ID
	e.Handle(e, &struct{}{})
	db.DB.Preload("Stats").First(player, player.ID)
	assert.Equal(t, player.Stats.PlayedBballCount, 2)
	assert.Equal(t, player.Stats.TotalLobbies(), 2)
}