Skip to content

Commit

Permalink
test: adding test cases for search queries wrapped in quotes and cont…
Browse files Browse the repository at this point in the history
…ain special characters
  • Loading branch information
Tony-MK authored Dec 3, 2024
1 parent 444870b commit cb1fd22
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions tests/unit/SearchParserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit cb1fd22

Please sign in to comment.