feat(doc/search): Enhance search functionality with filter and validate options for advanced query control
This commit is contained in:
@ -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();
|
||||
|
Reference in New Issue
Block a user