feat(doc/search): Enhance search functionality with filter and validate options for advanced query control

This commit is contained in:
2025-04-22 19:13:17 +00:00
parent 498f586ddb
commit 436311ab06
5 changed files with 72 additions and 11 deletions

View File

@ -276,6 +276,20 @@ tap.test('should support wildcard plain term with question mark pattern', async
expect(names).toEqual(['Galaxy S21', 'iPhone 12']);
});
// Filter and Validation tests
tap.test('should apply filter option to restrict results', async () => {
// search term 'book' across all fields but restrict to Books category
const bookFiltered = await Product.search('book', { filter: { category: 'Books' } });
expect(bookFiltered.length).toEqual(2);
bookFiltered.forEach((p) => expect(p.category).toEqual('Books'));
});
tap.test('should apply validate hook to post-filter results', async () => {
// return only products with price > 500
const expensive = await Product.search('', { validate: (p) => p.price > 500 });
expect(expensive.length).toBeGreaterThan(0);
expensive.forEach((p) => expect(p.price).toBeGreaterThan(500));
});
// Close database connection
tap.test('close database connection', async () => {
await testDb.mongoDb.dropDatabase();