1- import { EventStoreDBClient , StreamingRead } from "@eventstore/db-client" ;
1+ import { EventStoreDBClient , StreamingRead , StreamSubscription } from "@eventstore/db-client" ;
22import { EventStoreDBContainer } from "./eventstoredb-container" ;
33
44describe ( "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
4890async 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