1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: validate date filter and add more tests (#5525)

This commit is contained in:
Jaanus Sellin 2023-12-04 15:41:05 +02:00 committed by GitHub
parent a506b92544
commit d1984b2447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View File

@ -126,6 +126,19 @@ const filterFeaturesByState = async (state: string, expectedCode = 200) => {
.expect(expectedCode);
};
const filterFeaturesByOperators = async (
state: string,
tag: string,
createdAt: string,
expectedCode = 200,
) => {
return app.request
.get(
`/api/admin/search/features?createdAt=${createdAt}&state=${state}&tag=${tag}`,
)
.expect(expectedCode);
};
const filterFeaturesByCreated = async (
createdAt: string,
expectedCode = 200,
@ -830,3 +843,29 @@ test('should search features by created date with operators', async () => {
features: [{ name: 'my_feature_b' }],
});
});
test('should filter features by combined operators', async () => {
await app.createFeature({
name: 'my_feature_a',
createdAt: '2023-01-27T15:21:39.975Z',
stale: true,
});
await app.createFeature({
name: 'my_feature_b',
createdAt: '2023-01-29T15:21:39.975Z',
});
await app.addTag('my_feature_b', {
type: 'simple',
value: 'my_tag',
});
const { body } = await filterFeaturesByOperators(
'IS_NOT:active',
'DO_NOT_INCLUDE:simple:my_tag',
'IS_BEFORE:2023-01-28T15:21:39.975Z',
);
expect(body).toMatchObject({
features: [{ name: 'my_feature_a' }],
});
});

View File

@ -138,7 +138,8 @@ export const featureSearchQueryParameters = [
schema: {
type: 'string',
example: 'IS_ON_OR_AFTER:2023-01-28T15:21:39.975Z',
pattern: '^(IS_BEFORE|IS_ON_OR_AFTER):(.*?)(,([a-zA-Z0-9_]+))*$',
pattern:
'^(IS_BEFORE|IS_ON_OR_AFTER):\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$',
},
description:
'The date the feature was created. The date can be specified with an operator. The supported operators are IS_BEFORE, IS_ON_OR_AFTER.',