66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { createBarkBattleDraft, publishBarkBattleWork } from './barkBattleCreationClient';
|
|
|
|
const requestJsonMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock('../apiClient', () => ({
|
|
requestJson: requestJsonMock,
|
|
}));
|
|
|
|
describe('barkBattleCreationClient', () => {
|
|
afterEach(() => {
|
|
requestJsonMock.mockReset();
|
|
});
|
|
|
|
it('creates a lightweight draft through creation API', async () => {
|
|
requestJsonMock.mockResolvedValueOnce({ draftId: 'draft-1' });
|
|
|
|
await createBarkBattleDraft({
|
|
title: '周末狗狗杯',
|
|
description: '',
|
|
themePreset: 'neon-park',
|
|
playerDogSkinPreset: 'shiba',
|
|
opponentDogSkinPreset: 'husky',
|
|
difficultyPreset: 'hard',
|
|
leaderboardEnabled: true,
|
|
});
|
|
|
|
expect(requestJsonMock).toHaveBeenCalledWith(
|
|
'/api/creation/bark-battle/drafts',
|
|
expect.objectContaining({
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
title: '周末狗狗杯',
|
|
description: '',
|
|
themePreset: 'neon-park',
|
|
playerDogSkinPreset: 'shiba',
|
|
opponentDogSkinPreset: 'husky',
|
|
difficultyPreset: 'hard',
|
|
leaderboardEnabled: true,
|
|
}),
|
|
}),
|
|
'创建汪汪声浪大作战草稿失败',
|
|
expect.objectContaining({ retry: expect.objectContaining({ retryUnsafeMethods: true }) }),
|
|
);
|
|
});
|
|
|
|
it('publishes a draft and returns stable work config', async () => {
|
|
requestJsonMock.mockResolvedValueOnce({ workId: 'work-1' });
|
|
|
|
await publishBarkBattleWork({ draftId: 'draft-1', workId: 'work-1' });
|
|
|
|
expect(requestJsonMock).toHaveBeenCalledWith(
|
|
'/api/creation/bark-battle/works/publish',
|
|
expect.objectContaining({
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ draftId: 'draft-1', workId: 'work-1' }),
|
|
}),
|
|
'发布汪汪声浪大作战作品失败',
|
|
expect.objectContaining({ retry: expect.objectContaining({ retryUnsafeMethods: true }) }),
|
|
);
|
|
});
|
|
});
|