mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	feat: validate date filter and add more tests (#5525)
This commit is contained in:
		
							parent
							
								
									a506b92544
								
							
						
					
					
						commit
						d1984b2447
					
				@ -126,6 +126,19 @@ const filterFeaturesByState = async (state: string, expectedCode = 200) => {
 | 
				
			|||||||
        .expect(expectedCode);
 | 
					        .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 (
 | 
					const filterFeaturesByCreated = async (
 | 
				
			||||||
    createdAt: string,
 | 
					    createdAt: string,
 | 
				
			||||||
    expectedCode = 200,
 | 
					    expectedCode = 200,
 | 
				
			||||||
@ -830,3 +843,29 @@ test('should search features by created date with operators', async () => {
 | 
				
			|||||||
        features: [{ name: 'my_feature_b' }],
 | 
					        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' }],
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
@ -138,7 +138,8 @@ export const featureSearchQueryParameters = [
 | 
				
			|||||||
        schema: {
 | 
					        schema: {
 | 
				
			||||||
            type: 'string',
 | 
					            type: 'string',
 | 
				
			||||||
            example: 'IS_ON_OR_AFTER:2023-01-28T15:21:39.975Z',
 | 
					            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:
 | 
					        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.',
 | 
					            'The date the feature was created. The date can be specified with an operator. The supported operators are IS_BEFORE, IS_ON_OR_AFTER.',
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user