Files
Genarrative/src/services/puzzle-gallery/puzzleGalleryClient.test.ts
2026-04-29 20:56:59 +08:00

53 lines
1.4 KiB
TypeScript

import { beforeEach, expect, test, vi } from 'vitest';
const { requestJsonMock } = vi.hoisted(() => ({
requestJsonMock: vi.fn(),
}));
vi.mock('../apiClient', () => ({
requestJson: requestJsonMock,
}));
import { getPuzzleGalleryDetail, listPuzzleGallery } from './puzzleGalleryClient';
beforeEach(() => {
requestJsonMock.mockReset();
requestJsonMock.mockResolvedValue({ items: [] });
});
test('listPuzzleGallery reads public gallery without auth refresh coupling', async () => {
await listPuzzleGallery();
expect(requestJsonMock).toHaveBeenCalledWith(
'/api/runtime/puzzle/gallery',
expect.objectContaining({ method: 'GET' }),
'读取拼图广场失败',
expect.objectContaining({
retry: expect.objectContaining({ maxRetries: 1 }),
skipAuth: true,
skipRefresh: true,
}),
);
});
test('getPuzzleGalleryDetail reads public detail without auth refresh coupling', async () => {
requestJsonMock.mockResolvedValueOnce({
item: {
profileId: 'puzzle-profile-1',
},
});
await getPuzzleGalleryDetail('puzzle-profile-1');
expect(requestJsonMock).toHaveBeenCalledWith(
'/api/runtime/puzzle/gallery/puzzle-profile-1',
expect.objectContaining({ method: 'GET' }),
'读取拼图广场详情失败',
expect.objectContaining({
retry: expect.objectContaining({ maxRetries: 1 }),
skipAuth: true,
skipRefresh: true,
}),
);
});