API版本化:迁移管理员与统计分析入口
This commit is contained in:
1 parent
acd9470d51
commit
a204876400
9 files changed
+147
-11
No files matched your search
@@ -12,7 +12,7 @@ import {
|
||||
getItemPublishBatches, getItemPublishBatch, startItemPublishBatch,
|
||||
getNotificationChannels, getMessageNotifications, getAccountBindings,
|
||||
getOrders, getOrderDetail, updateOrder,
|
||||
getOrderAnalytics,
|
||||
getAdminStats, getDashboardStats, getOrderAnalytics,
|
||||
getReplyRules, getDefaultReplies, getDefaultReply, updateDefaultReply, deleteDefaultReply, clearDefaultReplyRecords,
|
||||
getShippingRules,
|
||||
getShippingRulesPage,
|
||||
@@ -1084,3 +1084,26 @@ const runVersionedReplyAPITest = async () => {
|
||||
};
|
||||
|
||||
test('keyword and default reply APIs use versioned compatibility routes', runVersionedReplyAPITest);
|
||||
|
||||
// 管理员、仪表盘和订单分析 API 使用版本化兼容入口。
|
||||
const runVersionedAdminAnalyticsAPITest = async () => {
|
||||
// fetchMock 是管理员和统计分析请求的测试替身。
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse({ total_users: 1, total_cookies: 1, active_cookies: 1, total_cards: 0, total_keywords: 0, total_orders: 0 }))
|
||||
.mockResolvedValueOnce(jsonResponse({ total_cookies: 1, active_cookies: 1, total_cards: 0, available_card_stock: 0, total_keywords: 0, total_orders: 0 }))
|
||||
.mockResolvedValueOnce(jsonResponse({ revenue_stats: {}, daily_stats: [], status_stats: [], city_stats: [], item_stats: [] }))
|
||||
.mockResolvedValueOnce(jsonResponse({ orders: [], total: 0, page: 1, page_size: 500, truncated: false }));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await getAdminStats();
|
||||
await getDashboardStats();
|
||||
await getOrderAnalytics({ start_date: '2026-01-01', end_date: '2026-01-02' });
|
||||
await getValidOrders({ start_date: '2026-01-01', end_date: '2026-01-02' });
|
||||
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/admin/stats', expect.objectContaining({ method: 'GET' }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/analytics/dashboard', expect.objectContaining({ method: 'GET' }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, expect.stringContaining('/api/v1/analytics/orders?start_date=2026-01-01&end_date=2026-01-02'), expect.objectContaining({ method: 'GET' }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(4, expect.stringContaining('/api/v1/analytics/orders/valid?start_date=2026-01-01&end_date=2026-01-02'), expect.objectContaining({ method: 'GET' }));
|
||||
};
|
||||
|
||||
test('admin and analytics APIs use versioned compatibility routes', runVersionedAdminAnalyticsAPITest);
|
||||
@@ -376,11 +376,11 @@ export const importOrders = async (data: Partial<Order>[] | FormData): Promise<O
|
||||
|
||||
// Stats
|
||||
export const getAdminStats = async (): Promise<AdminStatsResponse> => {
|
||||
return get('/admin/stats');
|
||||
return get('/api/v1/admin/stats');
|
||||
};
|
||||
|
||||
export const getDashboardStats = async (): Promise<DashboardStatsResponse> => {
|
||||
return get('/dashboard/stats');
|
||||
return get('/api/v1/analytics/dashboard');
|
||||
};
|
||||
|
||||
export const getOrderAnalytics = async (daysOrParams: number | {start_date: string; end_date: string} = 7): Promise<OrderAnalyticsResponse> => {
|
||||
@@ -398,7 +398,7 @@ export const getOrderAnalytics = async (daysOrParams: number | {start_date: stri
|
||||
params = daysOrParams;
|
||||
}
|
||||
|
||||
return get('/analytics/orders', {
|
||||
return get('/api/v1/analytics/orders', {
|
||||
...params,
|
||||
timezone_offset_minutes: -new Date().getTimezoneOffset(),
|
||||
});
|
||||
@@ -411,7 +411,7 @@ export interface ValidOrdersResult {
|
||||
}
|
||||
|
||||
export const getValidOrders = async (dateRange: {start_date: string; end_date: string}): Promise<ValidOrdersResult> => {
|
||||
const res = await get<ValidOrdersResponse | ValidOrderResponse[]>('/analytics/orders/valid', {
|
||||
const res = await get<ValidOrdersResponse | ValidOrderResponse[]>('/api/v1/analytics/orders/valid', {
|
||||
start_date: dateRange.start_date,
|
||||
end_date: dateRange.end_date,
|
||||
timezone_offset_minutes: -new Date().getTimezoneOffset(),
|
||||
|
||||
Reference in new issue
Block a user