fix(api): align scenario 2601 reference data
This commit is contained in:
@@ -79,7 +79,7 @@ const createContext = (options: {
|
||||
nationMeta?: Record<string, unknown>;
|
||||
requestCommand?: ReturnType<typeof vi.fn>;
|
||||
accessToken?: string;
|
||||
logs?: Array<{ id: number; text: string }>;
|
||||
logs?: Array<{ id: number; text: string; year?: number; month?: number; createdAt?: Date }>;
|
||||
}) => {
|
||||
const me = options.me === undefined ? buildGeneral() : options.me;
|
||||
const targets = options.targets ?? (me ? [me] : []);
|
||||
@@ -119,12 +119,24 @@ const createContext = (options: {
|
||||
},
|
||||
logEntry: {
|
||||
groupBy: vi.fn(async () => []),
|
||||
findMany: vi.fn(async (query?: { where?: { id?: { lt?: number } }; take?: number }) => {
|
||||
const source = options.logs ?? [{ id: 1, text: '기록' }];
|
||||
const beforeId = query?.where?.id?.lt;
|
||||
const filtered = beforeId ? source.filter((entry) => entry.id < beforeId) : source;
|
||||
return query?.take ? filtered.slice(0, query.take) : filtered;
|
||||
}),
|
||||
findMany: vi.fn(
|
||||
async (query?: {
|
||||
where?: { id?: { lt?: number } };
|
||||
take?: number;
|
||||
select?: { id?: boolean; text?: boolean };
|
||||
}) => {
|
||||
const source = (options.logs ?? [{ id: 1, text: '기록' }]).map((entry) => ({
|
||||
year: 185,
|
||||
month: 1,
|
||||
createdAt: now,
|
||||
...entry,
|
||||
}));
|
||||
const beforeId = query?.where?.id?.lt;
|
||||
const filtered = beforeId ? source.filter((entry) => entry.id < beforeId) : source;
|
||||
const selected = query?.select ? filtered.map(({ id, text }) => ({ id, text })) : filtered;
|
||||
return query?.take ? selected.slice(0, query.take) : selected;
|
||||
}
|
||||
),
|
||||
},
|
||||
};
|
||||
const redisClient = { get: async () => null, set: async () => null };
|
||||
@@ -405,6 +417,14 @@ describe('battle-center general and user permissions', () => {
|
||||
});
|
||||
await expect(appRouter.createCaller(tenured.context).nation.getBattleCenter()).resolves.toMatchObject({
|
||||
me: { id: 7, permissionLevel: 1 },
|
||||
generals: [
|
||||
{
|
||||
id: 7,
|
||||
picture: 'default.jpg',
|
||||
imageServer: 0,
|
||||
battleStats: { kills: 0, deaths: 0, fire: 0, killCrew: 0, deathCrew: 0, dex: [0, 0, 0, 0, 0] },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const auditor = createContext({
|
||||
@@ -430,6 +450,7 @@ describe('battle-center general and user permissions', () => {
|
||||
|
||||
await expect(member.nation.getGeneralLog({ generalId: me.id, type: 'generalAction' })).resolves.toMatchObject({
|
||||
generalId: me.id,
|
||||
logs: [{ id: 1, year: 185, month: 1, createdAt: '2026-01-01 00:00:00' }],
|
||||
});
|
||||
await expect(
|
||||
member.nation.getGeneralLog({ generalId: otherUser.id, type: 'generalAction' })
|
||||
|
||||
@@ -52,12 +52,27 @@ const archiveRows = [
|
||||
year: 219,
|
||||
month: 12,
|
||||
map: { year: 219, month: 12, startYear: 190, cityList: [], nationList: [] },
|
||||
nations: [{ id: 1, name: '현재기수국', color: '#00FF00', level: 7, power: 1300, generalCount: 10, cities: ['낙양'] }],
|
||||
nations: [
|
||||
{ id: 1, name: '현재기수국', color: '#00FF00', level: 7, power: 1300, generalCount: 10, cities: ['낙양'] },
|
||||
],
|
||||
globalHistory: ['저장된 현재 기수 과거 기록'],
|
||||
globalAction: ['저장된 현재 기수 과거 행동'],
|
||||
hash: 'current-archive',
|
||||
createdAt: new Date('2026-07-31T00:00:00.000Z'),
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
profileName: profile.id,
|
||||
sourceId: 201,
|
||||
year: 219,
|
||||
month: 11,
|
||||
map: { year: 219, month: 11, startYear: 190, cityList: [], nationList: [] },
|
||||
nations: [],
|
||||
globalHistory: ['레거시 프로필 별칭 기록'],
|
||||
globalAction: [],
|
||||
hash: 'legacy-profile-alias',
|
||||
createdAt: new Date('2026-07-30T00:00:00.000Z'),
|
||||
},
|
||||
];
|
||||
|
||||
const authFor = (userId: string): GameSessionTokenPayload => ({
|
||||
@@ -75,14 +90,21 @@ const authFor = (userId: string): GameSessionTokenPayload => ({
|
||||
sanctions: {},
|
||||
});
|
||||
|
||||
const buildContext = (auth: GameSessionTokenPayload | null, options: { hasGeneral?: boolean } = {}): GameApiContext => {
|
||||
const buildContext = (
|
||||
auth: GameSessionTokenPayload | null,
|
||||
options: { hasGeneral?: boolean; worldMeta?: unknown } = {}
|
||||
): GameApiContext => {
|
||||
const db = {
|
||||
general: {
|
||||
findFirst: async ({ where }: { where: { userId: string } }) =>
|
||||
options.hasGeneral === false ? null : { id: where.userId === 'owner-a' ? 1 : 2, userId: where.userId },
|
||||
},
|
||||
worldState: {
|
||||
findFirst: async () => ({ currentYear: 220, currentMonth: 1, meta: { serverId: currentServerId } }),
|
||||
findFirst: async () => ({
|
||||
currentYear: 220,
|
||||
currentMonth: 1,
|
||||
meta: options.worldMeta ?? { serverId: currentServerId },
|
||||
}),
|
||||
},
|
||||
yearbookHistory: {
|
||||
findFirst: async (args: {
|
||||
@@ -198,6 +220,16 @@ describe('historical yearbook access from dynasty', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('reads imported history under the short profile ID when world metadata has no server ID', async () => {
|
||||
const caller = appRouter.createCaller(buildContext(authFor('owner-a'), { worldMeta: {} }));
|
||||
|
||||
await expect(caller.yearbook.getRange()).resolves.toEqual({
|
||||
firstYearMonth: 219 * 12 + 10,
|
||||
lastYearMonth: 219 * 12 + 10,
|
||||
currentYearMonth: 220 * 12,
|
||||
});
|
||||
});
|
||||
|
||||
it('uses stored logs for a past month of the current generation', async () => {
|
||||
const caller = appRouter.createCaller(buildContext(authFor('owner-a')));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user