43 行
1.5 KiB
JavaScript
43 行
1.5 KiB
JavaScript
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("throws IntegrationDispatchError if erp fails", async () => {
|
|
await expect(
|
|
dispatcher.dispatchOutboxEvent({
|
|
config: { erpSyncEnabled: false },
|
|
eventType: "erp.reimbursement.paid",
|
|
payload: { reimbursementId: 1 },
|
|
})
|
|
).rejects.toThrow(dispatcher.IntegrationDispatchError);
|
|
});
|
|
|
|
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");
|
|
});
|
|
|
|
it("throws error for unsupported event", async () => {
|
|
await expect(
|
|
dispatcher.dispatchOutboxEvent({
|
|
config: {},
|
|
eventType: "unknown.event",
|
|
})
|
|
).rejects.toThrow("unsupported_outbox_event:unknown.event");
|
|
});
|
|
});
|