Skip to content

Commit 4ec62da

Browse files
committed
fix tests
1 parent 7b760ed commit 4ec62da

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

src/EventQueueProcessorBase.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,10 @@ class EventQueueProcessorBase {
12041204
}
12051205

12061206
statusMapContainsError(statusMap) {
1207-
return Object.values(statusMap).includes(EventProcessingStatus.Error);
1207+
this.#normalizeStatusMap(statusMap);
1208+
return Object.values(statusMap)
1209+
.map(({ status }) => status)
1210+
.includes(EventProcessingStatus.Error);
12081211
}
12091212

12101213
clearEventProcessingContext() {

test/__snapshots__/eventQueueOutbox.test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ exports[`event-queue outbox monkeyPatchCAPOutbox=true req reject should be caugh
298298
]
299299
`;
300300

301+
exports[`event-queue outbox monkeyPatchCAPOutbox=true req reject should be caught for send and rollback transaction 1`] = `
302+
[
303+
[
304+
"error processing outboxed service call",
305+
[Error: error occurred],
306+
{
307+
"serviceName": "NotificationService",
308+
},
309+
],
310+
]
311+
`;
312+
301313
exports[`event-queue outbox monkeyPatchCAPOutbox=true req reject should cause an error for emit 1`] = `
302314
[
303315
[

test/asset/outboxProject/srv/service/service.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ class NotificationService extends cds.Service {
1414
});
1515
});
1616

17-
this.on("rejectEvent", (req) => {
17+
this.on("rejectEvent", async (req) => {
18+
await INSERT.into("sap.eventqueue.Lock").entries({
19+
code: req.data.lockId,
20+
});
1821
req.reject(404, "error occurred");
1922
});
2023

test/eventQueueOutbox.test.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,22 +510,30 @@ describe("event-queue outbox", () => {
510510
expect(loggerMock.callsLengths().error).toEqual(0);
511511
});
512512

513-
it("req reject should be caught for send", async () => {
513+
it("req reject should be caught for send and rollback transaction", async () => {
514514
const service = await cds.connect.to("NotificationService");
515515
const outboxedService = cds.outboxed(service).tx(context);
516+
const lockId = cds.utils.uuid();
516517
await outboxedService.send("rejectEvent", {
517518
to: "to",
518519
subject: "subject",
519520
body: "body",
521+
lockId,
520522
});
521523
await commitAndOpenNew();
522524
await testHelper.selectEventQueueAndExpectOpen(tx, { expectedLength: 1 });
523525

526+
await commitAndOpenNew();
524527
await processEventQueue(tx.context, "CAP_OUTBOX", service.name);
525528
await commitAndOpenNew();
526-
const [event] = await testHelper.selectEventQueueAndReturn(tx, {
527-
expectedLength: 1,
528-
additionalColumns: ["error"],
529+
530+
const [event] = await cds.tx({}, async (tx) => {
531+
const lock = await tx.run(SELECT.one.from("sap.eventqueue.Lock").where({ code: lockId }));
532+
expect(lock).toBeUndefined();
533+
return await testHelper.selectEventQueueAndReturn(tx, {
534+
expectedLength: 1,
535+
additionalColumns: ["error"],
536+
});
529537
});
530538
expect(event.status).toEqual(EventProcessingStatus.Error);
531539
expect(JSON.parse(event.error)).toEqual(
@@ -542,16 +550,22 @@ describe("event-queue outbox", () => {
542550
it("req reject should cause an error for emit", async () => {
543551
const service = await cds.connect.to("NotificationService");
544552
const outboxedService = cds.outboxed(service).tx(context);
553+
const lockId = cds.utils.uuid();
545554
await outboxedService.emit("rejectEvent", {
546555
to: "to",
547556
subject: "subject",
548557
body: "body",
558+
lockId,
549559
});
550560
await commitAndOpenNew();
551561
await testHelper.selectEventQueueAndExpectOpen(tx, { expectedLength: 1 });
552562

553-
await processEventQueue(tx.context, "CAP_OUTBOX", service.name);
554563
await commitAndOpenNew();
564+
await processEventQueue(tx.context, "CAP_OUTBOX", service.name);
565+
await cds.tx({}, async (tx) => {
566+
const lock = await tx.run(SELECT.one.from("sap.eventqueue.Lock").where({ code: lockId }));
567+
expect(lock).toBeUndefined();
568+
});
555569
await testHelper.selectEventQueueAndExpectError(tx, { expectedLength: 1 });
556570
expect(loggerMock.callsLengths().error).toEqual(1);
557571
expect(loggerMock.calls().error).toMatchSnapshot();
@@ -566,7 +580,9 @@ describe("event-queue outbox", () => {
566580
body: "body",
567581
});
568582
await commitAndOpenNew();
569-
await testHelper.selectEventQueueAndExpectOpen(tx, { expectedLength: 1 });
583+
await cds.tx({}, async (tx) => {
584+
await testHelper.selectEventQueueAndExpectOpen(tx, { expectedLength: 1 });
585+
});
570586

571587
await processEventQueue(tx.context, "CAP_OUTBOX", service.name);
572588
await commitAndOpenNew();
@@ -582,10 +598,12 @@ describe("event-queue outbox", () => {
582598
to: "to",
583599
subject: "subject",
584600
body: "body",
601+
lockId: cds.utils.uuid(),
585602
});
586603
await commitAndOpenNew();
587604
await testHelper.selectEventQueueAndExpectOpen(tx, { expectedLength: 1 });
588605

606+
await commitAndOpenNew();
589607
await processEventQueue(tx.context, "CAP_OUTBOX", service.name);
590608
await commitAndOpenNew();
591609
await testHelper.selectEventQueueAndExpectError(tx, { expectedLength: 1 });

0 commit comments

Comments
 (0)