-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from AlexcastroDev/feat/add-custom-filter
feat: search by custom filter
- Loading branch information
Showing
8 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import SearchEngine from '..' | ||
import { RuleOperator } from '../../interfaces' | ||
import collection from '../../__mocks__/movies.json' | ||
|
||
interface IMovie { | ||
id: number | ||
title: string | ||
year: number | ||
} | ||
|
||
describe('Should match strings', () => { | ||
it('[String]: Should cause exception', () => { | ||
const results = () => | ||
new SearchEngine(collection).search([ | ||
{ | ||
type: 'custom', | ||
operator: RuleOperator.AND, | ||
}, | ||
]) | ||
|
||
expect(results).toThrow('[flexysearch]: Custom filter not valid') | ||
}) | ||
it('[String]: Should cause exception', () => { | ||
const results = new SearchEngine(collection).search([ | ||
{ | ||
type: 'custom', | ||
operator: RuleOperator.AND, | ||
filter: (datum: IMovie) => { | ||
return datum.year === 2009 | ||
}, | ||
}, | ||
]) | ||
|
||
expect(results).toStrictEqual([ | ||
{ | ||
id: 1, | ||
title: 'Film 1', | ||
year: 2009, | ||
}, | ||
{ | ||
id: 7, | ||
title: 'Film 7', | ||
year: 2009, | ||
}, | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const omit = (object: Record<string, any>, keys: Array<string>): Record<string, any> => { | ||
if (!object) return {} | ||
try { | ||
const payload = Object.entries(object).filter(([key]) => !keys.includes(key)) | ||
const data: { [key: string]: any } = {} | ||
|
||
payload.forEach((item) => { | ||
const [key, value] = item | ||
data[key] = value | ||
}) | ||
return data | ||
} catch { | ||
return {} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters