fix(backend): 생성 장수 첫 턴을 접수 시각에 맞춤
daemon 완료 시각이 뒤처져도 신규 장수 턴을 접수된 논리 게임 시각부터 한 턴 안에 배정한다. 로비 응답에는 보정 시계가 사용할 서버 게임 시각과 clock mode를 추가한다.
This commit is contained in:
@@ -3,7 +3,15 @@ import { describe, expect, it, vi } from 'vitest';
|
||||
import type { DatabaseClient, GameApiContext } from '../src/context.js';
|
||||
import { appRouter } from '../src/router.js';
|
||||
|
||||
const buildContext = (meta: Record<string, unknown>): GameApiContext =>
|
||||
const buildContext = (
|
||||
meta: Record<string, unknown>,
|
||||
clock: {
|
||||
baseTime?: Date;
|
||||
tick?: bigint;
|
||||
mode?: string;
|
||||
wallAnchor?: Date;
|
||||
} = {}
|
||||
): GameApiContext =>
|
||||
({
|
||||
auth: null,
|
||||
db: {
|
||||
@@ -16,6 +24,10 @@ const buildContext = (meta: Record<string, unknown>): GameApiContext =>
|
||||
tickSeconds: 3_600,
|
||||
config: {},
|
||||
meta,
|
||||
clockBaseTime: clock.baseTime ?? null,
|
||||
clockTick: clock.tick ?? null,
|
||||
clockMode: clock.mode ?? 'realtime',
|
||||
clockWallAnchor: clock.wallAnchor ?? null,
|
||||
updatedAt: new Date('2026-07-31T00:00:00.000Z'),
|
||||
})),
|
||||
},
|
||||
@@ -36,4 +48,23 @@ describe('lobby season state', () => {
|
||||
|
||||
expect(result.isUnited).toBe(isunited);
|
||||
});
|
||||
|
||||
it('returns the projected server game time and whether the clock is running', async () => {
|
||||
const result = await appRouter
|
||||
.createCaller(
|
||||
buildContext(
|
||||
{},
|
||||
{
|
||||
baseTime: new Date('2026-08-15T00:00:00.000Z'),
|
||||
tick: 72_000_000n,
|
||||
mode: 'manual',
|
||||
wallAnchor: new Date('2026-08-15T17:00:00.000Z'),
|
||||
}
|
||||
)
|
||||
)
|
||||
.lobby.info();
|
||||
|
||||
expect(result.serverTime).toBe('2026-08-15T02:00:00.000Z');
|
||||
expect(result.clockMode).toBe('manual');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user