Backend (services/): make the app testable and fill real gaps. - Extract buildApp() factory; index.ts owns listen()/matcher tick - Real Apple/Google identity verification via jose JWKS (iss/aud/sub) - Guest -> OAuth account linking (POST /auth/link), rebind in place - POST /matches/:id/complete: record match + participants, update leaderboard, idempotent, guarded by server-to-server secret - Extract pure matchmaking pairing (computePairings); fix ticket deckId loss on match; map ZodError -> 400; @fastify/cors - vitest suite (40 tests), initial Prisma migration, prisma schema path Web (web/): new Vite + React + TS client. - Typed API client with one-shot 401 refresh/retry, localStorage auth - Login (guest), deck builder (slot-0 hero rule), queue polling, leaderboard; 11 tests, clean build Game (Assets/, Unity C#): champion-select layout now fits the roster size; add Golem and Bandit champions. Docs: root DEVELOPMENT.md tying game + services + web together. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
||
import { computePairings, QueuedPlayer } from "../src/modules/matchmaking/matcher";
|
||
|
||
const p = (id: string, mmr: number): QueuedPlayer => ({ id, mmr });
|
||
const ids = (pairs: [QueuedPlayer, QueuedPlayer][]) =>
|
||
pairs.map(([a, b]) => [a.id, b.id]);
|
||
|
||
describe("computePairings", () => {
|
||
it("returns no pairs for an empty or single-player pool", () => {
|
||
expect(computePairings([], 150)).toEqual([]);
|
||
expect(computePairings([p("a", 1000)], 150)).toEqual([]);
|
||
});
|
||
|
||
it("pairs two players whose MMR gap is within the window", () => {
|
||
const pairs = computePairings([p("a", 1000), p("b", 1100)], 150);
|
||
expect(ids(pairs)).toEqual([["a", "b"]]);
|
||
});
|
||
|
||
it("does not pair players whose MMR gap exceeds the window", () => {
|
||
expect(computePairings([p("a", 1000), p("b", 1200)], 150)).toEqual([]);
|
||
});
|
||
|
||
it("treats a gap exactly equal to the window as matchable", () => {
|
||
const pairs = computePairings([p("a", 1000), p("b", 1150)], 150);
|
||
expect(ids(pairs)).toEqual([["a", "b"]]);
|
||
});
|
||
|
||
it("consumes the second player so three-in-a-row yields one pair", () => {
|
||
const pairs = computePairings([p("a", 1000), p("b", 1050), p("c", 1090)], 150);
|
||
expect(ids(pairs)).toEqual([["a", "b"]]);
|
||
});
|
||
|
||
it("forms multiple independent pairs across a larger pool", () => {
|
||
const pool = [p("a", 1000), p("b", 1010), p("c", 1500), p("d", 1520)];
|
||
expect(ids(computePairings(pool, 150))).toEqual([
|
||
["a", "b"],
|
||
["c", "d"],
|
||
]);
|
||
});
|
||
|
||
it("skips an out-of-window neighbor but still matches the next viable pair", () => {
|
||
// a is stranded (b is >150 away); b–c are within window and pair up.
|
||
const pool = [p("a", 1000), p("b", 1300), p("c", 1320)];
|
||
expect(ids(computePairings(pool, 150))).toEqual([["b", "c"]]);
|
||
});
|
||
});
|