阶段十:完成注释门禁最终验收
This commit is contained in:
1 parent
d1a165f897
commit
f30a1f68f8
29 files changed
+509
-7253
No files matched your search
@@ -21,7 +21,7 @@ test('maps AMap POI fields to the publish location shape', () => {
|
||||
poi_name: '人民广场',
|
||||
province: '上海市',
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('drops incomplete or invalid AMap POIs', () => {
|
||||
expect(amapPOIToPublishLocation({
|
||||
@@ -32,4 +32,4 @@ test('drops incomplete or invalid AMap POIs', () => {
|
||||
cityname: '上海市',
|
||||
location: { lng: 0, lat: 31.2 },
|
||||
})).toBeNull();
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
@@ -1,33 +1,46 @@
|
||||
import type { PublishLocation } from './api';
|
||||
|
||||
const AMAP_SCRIPT_ID = 'ydisks-amap-js-api';
|
||||
const AMAP_SCRIPT_ID = 'ydisks-amap-js-api'; /* AMAP_SCRIPT_ID 表示AMAPSCRIPTID。 */
|
||||
// 高德 JS API 的 Key 是前端公开 Key;部署时可通过 VITE_AMAP_JS_KEY 覆盖。
|
||||
const DEFAULT_AMAP_JS_KEY = 'c9b68d4ce9a2a97f22a4a439404488ca';
|
||||
|
||||
export interface AMapLocationValue {
|
||||
lng: number;
|
||||
lat: number;
|
||||
// lng 表示lng。
|
||||
lng: number;
|
||||
// lat 表示lat。
|
||||
lat: number;
|
||||
}
|
||||
|
||||
export interface AMapPOI {
|
||||
id?: string;
|
||||
name?: string;
|
||||
address?: string;
|
||||
adname?: string;
|
||||
cityname?: string;
|
||||
adcode?: string | number;
|
||||
pname?: string;
|
||||
location?: AMapLocationValue;
|
||||
// id 表示id。
|
||||
id?: string;
|
||||
// name 表示name。
|
||||
name?: string;
|
||||
// address 表示address。
|
||||
address?: string;
|
||||
// adname 表示adname。
|
||||
adname?: string;
|
||||
// cityname 表示cityname。
|
||||
cityname?: string;
|
||||
// adcode 表示adcode。
|
||||
adcode?: string | number;
|
||||
// pname 表示pname。
|
||||
pname?: string;
|
||||
// location 表示location。
|
||||
location?: AMapLocationValue;
|
||||
}
|
||||
|
||||
interface AMapPlaceSearchResult {
|
||||
poiList?: {
|
||||
pois?: AMapPOI[];
|
||||
// poiList 表示poiList。
|
||||
poiList?: {
|
||||
// pois 表示pois。
|
||||
pois?: AMapPOI[];
|
||||
};
|
||||
}
|
||||
|
||||
interface AMapPlaceSearch {
|
||||
searchNearBy(
|
||||
// searchNearBy 表示searchNearBy。
|
||||
searchNearBy(
|
||||
keyword: string,
|
||||
center: [number, number],
|
||||
radius: number,
|
||||
@@ -36,42 +49,47 @@ interface AMapPlaceSearch {
|
||||
}
|
||||
|
||||
interface AMapAPI {
|
||||
PlaceSearch: new (options: { extensions: 'all'; pageSize: number }) => AMapPlaceSearch;
|
||||
// PlaceSearch 表示PlaceSearch。
|
||||
PlaceSearch: new (options: { /* extensions 表示extensions。 */ extensions: 'all'; /* pageSize 表示pageSize。 */ pageSize: number }) => AMapPlaceSearch;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
AMap?: AMapAPI;
|
||||
__ydisksAmapLoaded?: () => void;
|
||||
// AMap 表示AMap。
|
||||
AMap?: AMapAPI;
|
||||
// __ydisksAmapLoaded 表示ydisksAmapLoaded。
|
||||
__ydisksAmapLoaded?: () => void;
|
||||
}
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_AMAP_JS_KEY?: string;
|
||||
// VITE_AMAP_JS_KEY 表示VITEAMAPJSKEY。
|
||||
readonly VITE_AMAP_JS_KEY?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
// env 表示env。
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
}
|
||||
|
||||
let amapLoadPromise: Promise<AMapAPI> | null = null;
|
||||
let amapLoadPromise: Promise<AMapAPI> | null = null; /* amapLoadPromise 表示amapLoadPromise。 */
|
||||
|
||||
const configuredAmapKey = (): string => {
|
||||
const key = import.meta.env.VITE_AMAP_JS_KEY?.trim();
|
||||
const key = import.meta.env.VITE_AMAP_JS_KEY?.trim(); /* key 表示key。 */
|
||||
return key || DEFAULT_AMAP_JS_KEY;
|
||||
};
|
||||
}; /* configuredAmapKey 表示configuredAmapKey。 */
|
||||
|
||||
const loadAMap = (): Promise<AMapAPI> => {
|
||||
if (window.AMap) return Promise.resolve(window.AMap);
|
||||
if (amapLoadPromise) return amapLoadPromise;
|
||||
|
||||
amapLoadPromise = new Promise<AMapAPI>((resolve, reject) => {
|
||||
const existing = document.getElementById(AMAP_SCRIPT_ID) as HTMLScriptElement | null;
|
||||
const script = existing || document.createElement('script');
|
||||
const existing = document.getElementById(AMAP_SCRIPT_ID) as HTMLScriptElement | null; /* existing 表示existing。 */
|
||||
const script = existing || document.createElement('script'); /* script 表示script。 */
|
||||
const cleanup = () => {
|
||||
window.__ydisksAmapLoaded = undefined;
|
||||
window.clearTimeout(timeout);
|
||||
};
|
||||
}; /* cleanup 表示cleanup。 */
|
||||
const finish = () => {
|
||||
if (window.AMap) {
|
||||
cleanup();
|
||||
@@ -80,11 +98,11 @@ const loadAMap = (): Promise<AMapAPI> => {
|
||||
cleanup();
|
||||
reject(new Error('高德地图 API 加载完成但未找到 AMap 对象'));
|
||||
}
|
||||
};
|
||||
}; /* finish 表示finish。 */
|
||||
const timeout = window.setTimeout(() => {
|
||||
cleanup();
|
||||
reject(new Error('高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置'));
|
||||
}, 15_000);
|
||||
} /* 回调函数负责当前业务流程。 */, 15_000); /* timeout 表示timeout。 */
|
||||
|
||||
window.__ydisksAmapLoaded = finish;
|
||||
script.id = AMAP_SCRIPT_ID;
|
||||
@@ -93,22 +111,22 @@ const loadAMap = (): Promise<AMapAPI> => {
|
||||
script.onerror = () => {
|
||||
cleanup();
|
||||
reject(new Error('高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置'));
|
||||
};
|
||||
} /* 回调函数负责当前业务流程。 */;
|
||||
if (!existing) document.head.appendChild(script);
|
||||
}).catch(error => {
|
||||
} /* 回调函数负责当前业务流程。 */).catch(error => {
|
||||
amapLoadPromise = null;
|
||||
throw error;
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
return amapLoadPromise;
|
||||
};
|
||||
}; /* loadAMap 表示loadAMap。 */
|
||||
|
||||
const validCoordinate = (value: number): boolean => Number.isFinite(value) && value !== 0;
|
||||
const validCoordinate = (value: number): boolean => Number.isFinite(value) && value !== 0; /* validCoordinate 表示validCoordinate。 */
|
||||
|
||||
// 字段映射与闲鱼网页版发布页一致:adcode → divisionId,name → poi,pname/cityname/adname → 行政区。
|
||||
export const amapPOIToPublishLocation = (poi: AMapPOI): PublishLocation | null => {
|
||||
const longitude = Number(poi.location?.lng);
|
||||
const latitude = Number(poi.location?.lat);
|
||||
const longitude = Number(poi.location?.lng); /* longitude 表示longitude。 */
|
||||
const latitude = Number(poi.location?.lat); /* latitude 表示latitude。 */
|
||||
const location: PublishLocation = {
|
||||
area: String(poi.adname || '').trim(),
|
||||
city: String(poi.cityname || '').trim(),
|
||||
@@ -118,7 +136,7 @@ export const amapPOIToPublishLocation = (poi: AMapPOI): PublishLocation | null =
|
||||
poi_id: String(poi.id || '').trim(),
|
||||
poi_name: String(poi.name || '').trim(),
|
||||
province: String(poi.pname || '').trim(),
|
||||
};
|
||||
}; /* location 表示location。 */
|
||||
if (!location.division_id || !location.province || !location.city || !location.poi_id || !location.poi_name) {
|
||||
return null;
|
||||
}
|
||||
@@ -132,9 +150,9 @@ export const getPublishLocations = async (longitude: number, latitude: number):
|
||||
if (!validCoordinate(longitude) || !validCoordinate(latitude) || longitude < -180 || longitude > 180 || latitude < -90 || latitude > 90) {
|
||||
throw new Error('经纬度无效');
|
||||
}
|
||||
const amap = await loadAMap();
|
||||
const amap = await loadAMap(); /* amap 表示amap。 */
|
||||
return new Promise<PublishLocation[]>((resolve, reject) => {
|
||||
const placeSearch = new amap.PlaceSearch({ extensions: 'all', pageSize: 10 });
|
||||
const placeSearch = new amap.PlaceSearch({ extensions: 'all', pageSize: 10 }); /* placeSearch 表示placeSearch。 */
|
||||
placeSearch.searchNearBy('', [longitude, latitude], 1_000, (status, result) => {
|
||||
if (status !== 'complete') {
|
||||
if (status === 'no_data') {
|
||||
@@ -146,8 +164,8 @@ export const getPublishLocations = async (longitude: number, latitude: number):
|
||||
}
|
||||
const locations = (result?.poiList?.pois || [])
|
||||
.map(amapPOIToPublishLocation)
|
||||
.filter((location): location is PublishLocation => location !== null);
|
||||
.filter((location): location is PublishLocation => location !== null /* 回调函数负责当前业务流程。 */); /* locations 表示locations。 */
|
||||
resolve(locations);
|
||||
});
|
||||
});
|
||||
};
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
}; /* getPublishLocations 表示getPublishLocations。 */
|
||||
+104
-104
@@ -45,32 +45,32 @@ import {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateSystemSettings uses one atomic bulk request', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await updateSystemSettings({ theme_color: 'blue', renewal_log_retention_days: 15 });
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/settings/system', expect.objectContaining({ method: 'PUT', credentials: 'include' }));
|
||||
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({ theme_color: 'blue', renewal_log_retention_days: 15 });
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('health API exposes build metadata through the request boundary', async () => {
|
||||
// fetchMock 是健康检查 API 的请求替身。
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ version: '1.2.3', commit: 'abc123' }));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const controller = new AbortController();
|
||||
const controller = new AbortController(); /* controller 表示controller。 */
|
||||
|
||||
await expect(getHealth({ signal: controller.signal })).resolves.toEqual({ version: '1.2.3', commit: 'abc123' });
|
||||
expect(fetchMock).toHaveBeenCalledWith('/health', expect.objectContaining({ method: 'GET', signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('chat APIs preserve account and conversation scope', async () => {
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse({ sessions: [{ account_id: 'a1', chat_id: 'c1' }] }))
|
||||
.mockResolvedValueOnce(jsonResponse({ messages: [{ account_id: 'a1', chat_id: 'c1', id: 1 }] }))
|
||||
.mockImplementation(() => Promise.resolve(jsonResponse({ success: true, message: { id: 2 } })));
|
||||
.mockImplementation(() => Promise.resolve(jsonResponse({ success: true, message: { id: 2 } })) /* 回调函数负责当前业务流程。 */); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await getChatSessions('a1');
|
||||
await getChatMessages('a1', 'c1', 9);
|
||||
@@ -80,7 +80,7 @@ test('chat APIs preserve account and conversation scope', async () => {
|
||||
expect(fetchMock.mock.calls[1][0]).toBe('/api/v1/chat/messages?account_id=a1&chat_id=c1&before_id=9');
|
||||
expect(JSON.parse(fetchMock.mock.calls[2][1].body)).toMatchObject({ account_id: 'a1', chat_id: 'c1', buyer_id: 'b1' });
|
||||
expect(JSON.parse(fetchMock.mock.calls[3][1].body)).toEqual({ account_id: 'a1', chat_id: 'c1' });
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('Chat 会话、消息和发送 API 转发外部取消信号', async () => {
|
||||
// fetchMock 验证会话切换、消息分页和文本/图片发送共享取消控制能力。
|
||||
@@ -103,10 +103,10 @@ test('Chat 会话、消息和发送 API 转发外部取消信号', async () => {
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/chat/messages', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(4, '/api/v1/chat/images', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(5, '/api/v1/chat/read', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('account task APIs keep rating and polish account-scoped', async () => {
|
||||
const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(jsonResponse({ success: true, summary: { task_type: 'auto_rate' } })));
|
||||
const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(jsonResponse({ success: true, summary: { task_type: 'auto_rate' } })) /* 回调函数负责当前业务流程。 */); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await updateAccountTaskSettings('a1', {
|
||||
account_id: 'a1', auto_rate_enabled: true, rate_content: '交易愉快',
|
||||
@@ -117,7 +117,7 @@ test('account task APIs keep rating and polish account-scoped', async () => {
|
||||
expect(fetchMock.mock.calls[0][1].method).toBe('PUT');
|
||||
expect(fetchMock.mock.calls[1][0]).toBe('/api/v1/account-tasks/a1/run');
|
||||
expect(JSON.parse(fetchMock.mock.calls[1][1].body)).toEqual({ task_type: 'auto_rate' });
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('账号自动任务 API 转发外部取消信号', async () => {
|
||||
// fetchMock 验证读取、保存和执行账号任务都支持请求取消。
|
||||
@@ -128,26 +128,26 @@ test('账号自动任务 API 转发外部取消信号', async () => {
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
// controller 是 AccountAutomation feature Hook 使用的请求控制器。
|
||||
const controller = new AbortController();
|
||||
const settings = { account_id: 'a1', auto_rate_enabled: true, rate_content: '交易愉快', auto_polish_enabled: false, polish_time: '03:00' };
|
||||
const settings = { account_id: 'a1', auto_rate_enabled: true, rate_content: '交易愉快', auto_polish_enabled: false, polish_time: '03:00' }; /* settings 表示settings。 */
|
||||
await getAccountTaskSettings('a1', { signal: controller.signal });
|
||||
await updateAccountTaskSettings('a1', settings, { signal: controller.signal });
|
||||
await runAccountTask('a1', 'auto_rate', { signal: controller.signal });
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/account-tasks/a1', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/account-tasks/a1', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/account-tasks/a1/run', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getItemPublishBatches unwraps persisted batch list', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ batches: [{ id: 'batch-1', status: 'running' }] }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ batches: [{ id: 'batch-1', status: 'running' }] })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await expect(getItemPublishBatches(10)).resolves.toEqual([{ id: 'batch-1', status: 'running' }]);
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/items/publish-batches?limit=10', expect.objectContaining({ credentials: 'include' }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('automation issue APIs expose and resolve quarantined work', async () => {
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse({ runs: [{ id: 1 }], pending_tasks: [{ id: 2 }] }))
|
||||
.mockImplementation(() => Promise.resolve(jsonResponse({ success: true })));
|
||||
.mockImplementation(() => Promise.resolve(jsonResponse({ success: true })) /* 回调函数负责当前业务流程。 */); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await expect(getAutomationIssues()).resolves.toEqual({ runs: [{ id: 1 }], pending_tasks: [{ id: 2 }] });
|
||||
await resolveAutomationRun(1, 'continue');
|
||||
@@ -155,47 +155,47 @@ test('automation issue APIs expose and resolve quarantined work', async () => {
|
||||
expect(fetchMock.mock.calls[1][0]).toBe('/api/v1/automation-runs/1/resolve');
|
||||
expect(JSON.parse(fetchMock.mock.calls[1][1].body)).toEqual({ resolution: 'continue' });
|
||||
expect(fetchMock.mock.calls[2][0]).toBe('/api/v1/automation-pending-tasks/2/resolve');
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('order multipart requests use the shared authenticated form request path', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await syncOrders('acc1', 'pending_ship');
|
||||
await importOrders(new FormData());
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/orders/refresh', expect.objectContaining({ method: 'POST', credentials: 'include', body: expect.any(FormData) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/orders/import', expect.objectContaining({ method: 'POST', credentials: 'include', body: expect.any(FormData) }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('legacy notification channel aliases are normalized for the editor', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse([{ id: 1, name: '旧飞书', type: 'lark', config: 'not-json', enabled: true }])));
|
||||
const result = await getNotificationChannels();
|
||||
const result = await getNotificationChannels(); /* result 表示处理结果。 */
|
||||
expect(result.data?.[0]).toMatchObject({ type: 'feishu', config: {} });
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
const jsonResponse = (body: unknown) => new Response(JSON.stringify(body), {
|
||||
status: 200,
|
||||
headers: { 'content-type': 'application/json' },
|
||||
});
|
||||
}); /* jsonResponse 表示json接口响应结果。 */
|
||||
|
||||
test('getOrders normalizes backend order fields', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({
|
||||
orders: [{ order_id: 'o1', order_status: 'shipped', quantity: '2' }],
|
||||
total: 1,
|
||||
}));
|
||||
})); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const result = await getOrders(undefined, 'all', 1, 20, ' buyer ');
|
||||
const result = await getOrders(undefined, 'all', 1, 20, ' buyer '); /* result 表示处理结果。 */
|
||||
expect(result.data[0]).toMatchObject({ id: 'o1', status: 'shipped', quantity: 2 });
|
||||
expect(result.total).toBe(1);
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/orders?page=1&page_size=20&search=buyer', expect.objectContaining({ method: 'GET' }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getOrders maps unsupported backend statuses to unknown', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse({
|
||||
data: [{ order_id: 'o-unknown', order_status: 'legacy_status' }],
|
||||
})));
|
||||
const result = await getOrders();
|
||||
const result = await getOrders(); /* result 表示处理结果。 */
|
||||
expect(result.data[0].status).toBe('unknown');
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('订单查询和导入 API 转发外部取消信号', async () => {
|
||||
// fetchMock 是同时验证订单查询和文件上传请求控制参数的替身。
|
||||
@@ -209,7 +209,7 @@ test('订单查询和导入 API 转发外部取消信号', async () => {
|
||||
await importOrders(new FormData(), { signal: controller.signal });
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/orders?page=1&page_size=20', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/orders/import', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('Dashboard 统计 API 转发外部取消信号', async () => {
|
||||
// fetchMock 验证 Dashboard 的概览、趋势和订单明细共用同一个取消信号。
|
||||
@@ -229,7 +229,7 @@ test('Dashboard 统计 API 转发外部取消信号', async () => {
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/analytics/dashboard', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, expect.stringContaining('/api/v1/analytics/orders?'), expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(4, expect.stringContaining('/api/v1/analytics/orders/valid?'), expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('Settings 配置、模型和凭据 API 转发外部取消信号', async () => {
|
||||
// fetchMock 验证 Settings 的读取、模型发现和凭据保存共享取消控制能力。
|
||||
@@ -249,7 +249,7 @@ test('Settings 配置、模型和凭据 API 转发外部取消信号', async ()
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/settings/ai-models', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/session', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(4, '/api/v1/session/credentials', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('通知渠道和 SMTP API 转发外部取消信号', async () => {
|
||||
// fetchMock 验证渠道读取、保存和 SMTP 读写都支持取消控制。
|
||||
@@ -269,7 +269,7 @@ test('通知渠道和 SMTP API 转发外部取消信号', async () => {
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/notifications/channels/channel-1', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/settings/system', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(4, '/api/v1/settings/system', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getShippingRulesPage sends filters and preserves pagination metadata', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({
|
||||
@@ -279,7 +279,7 @@ test('getShippingRulesPage sends filters and preserves pagination metadata', asy
|
||||
page_size: 20,
|
||||
total_pages: 2,
|
||||
trigger_counts: { order_paid: 8, buyer_reviewed: 7, review_missing_timeout: 6 },
|
||||
}));
|
||||
})); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
const result = await getShippingRulesPage({
|
||||
@@ -289,7 +289,7 @@ test('getShippingRulesPage sends filters and preserves pagination metadata', asy
|
||||
search: ' 商品 ',
|
||||
page: 2,
|
||||
pageSize: 20,
|
||||
});
|
||||
}); /* result 表示处理结果。 */
|
||||
|
||||
expect(result).toMatchObject({
|
||||
total: 21,
|
||||
@@ -303,59 +303,59 @@ test('getShippingRulesPage sends filters and preserves pagination metadata', asy
|
||||
'/api/v1/automation-rules?page=2&page_size=20&cookie_id=acc1&trigger_type=order_paid&enabled=false&search=%E5%95%86%E5%93%81',
|
||||
expect.objectContaining({ method: 'GET', credentials: 'include' }),
|
||||
);
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getValidOrders accepts wrapped responses', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({
|
||||
orders: [{ order_id: 'o2', order_status: 'completed', quantity: '3' }],
|
||||
}));
|
||||
})); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
vi.spyOn(Date.prototype, 'getTimezoneOffset').mockReturnValue(-480);
|
||||
const result = await getValidOrders({ start_date: '2026-01-01', end_date: '2026-01-02' });
|
||||
const result = await getValidOrders({ start_date: '2026-01-01', end_date: '2026-01-02' }); /* result 表示处理结果。 */
|
||||
expect(result).toEqual({
|
||||
orders: [expect.objectContaining({ id: 'o2', status: 'completed', quantity: 3 })],
|
||||
total: 1,
|
||||
truncated: false,
|
||||
});
|
||||
expect(fetchMock.mock.calls[0][0]).toContain('timezone_offset_minutes=480');
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getOrderAnalytics sends the browser timezone offset', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ revenue_stats: {}, daily_stats: [], status_stats: [], city_stats: [] }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ revenue_stats: {}, daily_stats: [], status_stats: [], city_stats: [] })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
vi.spyOn(Date.prototype, 'getTimezoneOffset').mockReturnValue(-330);
|
||||
await getOrderAnalytics({ start_date: '2026-01-01', end_date: '2026-01-02' });
|
||||
expect(fetchMock.mock.calls[0][0]).toContain('timezone_offset_minutes=330');
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('paid orders are normalized to pending shipment', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse({ data: [{ order_id: 'o-paid', order_status: 'paid' }] })));
|
||||
const result = await getOrders();
|
||||
const result = await getOrders(); /* result 表示处理结果。 */
|
||||
expect(result.data[0].status).toBe('pending_ship');
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('completeQRVerification sends only the immutable target account', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, account_id: 'acc1' }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, account_id: 'acc1' })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await completeQRVerification('session-1', 'acc1');
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/qr-login/complete-verification/session-1', expect.objectContaining({
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ target_account_id: 'acc1' }),
|
||||
}));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('deleteItemPublishBatch removes an abandoned preview', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await deleteItemPublishBatch('preview-1');
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/items/publish-batches/preview-1', expect.objectContaining({
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
}));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('publishItem allows virtual publishing without an optional location', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await publishItem({
|
||||
cookie_id: 'acc1',
|
||||
@@ -366,9 +366,9 @@ test('publishItem allows virtual publishing without an optional location', async
|
||||
postage_mode: 'none',
|
||||
images: [],
|
||||
});
|
||||
const body = fetchMock.mock.calls[0][1].body as FormData;
|
||||
const body = fetchMock.mock.calls[0][1].body as FormData; /* body 表示请求体。 */
|
||||
expect(body.get('location')).toBeNull();
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getItems normalizes multi-spec flags from backend values', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse([{
|
||||
@@ -385,7 +385,7 @@ test('getItems normalizes multi-spec flags from backend values', async () => {
|
||||
multi_quantity_delivery: 1,
|
||||
}])));
|
||||
|
||||
const items = await getItems();
|
||||
const items = await getItems(); /* items 表示商品集合。 */
|
||||
expect(items[0]).toMatchObject({
|
||||
id: 'cookie-1-item-1',
|
||||
is_multi_spec: false,
|
||||
@@ -398,10 +398,10 @@ test('getItems normalizes multi-spec flags from backend values', async () => {
|
||||
is_multi_qty_ship: true,
|
||||
multi_quantity_delivery: true,
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getItems forwards the selected account filter', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse([]));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse([])); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await getItems('account-2');
|
||||
@@ -410,7 +410,7 @@ test('getItems forwards the selected account filter', async () => {
|
||||
method: 'GET',
|
||||
credentials: 'include',
|
||||
}));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getSystemSettings normalizes numeric renewal retention', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse({
|
||||
@@ -418,13 +418,13 @@ test('getSystemSettings normalizes numeric renewal retention', async () => {
|
||||
renewal_log_retention_days: 'invalid',
|
||||
})));
|
||||
|
||||
const settings = await getSystemSettings();
|
||||
const settings = await getSystemSettings(); /* settings 表示settings。 */
|
||||
expect(settings.ai_model).toBe('qwen-plus');
|
||||
expect(settings.renewal_log_retention_days).toBe(10);
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('logout calls backend session invalidation route', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await logout();
|
||||
@@ -433,10 +433,10 @@ test('logout calls backend session invalidation route', async () => {
|
||||
credentials: 'include',
|
||||
}));
|
||||
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('account cookie APIs include login_method when provided', async () => {
|
||||
const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(jsonResponse({ success: true })));
|
||||
const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(jsonResponse({ success: true })) /* 回调函数负责当前业务流程。 */); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await addAccount('acc1', 'unb=acc1', 'qr_scan');
|
||||
@@ -460,10 +460,10 @@ test('account cookie APIs include login_method when provided', async () => {
|
||||
value: 'unb=acc1; x=1',
|
||||
login_method: 'qr_scan',
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('account editor settings use one aggregate request', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await updateAccountSettings('acc1', {
|
||||
remark: 'main', auto_confirm: false, pause_duration: 5,
|
||||
@@ -475,7 +475,7 @@ test('account editor settings use one aggregate request', async () => {
|
||||
remark: 'main', auto_confirm: false, pause_duration: 5,
|
||||
username: 'user', show_browser: true, channel_ids: [1, 2],
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getAccountDetails normalizes show_browser and never exposes password', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse([{
|
||||
@@ -491,7 +491,7 @@ test('getAccountDetails normalizes show_browser and never exposes password', asy
|
||||
login_password: 'should-not-leak',
|
||||
}])));
|
||||
|
||||
const accounts = await getAccountDetails();
|
||||
const accounts = await getAccountDetails(); /* accounts 表示账号集合。 */
|
||||
expect(accounts[0]).toMatchObject({
|
||||
id: 'acc1',
|
||||
username: 'login-user',
|
||||
@@ -500,10 +500,10 @@ test('getAccountDetails normalizes show_browser and never exposes password', asy
|
||||
paused_until: 1780000000,
|
||||
paused: true,
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateAccountLoginInfo sends exactly provided fields', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateAccountLoginInfo('acc1', { username: 'login-user', show_browser: false });
|
||||
@@ -515,10 +515,10 @@ test('updateAccountLoginInfo sends exactly provided fields', async () => {
|
||||
username: 'login-user',
|
||||
show_browser: false,
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateAccountLoginInfo can request explicit password clearing', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateAccountLoginInfo('acc1', { username: 'login-user', clear_password: true, show_browser: false });
|
||||
@@ -527,10 +527,10 @@ test('updateAccountLoginInfo can request explicit password clearing', async () =
|
||||
clear_password: true,
|
||||
show_browser: false,
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateItem sends only the fields selected by the editor', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateItem('acc1', 'item1', { item_title: '改名商品' });
|
||||
@@ -541,13 +541,13 @@ test('updateItem sends only the fields selected by the editor', async () => {
|
||||
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({
|
||||
item_title: '改名商品',
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('password login service uses upstream-compatible routes', async () => {
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true, session_id: 'sid', status: 'processing' }))
|
||||
.mockResolvedValueOnce(jsonResponse({ status: 'success', account_id: 'acc1', cookie_count: 2 }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }));
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await passwordLogin({ account_id: 'acc1', account: 'u', password: 'p' });
|
||||
@@ -561,13 +561,13 @@ test('password login service uses upstream-compatible routes', async () => {
|
||||
password: 'p',
|
||||
});
|
||||
|
||||
const status = await checkPasswordLoginStatus('sid');
|
||||
const status = await checkPasswordLoginStatus('sid'); /* status 表示status。 */
|
||||
expect(status.status).toBe('success');
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/password-login/check/sid', expect.objectContaining({ method: 'GET' }));
|
||||
|
||||
await cancelPasswordLogin('sid');
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/password-login/cancel/sid', expect.objectContaining({ method: 'DELETE' }));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('账号编辑子模块请求支持取消过期响应', async () => {
|
||||
// fetchMock 是验证请求取消信号透传的测试替身。
|
||||
@@ -576,7 +576,7 @@ test('账号编辑子模块请求支持取消过期响应', async () => {
|
||||
.mockResolvedValueOnce(jsonResponse({ ai_enabled: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true, session_id: 'sid' }));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const controller = new AbortController();
|
||||
const controller = new AbortController(); /* controller 表示controller。 */
|
||||
|
||||
await getLongLoginSettings('acc1', { signal: controller.signal });
|
||||
await getAccountAISettings('acc1', { signal: controller.signal });
|
||||
@@ -585,7 +585,7 @@ test('账号编辑子模块请求支持取消过期响应', async () => {
|
||||
expect(fetchMock.mock.calls[0][1].signal).toBeInstanceOf(AbortSignal);
|
||||
expect(fetchMock.mock.calls[1][1].signal).toBeInstanceOf(AbortSignal);
|
||||
expect(fetchMock.mock.calls[2][1].signal).toBeInstanceOf(AbortSignal);
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getShippingRules exposes buyer reviewed gift rules as automation rules', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse([{
|
||||
@@ -610,7 +610,7 @@ test('getShippingRules exposes buyer reviewed gift rules as automation rules', a
|
||||
}],
|
||||
}])));
|
||||
|
||||
const rules = await getShippingRules();
|
||||
const rules = await getShippingRules(); /* rules 表示规则集合。 */
|
||||
expect(rules[0]).toMatchObject({
|
||||
id: '12',
|
||||
trigger_type: 'buyer_reviewed',
|
||||
@@ -622,7 +622,7 @@ test('getShippingRules exposes buyer reviewed gift rules as automation rules', a
|
||||
spec_value: '赠品',
|
||||
card_id: 7,
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('getReplyRules labels keyword matching according to engine contains behavior', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse([{
|
||||
@@ -631,10 +631,10 @@ test('getReplyRules labels keyword matching according to engine contains behavio
|
||||
reply: '马上安排',
|
||||
type: 'image',
|
||||
image_url: 'https://img.example/reply.png',
|
||||
}]));
|
||||
}])); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
const rules = await getReplyRules('acc1');
|
||||
const rules = await getReplyRules('acc1'); /* rules 表示规则集合。 */
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/reply-rules/acc1/typed', expect.objectContaining({ method: 'GET' }));
|
||||
expect(rules[0]).toMatchObject({
|
||||
id: '42',
|
||||
@@ -644,10 +644,10 @@ test('getReplyRules labels keyword matching according to engine contains behavio
|
||||
type: 'image',
|
||||
image_url: 'https://img.example/reply.png',
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateReplyRule preserves keyword image metadata when saving text edits', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateReplyRule({ id: '42', keyword: '发货', reply_content: '稍后安排', item_id: 'item-1' }, 'acc1');
|
||||
@@ -660,20 +660,20 @@ test('updateReplyRule preserves keyword image metadata when saving text edits',
|
||||
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({
|
||||
keyword: '发货', reply: '稍后安排', item_id: 'item-1', type: 'text', image_url: '',
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateReplyRule clears stale content when switching reply type', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateReplyRule({ id: '42', keyword: '发货', type: 'image', image_url: 'https://img.example/new.png' }, 'acc1');
|
||||
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({
|
||||
keyword: '发货', reply: '', item_id: '', type: 'image', image_url: 'https://img.example/new.png',
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('deleteReplyRule deletes one stable keyword row instead of replacing the list', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await deleteReplyRule('42', 'acc1');
|
||||
@@ -682,10 +682,10 @@ test('deleteReplyRule deletes one stable keyword row instead of replacing the li
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
}));
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('createNotificationChannel persists email recipient as to_email config', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await createNotificationChannel({
|
||||
@@ -700,16 +700,16 @@ test('createNotificationChannel persists email recipient as to_email config', as
|
||||
},
|
||||
});
|
||||
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body);
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body); /* body 表示请求体。 */
|
||||
expect(body.type).toBe('email');
|
||||
expect(JSON.parse(body.config)).toMatchObject({
|
||||
to_email: '[email protected]',
|
||||
});
|
||||
expect(JSON.parse(body.config)).not.toHaveProperty('from');
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('createNotificationChannel allows email channel to rely on system SMTP settings', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await createNotificationChannel({
|
||||
@@ -720,15 +720,15 @@ test('createNotificationChannel allows email channel to rely on system SMTP sett
|
||||
},
|
||||
});
|
||||
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body);
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body); /* body 表示请求体。 */
|
||||
expect(body.type).toBe('email');
|
||||
expect(JSON.parse(body.config)).toEqual({
|
||||
to_email: '[email protected]',
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateNotificationChannel supports partial enabled updates', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateNotificationChannel('7', { enabled: false });
|
||||
@@ -740,10 +740,10 @@ test('updateNotificationChannel supports partial enabled updates', async () => {
|
||||
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({
|
||||
enabled: false,
|
||||
});
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateShippingRule posts buyer reviewed gift payload to automation-rules', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 1 }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 1 })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateShippingRule({
|
||||
@@ -764,7 +764,7 @@ test('updateShippingRule posts buyer reviewed gift payload to automation-rules',
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
}));
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body);
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body); /* body 表示请求体。 */
|
||||
expect(body).toMatchObject({
|
||||
cookie_id: 'cookie-1',
|
||||
item_id: 'item-1',
|
||||
@@ -778,10 +778,10 @@ test('updateShippingRule posts buyer reviewed gift payload to automation-rules',
|
||||
sort_order: 1,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateShippingRule posts every matching card action before confirm shipment', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 3 }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 3 })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateShippingRule({
|
||||
@@ -809,7 +809,7 @@ test('updateShippingRule posts every matching card action before confirm shipmen
|
||||
],
|
||||
});
|
||||
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body);
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body); /* body 表示请求体。 */
|
||||
expect(body.trigger_type).toBe('order_paid');
|
||||
expect(body.actions).toEqual([
|
||||
expect.objectContaining({
|
||||
@@ -831,10 +831,10 @@ test('updateShippingRule posts every matching card action before confirm shipmen
|
||||
expect(JSON.parse(body.actions[0].config_json)).toEqual({ spec_name: '套餐', spec_value: '30天', delay_override: false });
|
||||
expect(JSON.parse(body.actions[1].config_json)).toEqual({ spec_name: '套餐', spec_value: '30天', delay_override: true });
|
||||
expect(body.actions[1].delay_seconds).toBe(0);
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateShippingRule preserves text actions while editing card variants', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 4 }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 4 })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateShippingRule({
|
||||
@@ -846,17 +846,17 @@ test('updateShippingRule preserves text actions while editing card variants', as
|
||||
actions: [{ action_type: 'send_text', message_template: '发货提示', enabled: true, sort_order: 2 }],
|
||||
});
|
||||
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body);
|
||||
expect(body.actions.map((action: { action_type: string }) => action.action_type)).toEqual([
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body); /* body 表示请求体。 */
|
||||
expect(body.actions.map((action: { /* action_type 表示actiontype。 */ action_type: string }) => action.action_type /* 回调函数负责当前业务流程。 */)).toEqual([
|
||||
'send_card',
|
||||
'send_text',
|
||||
'confirm_shipment',
|
||||
]);
|
||||
expect(body.actions[1].message_template).toBe('发货提示');
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
test('updateShippingRule posts review request text action without card requirement', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 2 }));
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 2 })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await updateShippingRule({
|
||||
@@ -873,7 +873,7 @@ test('updateShippingRule posts review request text action without card requireme
|
||||
}],
|
||||
});
|
||||
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body);
|
||||
const body = JSON.parse(fetchMock.mock.calls[0][1].body); /* body 表示请求体。 */
|
||||
expect(body.trigger_type).toBe('review_missing_timeout');
|
||||
expect(body.actions).toEqual([
|
||||
expect.objectContaining({
|
||||
@@ -882,7 +882,7 @@ test('updateShippingRule posts review request text action without card requireme
|
||||
message_template: '亲,方便的话麻烦给个评价~',
|
||||
}),
|
||||
]);
|
||||
});
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
// 会话 API 使用版本化兼容入口。
|
||||
const runVersionedSessionAPITest = async () => {
|
||||
|
||||
Reference in new issue
Block a user