阶段七:完成Notifications React feature化与渠道绑定边界

This commit is contained in:
Christ committed 2026-08-15 01:21:47 +08:00
1 parent b128ce60db
commit 2ec7bec05f
20 files changed
+1338 -1785

No files matched your search

+20
View File
@@ -160,6 +160,26 @@ test('订单查询和导入 API 转发外部取消信号', async () => {
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/orders/import', expect.objectContaining({ signal: expect.any(AbortSignal) }));
});
test('通知渠道和 SMTP API 转发外部取消信号', async () => {
// fetchMock 验证渠道读取、保存和 SMTP 读写都支持取消控制。
const fetchMock = vi.fn()
.mockResolvedValueOnce(jsonResponse([]))
.mockResolvedValueOnce(jsonResponse({ success: true }))
.mockResolvedValueOnce(jsonResponse({ data: {} }))
.mockResolvedValueOnce(jsonResponse({ success: true }));
vi.stubGlobal('fetch', fetchMock);
// controller 是通知 feature 传给服务 API 的共享取消控制器。
const controller = new AbortController();
await getNotificationChannels({ signal: controller.signal });
await updateNotificationChannel('channel-1', { enabled: false }, { signal: controller.signal });
await getSystemSettings({ signal: controller.signal });
await updateSystemSettings({ smtp_server: 'smtp.example.com' }, { signal: controller.signal });
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/notifications/channels', expect.objectContaining({ signal: expect.any(AbortSignal) }));
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({
data: [{ id: 7, name: '付款规则', trigger_type: 'order_paid', enabled: false, actions: [] }],
+12 -12
View File
@@ -880,16 +880,16 @@ export const deleteReplyRule = async (id: string, cookieId: string): Promise<Ope
}
// Settings
export const getSystemSettings = async (): Promise<SystemSettings> => {
const res = await get<{data: SystemSettings}>('/api/v1/settings/system');
export const getSystemSettings = async (options?: RequestControlOptions): Promise<SystemSettings> => {
const res = await get<{data: SystemSettings}>('/api/v1/settings/system', undefined, options);
return normalizeSettings(res.data || res); // handle {success:true, data: {...}} wrapper if exists
};
export const updateSystemSettings = async (settings: Partial<SystemSettings>): Promise<OperationResponse> => {
export const updateSystemSettings = async (settings: Partial<SystemSettings>, options?: RequestControlOptions): Promise<OperationResponse> => {
const payload = Object.fromEntries(
Object.entries(settings).filter(([, value]) => value !== undefined && value !== null),
);
return put('/api/v1/settings/system', payload);
return put('/api/v1/settings/system', payload, options);
};
export const getAccountAISettings = async (cookieId: string, options?: RequestControlOptions): Promise<AIReplySettingsResponse> => {
@@ -956,15 +956,15 @@ export const getNotificationChannels = async (options?: RequestControlOptions):
return { success: true, data: channels };
}
export const createNotificationChannel = async (data: { name: string; type: string; config: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }): Promise<MutationIDResponse> => {
export const createNotificationChannel = async (data: { name: string; type: string; config: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }, options?: RequestControlOptions): Promise<MutationIDResponse> => {
return post('/api/v1/notifications/channels', {
...data,
config: JSON.stringify(data.config),
event_types: stringifyNotificationEventTypes(data.event_types)
});
}, options);
}
export const updateNotificationChannel = async (channelId: string, data: { name?: string; type?: string; config?: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }): Promise<OperationResponse> => {
export const updateNotificationChannel = async (channelId: string, data: { name?: string; type?: string; config?: Record<string, unknown>; event_types?: NotificationEventType[]; enabled?: boolean }, options?: RequestControlOptions): Promise<OperationResponse> => {
const payload: Record<string, unknown> = { ...data };
if ('config' in data) {
payload.config = JSON.stringify(data.config);
@@ -972,11 +972,11 @@ export const updateNotificationChannel = async (channelId: string, data: { name?
if ('event_types' in data) {
payload.event_types = stringifyNotificationEventTypes(data.event_types);
}
return put(`/api/v1/notifications/channels/${channelId}`, payload);
return put(`/api/v1/notifications/channels/${channelId}`, payload, options);
}
export const deleteNotificationChannel = async (channelId: string): Promise<OperationResponse> => {
return del(`/api/v1/notifications/channels/${channelId}`);
export const deleteNotificationChannel = async (channelId: string, options?: RequestControlOptions): Promise<OperationResponse> => {
return del(`/api/v1/notifications/channels/${channelId}`, undefined, options);
}
// Message Notifications
@@ -1021,8 +1021,8 @@ export const setAccountBindings = async (cookieId: string, channelIds: number[])
}
// 测试发送
export const testNotificationChannel = async (channelId: string): Promise<OperationResponse> => {
return post(`/api/v1/notifications/channels/${channelId}/test`, {});
export const testNotificationChannel = async (channelId: string, options?: RequestControlOptions): Promise<OperationResponse> => {
return post(`/api/v1/notifications/channels/${channelId}/test`, {}, options);
}
// Default Reply