fix: 사령부 모바일 현재 턴과 NPC 대상을 호환
daemon 진행 뒤 국가 명령을 현재 슬롯에 재기준화하고 Ref 명령별 장수 대상 필터를 적용한다. 모바일 고급 편집기 12턴과 500px 8수뇌 행렬을 실제 Chromium 기준으로 복원한다.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { buildRefGeneralTargetOptions, type GeneralTargetSource } from '../src/turns/commandTargets.js';
|
||||
|
||||
const general = (overrides: Partial<GeneralTargetSource>): GeneralTargetSource => ({
|
||||
id: 1,
|
||||
name: '본인',
|
||||
nationId: 1,
|
||||
cityId: 10,
|
||||
npcState: 0,
|
||||
officerLevel: 5,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
describe('Ref command general targets', () => {
|
||||
const sources = [
|
||||
general({}),
|
||||
general({ id: 2, name: '아국유저', officerLevel: 12 }),
|
||||
general({ id: 3, name: '아국NPC', npcState: 2, officerLevel: 0 }),
|
||||
general({ id: 4, name: '타국유저', nationId: 2, cityId: 20, officerLevel: 0 }),
|
||||
general({ id: 5, name: '타국NPC', nationId: 2, cityId: 20, npcState: 3, officerLevel: 0 }),
|
||||
];
|
||||
const result = buildRefGeneralTargetOptions({
|
||||
actorId: 1,
|
||||
actorNationId: 1,
|
||||
generals: sources,
|
||||
nationNames: new Map([
|
||||
[1, '아국'],
|
||||
[2, '타국'],
|
||||
]),
|
||||
cityNames: new Map([
|
||||
[10, '업'],
|
||||
[20, '허창'],
|
||||
]),
|
||||
});
|
||||
const ids = (action: string) => result.generalTargets[action]?.map((entry) => entry.value);
|
||||
|
||||
it('includes user and NPC generals of the same nation for every Ref nation personnel command', () => {
|
||||
for (const action of ['che_발령', 'che_포상', 'che_몰수', 'che_부대탈퇴지시']) {
|
||||
expect(ids(action)).toEqual([1, 2, 3]);
|
||||
}
|
||||
});
|
||||
|
||||
it('preserves the distinct Ref filters for gift, abdication, recruitment, and target-based joining', () => {
|
||||
expect(ids('che_증여')).toEqual([1, 2, 3]);
|
||||
expect(ids('che_선양')).toEqual([2, 3]);
|
||||
expect(ids('che_등용')).toEqual([4]);
|
||||
expect(ids('che_장수대상임관')).toEqual([2, 3, 4, 5]);
|
||||
expect(result.generals.map((entry) => entry.value)).toEqual([1, 2, 4]);
|
||||
});
|
||||
});
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
setGeneralTurns,
|
||||
setNationTurn,
|
||||
setNationTurns,
|
||||
setNationTurnsAtCurrentPositions,
|
||||
shiftGeneralTurns,
|
||||
shiftNationTurns,
|
||||
ReservedTurnRevisionConflictError,
|
||||
@@ -195,7 +196,7 @@ const buildDb = () => {
|
||||
},
|
||||
} as unknown as DatabaseClient;
|
||||
|
||||
return { db };
|
||||
return { db, nationTurns, nationRevisions };
|
||||
};
|
||||
|
||||
describe('reservedTurns', () => {
|
||||
@@ -339,6 +340,61 @@ describe('reservedTurns', () => {
|
||||
expect(noOpPush).toEqual(repeated);
|
||||
});
|
||||
|
||||
it('rebases stale nation slot input onto the current queue after a turn advances', async () => {
|
||||
const { db, nationTurns, nationRevisions } = buildDb();
|
||||
const seeded = await setNationTurns(
|
||||
db,
|
||||
6,
|
||||
12,
|
||||
[
|
||||
{ turnIndices: [0], action: 'che_증축', args: {} },
|
||||
{ turnIndices: [1], action: 'che_감축', args: {} },
|
||||
{ turnIndices: [2], action: 'che_천도', args: { destCityId: 3 } },
|
||||
],
|
||||
0
|
||||
);
|
||||
expect(seeded.revision).toBe(1);
|
||||
|
||||
// daemon이 한 턴을 소비한 뒤의 현재 큐를 모사한다.
|
||||
nationRevisions.set('6:12', 2);
|
||||
nationTurns.set('6:12', [
|
||||
{
|
||||
id: 1,
|
||||
nationId: 6,
|
||||
officerLevel: 12,
|
||||
turnIdx: 0,
|
||||
actionCode: 'che_감축',
|
||||
arg: {},
|
||||
createdAt: new Date(),
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
nationId: 6,
|
||||
officerLevel: 12,
|
||||
turnIdx: 1,
|
||||
actionCode: 'che_천도',
|
||||
arg: { destCityId: 3 },
|
||||
createdAt: new Date(),
|
||||
},
|
||||
]);
|
||||
|
||||
const result = await setNationTurnsAtCurrentPositions(
|
||||
db,
|
||||
6,
|
||||
12,
|
||||
[{ turnIndices: [2], action: 'che_포상', args: { destGeneralId: 77, amount: 100, isGold: true } }],
|
||||
1
|
||||
);
|
||||
|
||||
expect(result.revision).toBe(3);
|
||||
expect(result.turns[0]?.action).toBe('che_감축');
|
||||
expect(result.turns[1]?.action).toBe('che_천도');
|
||||
expect(result.turns[2]).toMatchObject({
|
||||
action: 'che_포상',
|
||||
args: { destGeneralId: 77, amount: 100, isGold: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects an API writer while the daemon holds the queue lease without touching turns', async () => {
|
||||
const deleteMany = vi.fn(async () => ({}));
|
||||
const createMany = vi.fn(async () => ({}));
|
||||
|
||||
@@ -1020,7 +1020,22 @@ describe('appRouter', () => {
|
||||
|
||||
expect(response.turns[0]?.args).toEqual({ isGold: true, amount: 1, destGeneralId: 7 });
|
||||
expect(response.turns[2]?.args).toEqual({ isGold: false, amount: 2, destGeneralId: 8 });
|
||||
expect(nationWrites).toHaveLength(1);
|
||||
|
||||
const rebased = await caller.turns.reserved.setNationBulk({
|
||||
generalId: general.id,
|
||||
entries: [
|
||||
{
|
||||
turnList: [2],
|
||||
action: 'che_포상',
|
||||
args: { isGold: true, amount: 3, destGeneralId: 9 },
|
||||
},
|
||||
],
|
||||
// 첫 요청 뒤 턴이 진행한 화면의 stale revision을 그대로 보낸 상황입니다.
|
||||
expectedRevision: 0,
|
||||
});
|
||||
expect(rebased.revision).toBe(2);
|
||||
expect(rebased.turns[2]?.args).toEqual({ isGold: true, amount: 3, destGeneralId: 9 });
|
||||
expect(nationWrites).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('enforces only legacy reservation permissions without applying full execution constraints', async () => {
|
||||
|
||||
Reference in New Issue
Block a user