fix: 유산 전투 특기 고정과 내역 스크롤 수정
초기화 시 전투 특기를 null로 정규화하고 이전 특기 배열을 보존해 다음 월 고정 배정이 daemon 재시작 없이 동작하게 한다. 다중 변경 내역이 문서 높이를 늘리도록 하고 API, 월간 persistence, 실제 Chromium 회귀 검증을 추가한다.
This commit is contained in:
@@ -72,6 +72,11 @@ const parseBuffRecord = (raw: unknown): Record<string, number> => {
|
||||
|
||||
const serializeBuffRecord = (buff: Record<string, number>): string => JSON.stringify(buff);
|
||||
|
||||
const readStringList = (raw: unknown): string[] => {
|
||||
const parsed = typeof raw === 'string' ? parseJson<unknown>(raw) : raw;
|
||||
return Array.isArray(parsed) ? parsed.filter((entry): entry is string => typeof entry === 'string') : [];
|
||||
};
|
||||
|
||||
const readBuffLevel = (buff: Record<string, number>, key: InheritBuffType): number => {
|
||||
const compatibilityKey = key === 'domesticSuccessProb' ? 'success' : key === 'domesticFailProb' ? 'fail' : null;
|
||||
return Math.max(0, Math.min(5, Math.floor(buff[key] ?? (compatibilityKey ? buff[compatibilityKey] : 0) ?? 0)));
|
||||
@@ -133,7 +138,7 @@ const patchGeneral = async (
|
||||
strength?: number;
|
||||
intelligence?: number;
|
||||
};
|
||||
specialWar?: string;
|
||||
specialWar?: string | null;
|
||||
}
|
||||
): Promise<void> => {
|
||||
const result = await ctx.turnDaemon.requestCommand({
|
||||
@@ -530,16 +535,15 @@ export const inheritRouter = router({
|
||||
}
|
||||
|
||||
const meta = asRecord(general.meta);
|
||||
const prevList =
|
||||
parseJson<string[]>(typeof meta.prev_types_special2 === 'string' ? meta.prev_types_special2 : null) ?? [];
|
||||
const prevList = readStringList(meta.prev_types_special2);
|
||||
prevList.push(general.special2Code);
|
||||
|
||||
await patchGeneral(ctx, general.id, {
|
||||
specialWar: 'None',
|
||||
specialWar: null,
|
||||
meta: {
|
||||
...meta,
|
||||
inheritResetSpecialWar: nextLevel,
|
||||
prev_types_special2: JSON.stringify(prevList),
|
||||
prev_types_special2: prevList,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -331,6 +331,90 @@ describe('inherit router actor and permission boundaries', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('reserves the selected Ref war trait and charges the authenticated owner once', async () => {
|
||||
const fixture = buildContext({
|
||||
inheritancePoint: 5_000,
|
||||
configConst: { availableSpecialWar: ['che_의술'] },
|
||||
});
|
||||
|
||||
await expect(
|
||||
appRouter.createCaller(fixture.context).inherit.setNextSpecialWar({ specialKey: 'che_의술' })
|
||||
).resolves.toEqual({ ok: true });
|
||||
|
||||
expect(fixture.requestCommand).toHaveBeenCalledWith({
|
||||
type: 'patchGeneral',
|
||||
generalId: 7,
|
||||
patch: { meta: { inheritSpecificSpecialWar: 'che_의술' } },
|
||||
});
|
||||
expect(fixture.pointUpsert).toHaveBeenCalledWith(expect.objectContaining({ update: { value: 1_000 } }));
|
||||
expect(fixture.logCreate).toHaveBeenCalledWith({
|
||||
data: {
|
||||
userId: 'user-1',
|
||||
year: 200,
|
||||
month: 4,
|
||||
text: '4000 포인트로 다음 전투 특기로 의술 지정',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('does not dispatch or charge when a different war trait is already reserved', async () => {
|
||||
const fixture = buildContext({
|
||||
inheritancePoint: 5_000,
|
||||
general: buildGeneral({ meta: { inheritSpecificSpecialWar: 'che_신산' } }),
|
||||
configConst: { availableSpecialWar: ['che_의술'] },
|
||||
});
|
||||
|
||||
await expect(
|
||||
appRouter.createCaller(fixture.context).inherit.setNextSpecialWar({ specialKey: 'che_의술' })
|
||||
).rejects.toMatchObject({ code: 'BAD_REQUEST', message: '이미 예약한 특기가 있습니다.' });
|
||||
expect(fixture.requestCommand).not.toHaveBeenCalled();
|
||||
expect(fixture.pointUpsert).not.toHaveBeenCalled();
|
||||
expect(fixture.logCreate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('resets the current war trait to the in-memory null sentinel and preserves Ref history as an array', async () => {
|
||||
const fixture = buildContext({
|
||||
inheritancePoint: 2_000,
|
||||
general: buildGeneral({ meta: { prev_types_special2: ['che_돌격'], marker: 3 } }),
|
||||
});
|
||||
|
||||
await expect(appRouter.createCaller(fixture.context).inherit.resetSpecialWar()).resolves.toEqual({ ok: true });
|
||||
|
||||
expect(fixture.requestCommand).toHaveBeenCalledWith({
|
||||
type: 'patchGeneral',
|
||||
generalId: 7,
|
||||
patch: {
|
||||
specialWar: null,
|
||||
meta: {
|
||||
prev_types_special2: ['che_돌격', 'che_선봉'],
|
||||
marker: 3,
|
||||
inheritResetSpecialWar: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(fixture.pointUpsert).toHaveBeenCalledWith(expect.objectContaining({ update: { value: 1_000 } }));
|
||||
expect(fixture.logCreate).toHaveBeenCalledWith({
|
||||
data: {
|
||||
userId: 'user-1',
|
||||
year: 200,
|
||||
month: 4,
|
||||
text: '1000 포인트로 전투 특기 초기화',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('does not dispatch or charge when the current war trait is already blank', async () => {
|
||||
const fixture = buildContext({ inheritancePoint: 2_000, general: buildGeneral({ special2Code: 'None' }) });
|
||||
|
||||
await expect(appRouter.createCaller(fixture.context).inherit.resetSpecialWar()).rejects.toMatchObject({
|
||||
code: 'BAD_REQUEST',
|
||||
message: '이미 전투 특기가 공란입니다.',
|
||||
});
|
||||
expect(fixture.requestCommand).not.toHaveBeenCalled();
|
||||
expect(fixture.pointUpsert).not.toHaveBeenCalled();
|
||||
expect(fixture.logCreate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('queues Ref-compatible nextTurnTimeBase without moving the current scheduled turn', async () => {
|
||||
const fixture = buildContext({
|
||||
inheritancePoint: 2_000,
|
||||
|
||||
Reference in New Issue
Block a user