feat(social): hide social controls on a deleted opponent's seat
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 29s
CI / integration (pull_request) Successful in 20s
CI / ui (pull_request) Successful in 1m17s
CI / conformance (pull_request) Successful in 11s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m49s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 29s
CI / integration (pull_request) Successful in 20s
CI / ui (pull_request) Successful in 1m17s
CI / conformance (pull_request) Successful in 11s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m49s
A deleted account keeps its seats in every shared game, so its opponents
still saw the add-friend and block controls on the scoreboard (deletion
drops the friendship, so the 🤝 even reappeared for a former friend) and
a chat composer nobody was behind. A friend request sent that way was
accepted by the server and stayed pending forever.
The per-viewer game views now mark such a seat (SeatView.deleted,
resolved beside the seat display names by a batch accounts.deleted_at
lookup) and the client hides every control aimed at it: add-friend,
block, and the chat composer (message + nudge) once no reachable
opponent is left. Live events carry the game domain's seat standings and
so leave the mark unset, so the delta reducers preserve the cached one.
SendFriendRequest and Block against a tombstone are refused with
social.ErrAccountDeleted (410 account_deleted) — the source of truth for
an older client.
This commit is contained in:
@@ -5,17 +5,22 @@ package inttest
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.uber.org/zap/zaptest"
|
||||
|
||||
"scrabble/backend/internal/account"
|
||||
"scrabble/backend/internal/accountdelete"
|
||||
"scrabble/backend/internal/engine"
|
||||
"scrabble/backend/internal/game"
|
||||
"scrabble/backend/internal/server"
|
||||
"scrabble/backend/internal/social"
|
||||
)
|
||||
|
||||
// deletedFields reads a tombstoned account's retained real name and its deleted_at.
|
||||
@@ -277,6 +282,115 @@ func TestDropAllRobotGames(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestDeletedAccountRefusesSocialActions: once an opponent's account is deleted, neither a
|
||||
// friend request nor a block may target it — the client hides both controls on a deleted
|
||||
// seat, and the server refuses them for an older client. The seat's deleted mark that drives
|
||||
// that hiding is resolved by Store.DeletedIDs.
|
||||
func TestDeletedAccountRefusesSocialActions(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store := account.NewStore(testDB)
|
||||
svc := newSocialService()
|
||||
deleter := accountdelete.NewDeleter(testDB)
|
||||
|
||||
_, seats := newGameWithSeats(t, 2) // a shared game: the befriend-an-opponent gate
|
||||
viewer, gone := seats[0], seats[1]
|
||||
|
||||
if err := svc.SendFriendRequest(ctx, viewer, gone); err != nil {
|
||||
t.Fatalf("friend request before deletion = %v, want nil", err)
|
||||
}
|
||||
if err := deleter.AnonymizeAndTombstone(ctx, gone); err != nil {
|
||||
t.Fatalf("delete: %v", err)
|
||||
}
|
||||
|
||||
// Deletion dropped the pending request with the rest of the account's social rows, so
|
||||
// this is a fresh request against the tombstone — exactly what an older client sends
|
||||
// after the 🤝 reappears on the finished game's scoreboard.
|
||||
if err := svc.SendFriendRequest(ctx, viewer, gone); !errors.Is(err, social.ErrAccountDeleted) {
|
||||
t.Errorf("friend request to a deleted account = %v, want ErrAccountDeleted", err)
|
||||
}
|
||||
if err := svc.Block(ctx, viewer, gone); !errors.Is(err, social.ErrAccountDeleted) {
|
||||
t.Errorf("block of a deleted account = %v, want ErrAccountDeleted", err)
|
||||
}
|
||||
// The live opponent stays actionable — the guard is per-account, not a blanket switch.
|
||||
live := provisionAccount(t)
|
||||
if err := svc.Block(ctx, viewer, live); err != nil {
|
||||
t.Errorf("block of a live account = %v, want nil", err)
|
||||
}
|
||||
|
||||
deleted, err := store.DeletedIDs(ctx, []uuid.UUID{viewer, gone})
|
||||
if err != nil {
|
||||
t.Fatalf("deleted ids: %v", err)
|
||||
}
|
||||
if !deleted[gone] {
|
||||
t.Error("the deleted account must be marked deleted")
|
||||
}
|
||||
if deleted[viewer] {
|
||||
t.Error("a live account must not be marked deleted")
|
||||
}
|
||||
}
|
||||
|
||||
// TestGameStateMarksDeletedSeat: the per-viewer game state marks the seat of a deleted
|
||||
// opponent, which is what hides the in-game social controls (add-friend, block, chat, nudge)
|
||||
// on the client; the viewer's own live seat stays unmarked.
|
||||
func TestGameStateMarksDeletedSeat(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
games := newGameService()
|
||||
seats := []uuid.UUID{provisionAccount(t), provisionAccount(t)}
|
||||
g, err := games.Create(ctx, game.CreateParams{
|
||||
Variant: engine.VariantEnglish, Seats: seats, TurnTimeout: 24 * time.Hour, Seed: openingSeed(t),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create game: %v", err)
|
||||
}
|
||||
srv := server.New(":0", server.Deps{
|
||||
Logger: zaptest.NewLogger(t),
|
||||
DB: testDB,
|
||||
Accounts: account.NewStore(testDB),
|
||||
Games: games,
|
||||
})
|
||||
viewer, gone := seats[0], seats[1]
|
||||
|
||||
if marks := stateSeatDeleted(t, srv, g.ID, viewer); marks[0] || marks[1] {
|
||||
t.Fatalf("before deletion no seat may be marked deleted, got %v", marks)
|
||||
}
|
||||
if err := accountdelete.NewDeleter(testDB).AnonymizeAndTombstone(ctx, gone); err != nil {
|
||||
t.Fatalf("delete: %v", err)
|
||||
}
|
||||
marks := stateSeatDeleted(t, srv, g.ID, viewer)
|
||||
if marks[0] {
|
||||
t.Error("the viewer's own live seat must not be marked deleted")
|
||||
}
|
||||
if !marks[1] {
|
||||
t.Error("the deleted opponent's seat must be marked deleted")
|
||||
}
|
||||
}
|
||||
|
||||
// stateSeatDeleted fetches viewer's game state and returns the seats' deleted marks, indexed
|
||||
// by seat.
|
||||
func stateSeatDeleted(t *testing.T, srv *server.Server, gameID, viewer uuid.UUID) map[int]bool {
|
||||
t.Helper()
|
||||
rec := userGet(t, srv, "/api/v1/user/games/"+gameID.String()+"/state", viewer)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("game state = %d (%s), want 200", rec.Code, rec.Body.String())
|
||||
}
|
||||
var body struct {
|
||||
Game struct {
|
||||
Seats []struct {
|
||||
Seat int `json:"seat"`
|
||||
Deleted bool `json:"deleted"`
|
||||
} `json:"seats"`
|
||||
} `json:"game"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("decode game state: %v", err)
|
||||
}
|
||||
out := map[int]bool{}
|
||||
for _, s := range body.Game.Seats {
|
||||
out[s.Seat] = s.Deleted
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// TestDeleteStepUpEmail: an email account's delete code verifies (wrong code rejected, no
|
||||
// deeplink in the mail); a platform-only account has no email and cannot request a code.
|
||||
func TestDeleteStepUpEmail(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user