feat(P19IM1-1,P19IM1-2): 新增通知渠道配置与Outbox派发
这个提交包含在:
@@ -1,42 +1,46 @@
|
||||
const dispatcher = require("../../../../src/services/integrations/dispatcher");
|
||||
|
||||
describe("Integration Dispatcher", () => {
|
||||
it("dispatches erp.reimbursement.paid", async () => {
|
||||
const result = await dispatcher.dispatchOutboxEvent({
|
||||
config: { erpSyncEnabled: true, erpSyncProvider: "mock" },
|
||||
eventType: "erp.reimbursement.paid",
|
||||
payload: { reimbursementId: 1 },
|
||||
});
|
||||
expect(result.channel).toBe("erp");
|
||||
expect(result.code).toBe("mock_synced");
|
||||
it("dispatches erp.reimbursement.paid", async () => {
|
||||
const result = await dispatcher.dispatchOutboxEvent({
|
||||
config: { erpSyncEnabled: true, erpSyncProvider: "mock" },
|
||||
eventType: "erp.reimbursement.paid",
|
||||
payload: { reimbursementId: "rb-1", formNumber: "BX-001" },
|
||||
});
|
||||
|
||||
it("throws IntegrationDispatchError if erp fails", async () => {
|
||||
await expect(
|
||||
dispatcher.dispatchOutboxEvent({
|
||||
config: { erpSyncEnabled: false },
|
||||
eventType: "erp.reimbursement.paid",
|
||||
payload: { reimbursementId: 1 },
|
||||
})
|
||||
).rejects.toThrow(dispatcher.IntegrationDispatchError);
|
||||
expect(result.channel).toBe("erp");
|
||||
expect(result.code).toBe("mock_synced");
|
||||
});
|
||||
|
||||
it("dispatches notification.im with mock channel", async () => {
|
||||
const result = await dispatcher.dispatchOutboxEvent({
|
||||
prisma: {
|
||||
notificationChannel: {
|
||||
findUnique: vi.fn().mockResolvedValue({
|
||||
id: "channel-1",
|
||||
channel_type: "wecom",
|
||||
name: "test",
|
||||
enabled: true,
|
||||
config_json: { mode: "mock", routing: {} },
|
||||
template_json: null,
|
||||
}),
|
||||
},
|
||||
},
|
||||
config: { imNotifierEnabled: true },
|
||||
eventType: "notification.im",
|
||||
payload: { channelId: "channel-1", channelType: "wecom", title: "title", body: "body" },
|
||||
});
|
||||
|
||||
it("dispatches notification.im", async () => {
|
||||
const result = await dispatcher.dispatchOutboxEvent({
|
||||
config: {},
|
||||
eventType: "notification.im",
|
||||
payload: { channelType: "slack" },
|
||||
});
|
||||
expect(result.channel).toBe("im");
|
||||
expect(result.response.channelType).toBe("slack");
|
||||
});
|
||||
expect(result.channel).toBe("im");
|
||||
expect(result.code).toBe("mock_sent");
|
||||
});
|
||||
|
||||
it("throws error for unsupported event", async () => {
|
||||
await expect(
|
||||
dispatcher.dispatchOutboxEvent({
|
||||
config: {},
|
||||
eventType: "unknown.event",
|
||||
})
|
||||
).rejects.toThrow("unsupported_outbox_event:unknown.event");
|
||||
});
|
||||
it("throws error for unsupported event", async () => {
|
||||
await expect(
|
||||
dispatcher.dispatchOutboxEvent({
|
||||
config: {},
|
||||
eventType: "unknown.event",
|
||||
}),
|
||||
).rejects.toThrow("unsupported_outbox_event:unknown.event");
|
||||
});
|
||||
});
|
||||
|
||||
在新工单中引用
屏蔽一个用户