Skip to content

Commit

Permalink
feat: validate date filter and add more tests (#5525)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus authored Dec 4, 2023
1 parent a506b92 commit d1984b2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/lib/features/feature-search/feature.search.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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' }],
});
});
3 changes: 2 additions & 1 deletion src/lib/openapi/spec/feature-search-query-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit d1984b2

Please sign in to comment.