mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-04 11:17:02 +02:00
Improves handling of constraints in use that have been deleted. This change implments a few small changes on both the front and the back end on how we deal with constraints that have been deleted. The most important change is on the back end, in the `/constraints/validate` endpoint. We used to throw here if the constraint couldn't be found, but the only reason we wanted to look for the constraint in the db was to check for legal values. Now, instead, we'll allow you to pass a constraint field that doesn't exist in the database. We'll still check the values against the operator for validity, we just don't control legal values anymore (because there aren't any). On the front end, we improve the handling by showing the deleted context filed in the dropdown, both when the selector dropdown is closed and when it is open. However, if you change the context field, we remove the deleted field from the list. This seems like a sensible tradeoff. Means you can't select it if you've deselected it.
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import dbInit, { type ITestDb } from '../../helpers/database-init.js';
|
|
import getLogger from '../../../fixtures/no-logger.js';
|
|
import {
|
|
type IUnleashTest,
|
|
setupAppWithCustomConfig,
|
|
} from '../../helpers/test-helper.js';
|
|
|
|
let app: IUnleashTest;
|
|
let db: ITestDb;
|
|
|
|
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);
|
|
});
|