Skip to content

Commit

Permalink
✨ add an implementation to test the snapshot-handler loadMany method
Browse files Browse the repository at this point in the history
  • Loading branch information
drieshooghe committed Oct 12, 2022
1 parent a7f3f10 commit 91d1abc
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/e2e/src/application/repositories/account.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ export class AccountRepository {
return account;
}

async getAll(fromAccountId?: AccountId, limit?: number): Promise<Account[]> {
const accounts = [];
for await (const envelopes of this.accountSnapshotHandler.loadMany({
fromId: fromAccountId,
limit,
})) {
for (const { metadata, payload } of envelopes) {
const id = AccountId.from(metadata.aggregateId);
const eventStream = EventStream.for<Account>(Account, id);
const account = this.accountSnapshotHandler.deserialize(payload);

const eventCursor = this.eventStore.getEvents(eventStream, { fromVersion: metadata.version + 1 });
await account.loadFromHistory(eventCursor);

accounts.push(account);
}
}

return accounts;
}

async save(account: Account): Promise<void> {
const events = account.commit();
const stream = EventStream.for<Account>(Account, account.id);
Expand Down

0 comments on commit 91d1abc

Please sign in to comment.