|
3 | 3 | const { promisify } = require("util"); |
4 | 4 | const otel = require("@opentelemetry/api"); |
5 | 5 | jest.mock("@opentelemetry/api", () => require("./mocks/openTelemetry")); |
| 6 | +jest.mock("@cap-js-community/common", () => { |
| 7 | + return { |
| 8 | + RedisClient: { create: () => ({}) }, |
| 9 | + }; |
| 10 | +}); |
6 | 11 | const { Logger: mockLogger } = require("./mocks/logger"); |
7 | 12 | const loggerMock = mockLogger(); |
8 | 13 |
|
@@ -2536,20 +2541,6 @@ describe("event-queue outbox", () => { |
2536 | 2541 | expect(loggerMock.callsLengths().error).toEqual(0); |
2537 | 2542 | config.insertEventsBeforeCommit = true; |
2538 | 2543 | }); |
2539 | | - |
2540 | | - // it.skip("how to deal with specific event configuration srv.actionName", async () => { |
2541 | | - // const service = await cds.connect.to("Saga"); |
2542 | | - // await service.send("saga"); |
2543 | | - // await commitAndOpenNew(); |
2544 | | - // await processEventQueue(tx.context, "CAP_OUTBOX", service.name); |
2545 | | - // const [done, next] = await testHelper.selectEventQueueAndReturn(tx, { |
2546 | | - // expectedLength: 2, |
2547 | | - // additionalColumns: ["payload", "status"], |
2548 | | - // }); |
2549 | | - // expect(JSON.parse(done.payload)).toMatchObject({}); |
2550 | | - // expect(JSON.parse(done.payload)).toMatchObject({}); |
2551 | | - // expect(loggerMock.callsLengths().error).toEqual(0); |
2552 | | - // }); |
2553 | 2544 | }); |
2554 | 2545 |
|
2555 | 2546 | describe("provide next data", () => { |
@@ -2635,6 +2626,42 @@ describe("event-queue outbox", () => { |
2635 | 2626 | expect(loggerMock.callsLengths().error).toEqual(0); |
2636 | 2627 | }); |
2637 | 2628 | }); |
| 2629 | + |
| 2630 | + describe("general handlers", () => { |
| 2631 | + it("if succeeded handler exists and event is green, trigger next event", async () => { |
| 2632 | + const service = await cds.connect.to("Saga"); |
| 2633 | + await service.send("general", {}); |
| 2634 | + await commitAndOpenNew(); |
| 2635 | + await processEventQueue(tx.context, "CAP_OUTBOX", service.name); |
| 2636 | + const [done, next] = await testHelper.selectEventQueueAndReturn(tx, { |
| 2637 | + expectedLength: 2, |
| 2638 | + additionalColumns: ["payload"], |
| 2639 | + }); |
| 2640 | + expect(JSON.parse(done.payload)).toMatchObject({ event: "general" }); |
| 2641 | + expect(done.status).toEqual(EventProcessingStatus.Done); |
| 2642 | + |
| 2643 | + expect(JSON.parse(next.payload)).toMatchObject({ event: "#succeeded" }); |
| 2644 | + expect(next.status).toEqual(EventProcessingStatus.Done); |
| 2645 | + expect(loggerMock.callsLengths().error).toEqual(0); |
| 2646 | + }); |
| 2647 | + |
| 2648 | + it("if failed handler exists and event is red, trigger next event", async () => { |
| 2649 | + const service = await cds.connect.to("Saga"); |
| 2650 | + await service.send("general", { status: EventProcessingStatus.Error }); |
| 2651 | + await commitAndOpenNew(); |
| 2652 | + await processEventQueue(tx.context, "CAP_OUTBOX", service.name); |
| 2653 | + const [done, next] = await testHelper.selectEventQueueAndReturn(tx, { |
| 2654 | + expectedLength: 2, |
| 2655 | + additionalColumns: ["payload", "lastAttemptTimestamp"], |
| 2656 | + }); |
| 2657 | + expect(JSON.parse(done.payload)).toMatchObject({ event: "general" }); |
| 2658 | + expect(done.status).toEqual(EventProcessingStatus.Error); |
| 2659 | + |
| 2660 | + expect(JSON.parse(next.payload)).toMatchObject({ event: "#failed" }); |
| 2661 | + expect(next.status).toEqual(EventProcessingStatus.Done); |
| 2662 | + expect(loggerMock.callsLengths().error).toEqual(0); |
| 2663 | + }); |
| 2664 | + }); |
2638 | 2665 | }); |
2639 | 2666 | }); |
2640 | 2667 |
|
|
0 commit comments