Files
Genarrative/src/services/jump-hop/jumpHopClient.runtime.test.ts
五香丸子 6ee55707e1 统一跳一跳三维地块与落点判定
修正跳一跳长按起跳预测为真实脚点指向下一块顶面中心

统一前端指示器飞行动画与后端顶面 footprint 判定

调整 Three.js 方块贴图与角色顶面投影表现

补充跳一跳 UV 图集切片与运行态规则文档
2026-06-12 22:42:39 +08:00

128 lines
3.4 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
const apiClientMocks = vi.hoisted(() => ({
requestJson: vi.fn(),
}));
vi.mock('../apiClient', async () => {
const actual =
await vi.importActual<typeof import('../apiClient')>('../apiClient');
return {
...actual,
requestJson: apiClientMocks.requestJson,
};
});
import {
restartJumpHopRuntimeRun,
startJumpHopRuntimeRun,
submitJumpHopJump,
} from './jumpHopClient';
describe('jumpHopClient runtime requests', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.spyOn(Date, 'now').mockReturnValue(1780000000000);
apiClientMocks.requestJson.mockResolvedValue({ runId: 'run-1' });
});
afterEach(() => {
vi.restoreAllMocks();
});
it('starts runs through the shared runtime request skeleton', async () => {
await startJumpHopRuntimeRun('profile/1', {
runtimeGuestToken: 'runtime-guest-token',
});
expect(apiClientMocks.requestJson).toHaveBeenCalledWith(
'/api/runtime/jump-hop/runs',
expect.objectContaining({
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer runtime-guest-token',
},
body: JSON.stringify({ profileId: 'profile/1' }),
}),
'启动跳一跳运行态失败',
expect.objectContaining({
skipAuth: true,
skipRefresh: true,
}),
);
});
it('passes draft runtime mode in the start run request body', async () => {
await startJumpHopRuntimeRun('profile/1', {
runtimeMode: 'draft',
});
expect(apiClientMocks.requestJson).toHaveBeenCalledWith(
'/api/runtime/jump-hop/runs',
expect.objectContaining({
method: 'POST',
body: JSON.stringify({
profileId: 'profile/1',
runtimeMode: 'draft',
}),
}),
'启动跳一跳运行态失败',
expect.anything(),
);
});
it('submits jump input with a generated client event id', async () => {
await submitJumpHopJump(
'run/1',
{ dragDistance: 320 },
{ runtimeGuestToken: 'runtime-guest-token' },
);
expect(apiClientMocks.requestJson).toHaveBeenCalledWith(
'/api/runtime/jump-hop/runs/run%2F1/jump',
expect.objectContaining({
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer runtime-guest-token',
},
body: JSON.stringify({
dragDistance: 320,
clientEventId: 'jump-run/1-1780000000000',
}),
}),
'提交跳一跳起跳失败',
expect.objectContaining({
skipAuth: true,
skipRefresh: true,
}),
);
});
it('restarts runs with the same guest auth request skeleton', async () => {
await restartJumpHopRuntimeRun('run/1', {
runtimeGuestToken: 'runtime-guest-token',
});
expect(apiClientMocks.requestJson).toHaveBeenCalledWith(
'/api/runtime/jump-hop/runs/run%2F1/restart',
expect.objectContaining({
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer runtime-guest-token',
},
body: JSON.stringify({
clientActionId: 'restart-run/1-1780000000000',
}),
}),
'重新开始跳一跳失败',
expect.objectContaining({
skipAuth: true,
skipRefresh: true,
}),
);
});
});