API版本化:迁移订单刷新与批量操作入口
This commit is contained in:
1 parent
50a135fc29
commit
bc97f35fda
8 files changed
+148
-11
No files matched your search
@@ -24,7 +24,7 @@ import {
|
||||
passwordLogin,
|
||||
resolveAutomationRun,
|
||||
resolveDeferredAutomationTask,
|
||||
syncOrders,
|
||||
syncOrders, syncSingleOrder, manualShipOrder,
|
||||
updateReplyRule,
|
||||
deleteReplyRule,
|
||||
updateAccountCookie,
|
||||
@@ -111,8 +111,8 @@ test('order multipart requests use the shared authenticated form request path',
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
await syncOrders('acc1', 'pending_ship');
|
||||
await importOrders(new FormData());
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/orders/refresh', expect.objectContaining({ method: 'POST', credentials: 'include', body: expect.any(FormData) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/orders/import', expect.objectContaining({ method: 'POST', credentials: 'include', body: expect.any(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 () => {
|
||||
@@ -835,3 +835,20 @@ const runVersionedOrderAPITest = async () => {
|
||||
};
|
||||
|
||||
test('order list, detail, and update APIs use versioned compatibility routes', runVersionedOrderAPITest);
|
||||
|
||||
// 订单刷新与批量操作 API 使用版本化兼容入口。
|
||||
const runVersionedOrderRefreshAPITest = async () => {
|
||||
// fetchMock 是订单刷新与批量请求的测试替身。
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await syncSingleOrder('order-1');
|
||||
await manualShipOrder(['order-1'], 'status_only');
|
||||
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/orders/order-1/refresh', expect.objectContaining({ method: 'POST', credentials: 'include' }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/orders/manual-ship', expect.objectContaining({ method: 'POST', credentials: 'include' }));
|
||||
};
|
||||
|
||||
test('order refresh and batch APIs use versioned compatibility routes', runVersionedOrderRefreshAPITest);
|
||||
@@ -355,15 +355,15 @@ export const syncOrders = async (cookieId?: string, status?: string): Promise<Or
|
||||
if (cookieId) formData.append('cookie_id', cookieId);
|
||||
if (status) formData.append('status', status);
|
||||
|
||||
return postForm('/api/orders/refresh', formData);
|
||||
return postForm('/api/v1/orders/refresh', formData);
|
||||
};
|
||||
|
||||
export const syncSingleOrder = async (orderId: string): Promise<OrderSingleRefreshResponse> => {
|
||||
return post(`/api/orders/${orderId}/refresh`);
|
||||
return post(`/api/v1/orders/${orderId}/refresh`);
|
||||
};
|
||||
|
||||
export const manualShipOrder = async (orderIds: string[], shipMode: 'status_only' | 'full_delivery'): Promise<OrderBatchResponse> => {
|
||||
return post('/api/orders/manual-ship', {
|
||||
return post('/api/v1/orders/manual-ship', {
|
||||
order_ids: orderIds,
|
||||
ship_mode: shipMode,
|
||||
});
|
||||
@@ -371,7 +371,7 @@ export const manualShipOrder = async (orderIds: string[], shipMode: 'status_only
|
||||
|
||||
export const importOrders = async (data: Partial<Order>[] | FormData): Promise<OrderBatchResponse> => {
|
||||
const isFormData = data instanceof FormData;
|
||||
return isFormData ? postForm('/api/orders/import', data) : post('/api/orders/import', data);
|
||||
return isFormData ? postForm('/api/v1/orders/import', data) : post('/api/v1/orders/import', data);
|
||||
}
|
||||
|
||||
// Stats
|
||||
|
||||
Reference in new issue
Block a user