Skip to content

Commit

Permalink
fix(core): wrong outbox scheduleEvents behaviour with 0 events
Browse files Browse the repository at this point in the history
  • Loading branch information
gtoselli committed Apr 23, 2024
1 parent 54b1541 commit b2b81e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-meals-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fizzbuds/ddd-toolkit": patch
---

fix(core): wrong outbox scheduleEvents behaviour with 0 events
7 changes: 7 additions & 0 deletions packages/ddd-toolkit/src/outbox/mongo-outbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,11 @@ describe('Mongo outbox', () => {
});
});
});

describe('When scheduleEvents with 0 events', () => {
it('should not throw', async () => {
const session = mongoClient.startSession();
await outbox.scheduleEvents([], session);
});
});
});
1 change: 1 addition & 0 deletions packages/ddd-toolkit/src/outbox/mongo-outbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class MongoOutbox implements IOutbox, IInit, ITerminate {
}

public async scheduleEvents(events: IEvent<unknown>[], clientSession: ClientSession): Promise<string[]> {
if (!events.length) return [];
const { insertedIds } = await this.outboxCollection.insertMany(
events.map((event) => ({
event,
Expand Down

0 comments on commit b2b81e8

Please sign in to comment.