Files
galaxy-game/integration/lobby_free_tier_test.go
T
Ilia Denisov 009ea560f9
Tests · Go / test (push) Successful in 2m17s
Tests · UI / test (push) Waiting to run
feat(lobby): F8-04b hierarchical sidebar + paid-tier gate for create-game
Reshape the lobby UI from a single Overview into a two-level sidebar
(games · profile · DEV synthetic-reports) with four games sub-panels
(active-past · recruitment · invitations · private-games). Move the
`create new game` button into the private-games panel, merge the
applications section into recruitment cards as status chips, and add
DEV-only synthetic-report loader as a top-level screen.

Add a paid-tier gate at backend `lobby.game.create`: free callers get
`403 forbidden` before the lobby service is invoked. The UI hides the
private-games sub-panel + create button on free tier (DEV affordances
flag overrides). Update every integration test that creates a game to
use a new `testenv.PromoteToPaid` helper; add a new
`TestLobbyFlow_FreeUserCreateGameForbidden`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 23:53:53 +02:00

62 lines
2.0 KiB
Go

package integration_test
import (
"context"
"encoding/json"
"net/http"
"testing"
"time"
"galaxy/integration/testenv"
)
// TestLobbyFlow_FreeUserCreateGameForbidden asserts the F8-04b backend
// tier gate: a freshly registered (free-tier) account is rejected with
// `403 forbidden` when it tries to create a private game through the
// user-facing surface. The matching paid sibling
// `TestLobbyFlow_PrivateGameInviteRedeem` covers the success path with
// `testenv.PromoteToPaid`.
func TestLobbyFlow_FreeUserCreateGameForbidden(t *testing.T) {
plat := testenv.Bootstrap(t, testenv.BootstrapOptions{})
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
owner := testenv.RegisterSession(t, plat, "owner+free@example.com")
ownerID, err := owner.LookupUserID(ctx, plat)
if err != nil {
t.Fatalf("resolve owner: %v", err)
}
ownerHTTP := testenv.NewBackendUserClient(plat.Backend.HTTPURL, ownerID)
gameBody := map[string]any{
"game_name": "Free Tier Game",
"visibility": "private",
"min_players": 2,
"max_players": 4,
"start_gap_hours": 1,
"start_gap_players": 2,
"enrollment_ends_at": time.Now().Add(24 * time.Hour).UTC().Format(time.RFC3339),
"turn_schedule": "0 * * * *",
"target_engine_version": "v1.0.0",
}
raw, resp, err := ownerHTTP.Do(ctx, http.MethodPost, "/api/v1/user/lobby/games", gameBody)
if err != nil {
t.Fatalf("create private game: %v", err)
}
if resp.StatusCode != http.StatusForbidden {
t.Fatalf("expected 403 forbidden, got status=%d body=%s", resp.StatusCode, string(raw))
}
var envelope struct {
Error struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"error"`
}
if err := json.Unmarshal(raw, &envelope); err != nil {
t.Fatalf("decode error envelope: %v body=%s", err, string(raw))
}
if envelope.Error.Code != "forbidden" {
t.Fatalf("expected code=forbidden, got %q body=%s", envelope.Error.Code, string(raw))
}
}