1
This commit is contained in:
44
src/services/big-fish-gallery/bigFishGalleryClient.test.ts
Normal file
44
src/services/big-fish-gallery/bigFishGalleryClient.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { beforeEach, expect, test, vi } from 'vitest';
|
||||
|
||||
import { ApiClientError } from '../apiClient';
|
||||
|
||||
const { requestJsonMock } = vi.hoisted(() => ({
|
||||
requestJsonMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../apiClient', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('../apiClient')>();
|
||||
return {
|
||||
...actual,
|
||||
requestJson: requestJsonMock,
|
||||
};
|
||||
});
|
||||
|
||||
import { listBigFishGallery } from './bigFishGalleryClient';
|
||||
|
||||
beforeEach(() => {
|
||||
requestJsonMock.mockReset();
|
||||
});
|
||||
|
||||
test('listBigFishGallery returns empty items when public gallery is not ready', async () => {
|
||||
requestJsonMock.mockRejectedValueOnce(
|
||||
new ApiClientError({
|
||||
message: '读取大鱼吃小鱼广场失败',
|
||||
status: 400,
|
||||
code: 'HTTP_400',
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(listBigFishGallery()).resolves.toEqual({ items: [] });
|
||||
});
|
||||
|
||||
test('listBigFishGallery keeps non-gallery-read errors visible', async () => {
|
||||
const error = new ApiClientError({
|
||||
message: '服务暂不可用',
|
||||
status: 503,
|
||||
code: 'HTTP_503',
|
||||
});
|
||||
requestJsonMock.mockRejectedValueOnce(error);
|
||||
|
||||
await expect(listBigFishGallery()).rejects.toBe(error);
|
||||
});
|
||||
@@ -26,7 +26,10 @@ export async function listBigFishGallery() {
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
if (error instanceof ApiClientError && error.status === 404) {
|
||||
if (
|
||||
error instanceof ApiClientError &&
|
||||
(error.status === 400 || error.status === 404)
|
||||
) {
|
||||
return { items: [] };
|
||||
}
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user