Players can now join by their authenticatied account to lobbies. Only one account can join to a specific lobby.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package state
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gofrs/uuid/v5"
|
|
"github.com/stretchr/testify/require"
|
|
"medad.fun/internal/config"
|
|
"medad.fun/internal/game"
|
|
)
|
|
|
|
//nolint:paralleltest //this test is very stateful
|
|
func TestAddAndRemove(t *testing.T) {
|
|
require.Empty(t, lobbies, "Lobbies should be empty when test starts")
|
|
|
|
createLobby := func() *game.Lobby {
|
|
player, lobby, err := game.CreateLobby("", "player", uuid.Must(uuid.NewV4()), "dutch", true, 100, 10, 10, 3, 3, 1, nil, game.ChillScoring)
|
|
require.NoError(t, err)
|
|
lobby.OnPlayerDisconnect(player)
|
|
return lobby
|
|
}
|
|
lobbyA := createLobby()
|
|
lobbyB := createLobby()
|
|
lobbyC := createLobby()
|
|
|
|
AddLobby(lobbyA)
|
|
AddLobby(lobbyB)
|
|
AddLobby(lobbyC)
|
|
|
|
require.NotNil(t, GetLobby(lobbyA.LobbyID))
|
|
require.NotNil(t, GetLobby(lobbyB.LobbyID))
|
|
require.NotNil(t, GetLobby(lobbyC.LobbyID))
|
|
|
|
RemoveLobby(lobbyB.LobbyID)
|
|
require.Nil(t, GetLobby(lobbyB.LobbyID), "Lobby B should have been deleted.")
|
|
|
|
require.NotNil(t, GetLobby(lobbyA.LobbyID), "Lobby A shouldn't have been deleted.")
|
|
require.NotNil(t, GetLobby(lobbyC.LobbyID), "Lobby C shouldn't have been deleted.")
|
|
require.Len(t, lobbies, 2)
|
|
|
|
cleanupRoutineLogic(&config.LobbyCleanup{})
|
|
require.Empty(t, lobbies)
|
|
}
|