-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathregisterEventSchema.test.ts
More file actions
69 lines (59 loc) · 1.64 KB
/
registerEventSchema.test.ts
File metadata and controls
69 lines (59 loc) · 1.64 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
import assert from 'node:assert/strict';
import { afterEach, beforeEach, suite, test } from 'node:test';
import { Container } from './Container.js';
import { getImageVersionFromDockerfile } from './getImageVersionFromDockerfile.js';
suite('registerEventSchema', { 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('registers an event schema.', async (): Promise<void> => {
const client = container.getClient();
const eventType = 'io.eventsourcingdb.test';
const schema = {
type: 'object',
properties: {
value: {
type: 'number',
},
},
required: ['value'],
additionalProperties: false,
};
// Should not throw.
await client.registerEventSchema(eventType, schema);
});
test('throws an error if an event schema is already registered.', async (): Promise<void> => {
const client = container.getClient();
const eventType = 'io.eventsourcingdb.test';
const schema = {
type: 'object',
properties: {
value: {
type: 'number',
},
},
required: ['value'],
additionalProperties: false,
};
await client.registerEventSchema(eventType, schema);
await assert.rejects(
async () => {
await client.registerEventSchema(eventType, schema);
},
error => {
assert.ok(error instanceof Error);
assert.equal(
error.message,
`Failed to register event schema, got HTTP status code '409', expected '200'.`,
);
return true;
},
);
});
});