API版本化:迁移账号摘要与状态入口
This commit is contained in:
1 parent
42cc9ce675
commit
415a3adc5f
10 files changed
+195
-11
No files matched your search
@@ -6,7 +6,7 @@ import {
|
||||
checkPasswordLoginStatus,
|
||||
completeQRVerification,
|
||||
createNotificationChannel,
|
||||
getAccountDetails,
|
||||
getAccountDetails, getAccountRuntimeStatuses, updateAccountStatus,
|
||||
getAutomationIssues,
|
||||
getItems,
|
||||
getItemPublishBatches,
|
||||
@@ -763,3 +763,23 @@ const runVersionedSessionAPITest = async () => {
|
||||
};
|
||||
|
||||
test('session APIs use versioned compatibility routes', runVersionedSessionAPITest);
|
||||
|
||||
// 账号摘要、详情和状态 API 使用版本化兼容入口。
|
||||
const runVersionedAccountAPITest = async () => {
|
||||
// fetchMock 是账号 API 请求的测试替身。
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse([{ id: 'acc1', enabled: true, remark: '主账号' }]))
|
||||
.mockResolvedValueOnce(jsonResponse({ acc1: { state: 'error', connected: false, failures: 0, updated_at: '' } }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success: true }));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await getAccountDetails();
|
||||
await getAccountRuntimeStatuses();
|
||||
await updateAccountStatus('acc1', false);
|
||||
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/accounts/details', expect.objectContaining({ method: 'GET' }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/accounts/runtime-status', expect.objectContaining({ method: 'GET' }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/accounts/acc1/status', expect.objectContaining({ method: 'PUT' }));
|
||||
};
|
||||
|
||||
test('account summary and status APIs use versioned compatibility routes', runVersionedAccountAPITest);
|
||||
@@ -67,7 +67,7 @@ const accountAvatarURL = (item: AccountSummaryResponse, version: string): string
|
||||
};
|
||||
|
||||
export const getAccountDetails = async (options?: RequestControlOptions): Promise<AccountDetail[]> => {
|
||||
const data = await get<AccountSummaryResponse[]>('/cookies/details', undefined, options);
|
||||
const data = await get<AccountSummaryResponse[]>('/api/v1/accounts/details', undefined, options);
|
||||
const avatarVersion = Date.now().toString();
|
||||
return data.map(item => ({
|
||||
id: item.id,
|
||||
@@ -160,7 +160,7 @@ export interface AccountRuntimeStatus {
|
||||
}
|
||||
|
||||
export const getAccountRuntimeStatuses = async (options?: RequestControlOptions): Promise<Record<string, AccountRuntimeStatus>> => {
|
||||
return get('/cookies/runtime-status', undefined, options);
|
||||
return get('/api/v1/accounts/runtime-status', undefined, options);
|
||||
};
|
||||
|
||||
export const generateQRLogin = async (options?: RequestControlOptions): Promise<QRLoginGenerateResponse> => {
|
||||
@@ -187,7 +187,7 @@ export const completeQRVerification = async (
|
||||
|
||||
|
||||
export const updateAccountStatus = async (id: string, enabled: boolean): Promise<OperationResponse> => {
|
||||
return put(`/cookies/${id}/status`, { enabled });
|
||||
return put(`/api/v1/accounts/${id}/status`, { enabled });
|
||||
};
|
||||
|
||||
export const deleteAccount = async (id: string): Promise<OperationResponse> => {
|
||||
|
||||
Reference in new issue
Block a user