feat: 토너먼트 조별 전투 로그를 복원한다

예선과 본선 조별 경기의 최신 전투 로그를 저장하고 화면에 여덟 조 모두 표시한다. 결선은 최근 완료 경기와 종료 후 결승 로그를 유지하며 기존 대진 난수 순서를 보존한다.
This commit is contained in:
2026-08-22 04:51:46 +00:00
parent a41eb16bb9
commit e7fed61fb3
9 changed files with 345 additions and 30 deletions
@@ -179,6 +179,53 @@ const setTournamentFixture = async (redis: MemoryRedis, state: Record<string, un
};
describe('tournament router permissions and mutations', () => {
it('returns persisted group fight logs to an authenticated tournament viewer', async () => {
const redis = new MemoryRedis();
const transport = new TournamentTransport();
const general = buildGeneral(1, 'user-1');
await setTournamentFixture(redis, {
stage: 2,
phase: 1,
type: 0,
auto: true,
openYear: 193,
openMonth: 1,
termSeconds: 60,
nextAt: '2026-07-26T01:00:00.000Z',
});
await redis.set(
'sammo:che:default:tournament:matches',
JSON.stringify([
{
id: 201,
stage: 2,
roundIndex: 0,
groupId: 0,
attackerId: 11,
defenderId: 12,
winnerId: 11,
log: ['<S>●</> <Y>후보11</> <S>승리</>!'],
},
])
);
const caller = appRouter.createCaller(
buildContext({ redis, transport, generals: [general, buildGeneral(11, 'user-11')], userId: 'user-1' })
);
const snapshot = await caller.tournament.getSnapshot();
expect(snapshot.matches).toEqual([
expect.objectContaining({
stage: 2,
groupId: 0,
attackerId: 11,
defenderId: 12,
winnerId: 11,
log: ['<S>●</> <Y>후보11</> <S>승리</>!'],
}),
]);
});
it('charges the authenticated general once when joining', async () => {
const redis = new MemoryRedis();
const transport = new TournamentTransport();
@@ -359,10 +359,23 @@ describe('tournament worker (in-memory)', () => {
const prisma = createPrismaMock({ baseSeed: 'seed' });
const finalState = await runTournamentToCompletion({ store, prisma, baseSeed: 'seed' });
const matches = await store.getMatches();
const preliminaryLogs = matches.filter((match) => match.stage === 2);
const finalGroupLogs = matches.filter((match) => match.stage === 4);
const knockoutMatches = matches.filter((match) => match.stage >= 7);
const finalMatches = matches.filter((match) => match.stage === 10);
expect(finalState.stage).toBe(0);
expect(finalState.winnerId).toBe(15);
expect(preliminaryLogs).toHaveLength(8);
expect(finalGroupLogs).toHaveLength(8);
expect(knockoutMatches).toHaveLength(15);
expect(preliminaryLogs.map((match) => match.groupId).sort((a, b) => Number(a) - Number(b))).toEqual([
0, 1, 2, 3, 4, 5, 6, 7,
]);
expect(finalGroupLogs.map((match) => match.groupId).sort((a, b) => Number(a) - Number(b))).toEqual([
10, 11, 12, 13, 14, 15, 16, 17,
]);
expect([...preliminaryLogs, ...finalGroupLogs].every((match) => (match.log?.length ?? 0) >= 3)).toBe(true);
expect(finalMatches).toHaveLength(1);
expect(finalMatches[0]).toMatchObject({
attackerId: 15,