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) }
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) }
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) }