fix(dynasty): normalize archived nation records

This commit is contained in:
2026-07-31 15:28:04 +00:00
parent 6e8f048876
commit 8a17412fcd
9 changed files with 266 additions and 56 deletions
@@ -0,0 +1,41 @@
import { describe, expect, it } from 'vitest';
import type { Nation } from '@sammo-ts/logic';
import { buildOldNationArchiveData } from '../src/turn/oldNationArchive.js';
describe('old nation archive data', () => {
it('writes one canonical public shape for winner and deleted-nation readers', () => {
const nation: Nation = {
id: 2,
name: '위',
color: '#0000ff',
capitalCityId: 3,
chiefGeneralId: 7,
gold: 1_000,
rice: 2_000,
power: 8_000,
level: 5,
typeCode: 'che_법가',
meta: {
tech: 3_000,
aux: { legacy: 'preserved' },
max_power: { maxPower: 20_000, maxCrew: 80_000, maxCities: ['허창'] },
},
};
expect(buildOldNationArchiveData({ nation, generalIds: [7, 8], history: ['위가 멸망'] })).toMatchObject({
nation: 2,
name: '위',
type: 'che_법가',
typeCode: 'che_법가',
tech: 3_000,
power: 8_000,
maxPower: 20_000,
maxCrew: 80_000,
maxCities: ['허창'],
aux: { legacy: 'preserved', maxPower: 20_000, maxCrew: 80_000, maxCities: ['허창'] },
generals: [7, 8],
history: ['위가 멸망'],
});
});
});
@@ -330,6 +330,26 @@ integration('unification finalization transaction', () => {
expect(await db.inheritanceResult.count({ where: { serverId } })).toBe(1);
expect(await db.oldGeneral.count({ where: { serverId } })).toBe(1);
expect(await db.oldNation.count({ where: { serverId } })).toBe(2);
expect(
(
await db.oldNation.findUniqueOrThrow({
where: {
serverId_nation_sourceId: { serverId, nation: fixtureId, sourceId: 0 },
},
})
).data
).toMatchObject({
nation: fixtureId,
name: '원자통일국',
type: 'che_중립',
typeCode: 'che_중립',
tech: 123,
maxPower: 3_500,
maxCrew: 400,
maxCities: ['원자도시'],
aux: { maxPower: 3_500, maxCrew: 400, maxCities: ['원자도시'] },
generals: [fixtureId],
});
expect(await db.emperor.count({ where: { serverId } })).toBe(1);
expect(
(await db.inheritancePoint.findUniqueOrThrow({ where: { userId_key: { userId, key: 'previous' } } }))