From d1984b24479ac55792f2b884fa3d749b94a57518 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Mon, 4 Dec 2023 15:41:05 +0200 Subject: [PATCH] feat: validate date filter and add more tests (#5525) --- .../feature-search/feature.search.e2e.test.ts | 39 +++++++++++++++++++ .../spec/feature-search-query-parameters.ts | 3 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/lib/features/feature-search/feature.search.e2e.test.ts b/src/lib/features/feature-search/feature.search.e2e.test.ts index e2820ab93bd6..2394117c8b2a 100644 --- a/src/lib/features/feature-search/feature.search.e2e.test.ts +++ b/src/lib/features/feature-search/feature.search.e2e.test.ts @@ -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' }], + }); +}); diff --git a/src/lib/openapi/spec/feature-search-query-parameters.ts b/src/lib/openapi/spec/feature-search-query-parameters.ts index 442c487894f0..684fd9aa9909 100644 --- a/src/lib/openapi/spec/feature-search-query-parameters.ts +++ b/src/lib/openapi/spec/feature-search-query-parameters.ts @@ -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.',