Files
core2026/app/game-engine/test/oldNationArchive.test.ts
T
Hide_D 630bc29100 fix: 특수 유저 커맨드의 Ref 호환 경계를 보강한다
수뇌 국가 설정과 NPC 정책을 actor-bound ENGINE mutation으로 옮기고, 추방·등용·점령·멸망·아이템 폐기의 특수 분기를 Ref와 맞춘다.

요청 ID를 사용자·프로필별로 격리하고 토너먼트 손상 projection을 fail-closed하며 실제 DB 및 Ref 차등 회귀를 보강한다.
2026-08-24 12:10:57 +00:00

103 lines
3.2 KiB
TypeScript

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: ['위가 멸망'],
msg: '',
scout_msg: null,
});
});
it('prefers current notice fields and preserves empty strings', () => {
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: {
notice: '',
infoText: '',
nationNotice: { msg: 'legacy notice' },
msg: 'legacy flat notice',
scout_msg: 'legacy scout message',
},
};
expect(buildOldNationArchiveData({ nation, generalIds: [], history: [] })).toMatchObject({
msg: '',
scout_msg: '',
});
});
it('falls back to both legacy notice shapes and legacy scout text', () => {
const baseNation: Nation = {
id: 2,
name: '위',
color: '#0000ff',
capitalCityId: 3,
chiefGeneralId: 7,
gold: 1_000,
rice: 2_000,
power: 8_000,
level: 5,
typeCode: 'che_법가',
meta: {
nationNotice: { msg: 'legacy notice' },
msg: 'legacy flat notice',
scout_msg: 'legacy scout message',
},
};
expect(buildOldNationArchiveData({ nation: baseNation, generalIds: [], history: [] })).toMatchObject({
msg: 'legacy notice',
scout_msg: 'legacy scout message',
});
expect(
buildOldNationArchiveData({
nation: { ...baseNation, meta: { msg: 'legacy flat notice' } },
generalIds: [],
history: [],
})
).toMatchObject({ msg: 'legacy flat notice', scout_msg: null });
});
});