/
constraints.e2e.test.ts
42 lines (36 loc) · 1.21 KB
/
constraints.e2e.test.ts
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
import dbInit from '../../helpers/database-init';
import getLogger from '../../../fixtures/no-logger';
import { setupAppWithCustomConfig } from '../../helpers/test-helper';
let app;
let db;
const PATH = '/api/admin/constraints/validate';
beforeAll(async () => {
db = await dbInit('constraints', getLogger);
app = await setupAppWithCustomConfig(db.stores, {
experimental: {
flags: {
strictSchemaValidation: true,
},
},
});
});
afterAll(async () => {
await app.destroy();
await db.destroy();
});
test('should reject invalid constraints', async () => {
await app.request.post(PATH).send({}).expect(400);
await app.request.post(PATH).send({ a: 1 }).expect(400);
await app.request.post(PATH).send({ operator: 'IN' }).expect(400);
await app.request.post(PATH).send({ contextName: 'a' }).expect(400);
});
test('should accept valid constraints', async () => {
await app.request
.post(PATH)
.send({ contextName: 'environment', operator: 'NUM_EQ', value: 1 })
.expect(204);
await app.request
.post(PATH)
.send({ contextName: 'environment', operator: 'IN', values: ['a'] })
.expect(204);
});