unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
57 lines • 1.82 kB
JavaScript
import dbInit from '../../helpers/database-init.js';
import getLogger from '../../../fixtures/no-logger.js';
import { setupAppWithCustomConfig, } from '../../helpers/test-helper.js';
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);
});
test('should allow unknown constraints if their values are valid', async () => {
await app.request
.post(PATH)
.send({
contextName: 'not-a-default-context-value',
operator: 'NUM_EQ',
value: 1,
})
.expect(204);
});
test('should block unknown constraints if their values are invalid', async () => {
await app.request
.post(PATH)
.send({
contextName: 'not-a-default-context-value',
operator: 'IN',
value: 1,
})
.expect(400);
});
//# sourceMappingURL=constraints.e2e.test.js.map