-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adding test cases for search queries wrapped in quotes and cont…
…ain special characters
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,9 +382,109 @@ const tests = [ | |
}, | ||
]; | ||
|
||
/* | ||
* Test keywords with special characters and wrapped in quotes | ||
*/ | ||
|
||
const keywordTests = [ | ||
{ | ||
query: '" " " "', // Multiple whitespaces wrapped in quotes | ||
expected: { | ||
type: 'expense', | ||
status: 'all', | ||
sortBy: 'date', | ||
sortOrder: 'desc', | ||
filters: { | ||
operator: 'eq', | ||
left: 'keyword', | ||
right: [' ', ' '], | ||
}, | ||
}, | ||
}, | ||
{ | ||
query: '"https://expensify.com" "https://new.expensify.com"', | ||
expected: { | ||
type: 'expense', | ||
status: 'all', | ||
sortBy: 'date', | ||
sortOrder: 'desc', | ||
filters: { | ||
operator: 'eq', | ||
left: 'keyword', | ||
right: ['https://expensify.com', 'https://new.expensify.com'], | ||
}, | ||
}, | ||
}, | ||
{ | ||
query: '""https://expensify.com"" to ""https://new.expensify.com""', // Nested quotes with a colon | ||
expected: { | ||
type: 'expense', | ||
status: 'all', | ||
sortBy: 'date', | ||
sortOrder: 'desc', | ||
filters: { | ||
operator: 'eq', | ||
left: 'keyword', | ||
right: ['"https://expensify.com"', 'to', '"https://new.expensify.com"'], | ||
}, | ||
}, | ||
}, | ||
{ | ||
query: '"""https://expensify.com" to "https://new.expensify.com"""', // Mismatched quotes | ||
expected: { | ||
type: 'expense', | ||
status: 'all', | ||
sortBy: 'date', | ||
sortOrder: 'desc', | ||
filters: { | ||
operator: 'eq', | ||
left: 'keyword', | ||
right: ['""https://expensify.com', 'to', 'https://new.expensify.com""'], | ||
}, | ||
}, | ||
}, | ||
{ | ||
query: 'date>2024-01-01 from:[email protected] "https://expensify.com" "https://new.expensify.com"', | ||
expected: { | ||
type: 'expense', | ||
status: 'all', | ||
sortBy: 'date', | ||
sortOrder: 'desc', | ||
filters: { | ||
operator: 'and', | ||
left: { | ||
operator: 'and', | ||
left: { | ||
operator: 'gt', | ||
left: 'date', | ||
right: '2024-01-01', | ||
}, | ||
right: { | ||
operator: 'eq', | ||
left: 'from', | ||
right: '[email protected]', | ||
}, | ||
}, | ||
right: { | ||
operator: 'eq', | ||
left: 'keyword', | ||
right: ['https://expensify.com', 'https://new.expensify.com'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
describe('search parser', () => { | ||
test.each(tests)(`parsing: $query`, ({query, expected}) => { | ||
const result = searchParser.parse(query) as SearchQueryJSON; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('Testing search parser with special characters and wrapped in quotes.', () => { | ||
test.each(keywordTests)(`parsing: $query`, ({query, expected}) => { | ||
const result = searchParser.parse(query) as SearchQueryJSON; | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |