Files
core2026/app/game-engine/test/generalTurnLifecyclePersistence.test.ts
T
Hide_D 8c26a30977 feat: 명예의 전당에 유산 획득량을 추가
명장 일람과 같은 inherit_earned 기록을 은퇴와 통일 정산에서 Hall에 보존하고 기수별 순위로 표시한다. API, 저장 경로와 실제 Chromium 회귀 검사를 함께 보강한다.
2026-08-23 15:10:10 +00:00

165 lines
5.6 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import type { GamePrisma } from '@sammo-ts/infra';
import { LogCategory, LogScope } from '@sammo-ts/logic';
import { persistGeneralLifecycleEvents } from '../src/turn/generalTurnLifecyclePersistence.js';
import type { GeneralLifecycleEvent } from '../src/turn/inMemoryWorld.js';
import type { TurnGeneral } from '../src/turn/types.js';
const archivedGeneral = (): TurnGeneral => ({
id: 91,
userId: null,
name: '기록장수',
nationId: 0,
cityId: 1,
troopId: 0,
stats: { leadership: 80, strength: 70, intelligence: 60 },
experience: 1_000,
dedication: 500,
officerLevel: 0,
role: {
personality: null,
specialDomestic: null,
specialWar: null,
items: { horse: null, weapon: null, book: null, item: null },
},
injury: 0,
gold: 1_000,
rice: 1_000,
crew: 0,
crewTypeId: 1,
train: 0,
atmos: 0,
age: 70,
npcState: 2,
bornYear: 170,
deadYear: 240,
affinity: 50,
triggerState: { flags: {}, counters: {}, modifiers: {}, meta: {} },
meta: {
killturn: 0,
dex1: 1_000,
inheritRandomUnique: true,
inheritSpecificSpecialWar: true,
},
turnTime: new Date('0200-01-01T00:00:00.000Z'),
});
describe('general lifecycle archive history', () => {
it('stores the general history in descending log order when a general is deleted', async () => {
const general = archivedGeneral();
const upsert = vi.fn(async () => undefined);
const prisma = {
generalAccessLog: {
updateMany: vi.fn(async () => ({ count: 1 })),
deleteMany: vi.fn(async () => ({ count: 1 })),
},
logEntry: {
findMany: vi.fn(async () => [
{ category: LogCategory.BATTLE_BRIEF, text: '둘째 전투 결과' },
{ category: LogCategory.HISTORY, text: '<Y>●</>둘째 기록' },
{ category: LogCategory.BATTLE_BRIEF, text: '첫째 전투 결과' },
{ category: LogCategory.HISTORY, text: '<C>●</>첫 기록' },
]),
},
rankData: {
findMany: vi.fn(async () => [
{ type: 'warnum', value: 2 },
{ type: 'killnum', value: 1 },
]),
},
oldGeneral: { upsert },
} as unknown as GamePrisma.TransactionClient;
const event: GeneralLifecycleEvent = {
generalId: general.id,
outcome: 'deleted',
before: general,
year: 200,
month: 1,
};
await persistGeneralLifecycleEvents(prisma, [event], { serverId: 'archive-fixture' }, {});
expect(prisma.logEntry.findMany).toHaveBeenCalledWith({
where: {
generalId: general.id,
scope: LogScope.GENERAL,
category: { in: [LogCategory.HISTORY, LogCategory.BATTLE_BRIEF] },
},
orderBy: { id: 'desc' },
select: { category: true, text: true },
});
expect(upsert).toHaveBeenCalledWith(
expect.objectContaining({
create: expect.objectContaining({
data: expect.objectContaining({
history: ['<Y>●</>둘째 기록', '<C>●</>첫 기록'],
records: { battleResult: ['둘째 전투 결과', '첫째 전투 결과'] },
availability: { battleResultLogs: true },
meta: { killturn: 0, dex1: 1_000, rank_warnum: 2, rank_killnum: 1 },
}),
}),
})
);
});
it('stores the inheritance earned rank in the hall before a rebirth resets ranks', async () => {
const general = archivedGeneral();
const hallCreateMany = vi.fn(async () => ({ count: 1 }));
const prisma = {
generalAccessLog: {
updateMany: vi.fn(async () => ({ count: 1 })),
},
rankData: {
findMany: vi.fn(async () => [{ type: 'inherit_earned', value: 4_321 }]),
updateMany: vi.fn(async () => ({ count: 1 })),
},
nation: {
findUnique: vi.fn(async () => null),
},
gameHistory: {
count: vi.fn(async () => 2),
},
hallOfFame: {
findUnique: vi.fn(async () => null),
createMany: hallCreateMany,
update: vi.fn(async () => undefined),
},
} as unknown as GamePrisma.TransactionClient;
const event: GeneralLifecycleEvent = {
generalId: general.id,
outcome: 'retired',
before: general,
after: general,
year: 200,
month: 1,
};
await persistGeneralLifecycleEvents(
prisma,
[event],
{ serverId: 'hall-fixture', season: 4, scenarioId: 22, isUnited: 0 },
{}
);
expect(hallCreateMany).toHaveBeenCalledWith({
data: [
expect.objectContaining({
serverId: 'hall-fixture',
season: 4,
scenario: 22,
generalNo: general.id,
type: 'inherit_earned',
value: 4_321,
}),
],
skipDuplicates: true,
});
expect(prisma.rankData.updateMany).toHaveBeenCalledWith({
where: { generalId: general.id },
data: { value: 0 },
});
});
});