-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreadSubjects.test.ts
More file actions
99 lines (81 loc) · 2.55 KB
/
readSubjects.test.ts
File metadata and controls
99 lines (81 loc) · 2.55 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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('readSubjects', { 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 subjects if the database is empty.', async (): Promise<void> => {
const client = container.getClient();
let didReadSubjects = false;
for await (const _event of client.readSubjects('/')) {
didReadSubjects = true;
}
assert.equal(didReadSubjects, false);
});
test('reads all subjects.', async (): Promise<void> => {
const client = container.getClient();
const firstEvent: EventCandidate = {
source: 'https://www.eventsourcingdb.io',
subject: '/test/1',
type: 'io.eventsourcingdb.test',
data: {
value: 23,
},
};
const secondEvent: EventCandidate = {
source: 'https://www.eventsourcingdb.io',
subject: '/test/2',
type: 'io.eventsourcingdb.test',
data: {
value: 42,
},
};
await client.writeEvents([firstEvent, secondEvent]);
const subjectsRead: string[] = [];
for await (const subject of client.readSubjects('/')) {
subjectsRead.push(subject);
}
assert.equal(subjectsRead.length, 4);
assert.equal(subjectsRead[0], '/');
assert.equal(subjectsRead[1], '/test');
assert.equal(subjectsRead[2], '/test/1');
assert.equal(subjectsRead[3], '/test/2');
});
test('reads all subjects from the base subject.', async (): Promise<void> => {
const client = container.getClient();
const firstEvent: EventCandidate = {
source: 'https://www.eventsourcingdb.io',
subject: '/test/1',
type: 'io.eventsourcingdb.test',
data: {
value: 23,
},
};
const secondEvent: EventCandidate = {
source: 'https://www.eventsourcingdb.io',
subject: '/test/2',
type: 'io.eventsourcingdb.test',
data: {
value: 42,
},
};
await client.writeEvents([firstEvent, secondEvent]);
const subjectsRead: string[] = [];
for await (const subject of client.readSubjects('/test')) {
subjectsRead.push(subject);
}
assert.equal(subjectsRead.length, 3);
assert.equal(subjectsRead[0], '/test');
assert.equal(subjectsRead[1], '/test/1');
assert.equal(subjectsRead[2], '/test/2');
});
});