W1-W3 实现企业微信个人应用消息通知

这个提交包含在:
2026-05-11 09:17:00 +08:00
父节点 805e050ba8
当前提交 b1ae41fa99
共修改 12 个文件,包含 869 行新增和 111 行删除
@@ -41,6 +41,9 @@ function createPrismaState({ employees = [], channels = [] } = {}) {
.map((item) => ({
id: item.id,
roles: (item.roles ?? []).map((roleCode) => ({ role_code: roleCode })),
wecom_identity_binding: item.externalUserId
? { external_user_id: item.externalUserId }
: null,
}));
}),
},
@@ -186,6 +189,65 @@ describe('notificationDispatcher', () => {
expect(deliveryState[0]).toEqual(expect.objectContaining({ status: 'success' }));
});
it('passes bound wecom user ids to channel sender', async () => {
const { prisma } = createPrismaState({
employees: [
{
id: 'manager-1',
status: 'active',
notification_push_enabled: true,
roles: ['manager'],
externalUserId: 'oa_smoke_02',
},
],
channels: [buildChannel({ config_json: { mode: 'wecom_app_message', routing: {} } })],
});
const sendMessage = vi.fn().mockResolvedValue({
ok: true,
retryable: false,
code: 'wecom_app_sent',
message: null,
response: { errcode: 0 },
});
await dispatchNotificationBatch({
prisma,
config: {
imNotifierEnabled: true,
appOrigin: 'https://oa.example.com',
jwtSecret: 'test-secret',
},
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
requestId: 'req-wecom-bound',
notifications: [
{
id: 'notification-1',
recipient_employee_id: 'manager-1',
target_type: 'workflow_task',
},
],
type: 'workflow.task_assigned',
title: '测试待办',
body: '请处理审批',
targetType: 'workflow_task',
targetId: 'task-1',
targetPath: '/workflow/tasks/task-1',
sendMessage,
retryDelayMs: 0,
});
expect(sendMessage).toHaveBeenCalledTimes(1);
expect(sendMessage.mock.calls[0][0]).toEqual(
expect.objectContaining({
prisma,
payload: expect.objectContaining({
recipientEmployeeIds: ['manager-1'],
recipientExternalUserIds: ['oa_smoke_02'],
}),
}),
);
});
it('retries retryable failures until a later success', async () => {
const { prisma, deliveryState } = createPrismaState({
employees: [