Skip to content

Commit 802872d

Browse files
committed
test(eventstoredb): test standard projections
1 parent 2d9b6f3 commit 802872d

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

packages/modules/eventstoredb/src/eventstoredb-container.test.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventStoreDBClient, StreamingRead } from "@eventstore/db-client";
1+
import { EventStoreDBClient, StreamingRead, StreamSubscription } from "@eventstore/db-client";
22
import { EventStoreDBContainer } from "./eventstoredb-container";
33

44
describe("EventStoreDBContainer", () => {
@@ -43,6 +43,48 @@ describe("EventStoreDBContainer", () => {
4343
await container.stop();
4444
});
4545
// }
46+
47+
it("should use built-in projections", async () => {
48+
const container = await new EventStoreDBContainer().start();
49+
const client = EventStoreDBClient.connectionString(container.getConnectionString());
50+
51+
await client.appendToStream("Todo-1", [
52+
{
53+
contentType: "application/json",
54+
data: { title: "Do something" },
55+
metadata: {},
56+
id: "7eccc3a7-0664-4348-a621-029125741e22",
57+
type: "TodoCreated",
58+
},
59+
]);
60+
const stream = client.subscribeToStream("$ce-Todo", { resolveLinkTos: true });
61+
62+
expect(await getStreamFirstEvent(stream)).toEqual(
63+
expect.objectContaining({
64+
event: expect.objectContaining({
65+
data: { title: "Do something" },
66+
id: "7eccc3a7-0664-4348-a621-029125741e22",
67+
isJson: true,
68+
metadata: {},
69+
revision: 0n,
70+
streamId: "Todo-1",
71+
type: "TodoCreated",
72+
}),
73+
link: expect.objectContaining({
74+
isJson: false,
75+
metadata: expect.objectContaining({
76+
$causedBy: "7eccc3a7-0664-4348-a621-029125741e22",
77+
$o: "Todo-1",
78+
}),
79+
revision: 0n,
80+
streamId: "$ce-Todo",
81+
type: "$>",
82+
}),
83+
})
84+
);
85+
await stream.unsubscribe();
86+
await container.stop();
87+
});
4688
});
4789

4890
async function consumeSteamingRead(read: StreamingRead<unknown>): Promise<unknown[]> {
@@ -54,3 +96,9 @@ async function consumeSteamingRead(read: StreamingRead<unknown>): Promise<unknow
5496

5597
return events;
5698
}
99+
100+
async function getStreamFirstEvent(stream: StreamSubscription): Promise<unknown> {
101+
for await (const event of stream) {
102+
return event;
103+
}
104+
}

0 commit comments

Comments
 (0)