-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrunEventQlQuery.test.ts
More file actions
71 lines (57 loc) · 1.98 KB
/
runEventQlQuery.test.ts
File metadata and controls
71 lines (57 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import assert from 'node:assert/strict';
import { afterEach, beforeEach, suite, test } from 'node:test';
import { Container } from './Container.js';
import type { EventCandidate } from './EventCandidate.js';
import { getImageVersionFromDockerfile } from './getImageVersionFromDockerfile.js';
suite('runEventQlQuery', { timeout: 30_000 }, () => {
let container: Container;
beforeEach(async () => {
const imageVersion = getImageVersionFromDockerfile();
container = new Container().withImageTag(imageVersion);
await container.start();
});
afterEach(async () => {
await container.stop();
});
test('reads no rows if the query does not return any rows.', async (): Promise<void> => {
const client = container.getClient();
let didReadRows = false;
for await (const _row of client.runEventQlQuery('FROM e IN events PROJECT INTO e')) {
didReadRows = true;
}
assert.equal(didReadRows, false);
});
test('reads all rows the query returns.', async (): Promise<void> => {
const client = container.getClient();
const firstEvent: EventCandidate = {
source: 'https://www.eventsourcingdb.io',
subject: '/test',
type: 'io.eventsourcingdb.test',
data: {
value: 23,
},
};
const secondEvent: EventCandidate = {
source: 'https://www.eventsourcingdb.io',
subject: '/test',
type: 'io.eventsourcingdb.test',
data: {
value: 42,
},
};
await client.writeEvents([firstEvent, secondEvent]);
const rowsRead: unknown[] = [];
for await (const row of client.runEventQlQuery('FROM e IN events PROJECT INTO e')) {
rowsRead.push(row);
}
assert.equal(rowsRead.length, 2);
// biome-ignore lint/suspicious/noExplicitAny: Here, the cast is okay.
const firstRow = rowsRead[0] as any;
assert.equal(firstRow.id, '0');
assert.equal(firstRow.data.value, 23);
// biome-ignore lint/suspicious/noExplicitAny: Here, the cast is okay.
const secondRow = rowsRead[1] as any;
assert.equal(secondRow.id, '1');
assert.equal(secondRow.data.value, 42);
});
});