-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-10: test filter styles have equivalent output
- Loading branch information
1 parent
faf98ca
commit 92d8265
Showing
5 changed files
with
127 additions
and
28 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,82 @@ | ||
const { parseMongoFilter } = require('../../lib/mongo-filter/parse-mongo-filter') | ||
const { parseIbmFilter } = require('../../lib/ibm-filter/parse-ibm-filter') | ||
|
||
function testEachCase(testCases) { | ||
test.concurrent.each(testCases)('$title', ({ mongoQueryString, ibmQueryString}) => { | ||
const { results: mongoResults } = parseMongoFilter(mongoQueryString) | ||
const { results: ibmResults } = parseIbmFilter(ibmQueryString) | ||
try { | ||
expect(mongoResults).toEqual(ibmResults) | ||
} catch (e) { | ||
console.log('mongoResults: ', mongoResults) | ||
console.log('ibmResults: ', ibmResults) | ||
throw e | ||
} | ||
}) | ||
} | ||
|
||
describe('MongoDB-style filtering vs IBM-style filtering Equivalence Tests', () => { | ||
describe('value types', () => { | ||
testEachCase([ | ||
{ | ||
title: 'both styles should output string values the same way', | ||
mongoQueryString: "filter[name][$eq]=michael", | ||
ibmQueryString: "filter=equals(name,'michael')" | ||
}, | ||
{ | ||
title: 'both styles should output number values the same way', | ||
mongoQueryString: "filter[age][$eq]=25", | ||
ibmQueryString: "filter=equals(age,'25')" | ||
}, | ||
{ | ||
title: 'both styles should output date values the same way', | ||
mongoQueryString: "filter[born][$eq]=2020-01-01", | ||
ibmQueryString: "filter=equals(born,'2020-01-01')" | ||
}, | ||
{ | ||
title: 'both styles should output null values the same way', | ||
mongoQueryString: "filter[born][$eq]=null", | ||
ibmQueryString: "filter=equals(born,null)" | ||
}, | ||
]) | ||
}) | ||
describe('operators', () => { | ||
testEachCase([ | ||
{ | ||
title: 'both styles should output the "=" sql operator the same way', | ||
mongoQueryString: "filter[name][$eq]=michael", | ||
ibmQueryString: "filter=equals(name,'michael')" | ||
}, | ||
{ | ||
title: 'both styles should output the ">" sql operator the same way', | ||
mongoQueryString: "filter[name][$gt]=michael", | ||
ibmQueryString: "filter=greaterThan(name,'michael')" | ||
}, | ||
{ | ||
title: 'both styles should output the ">=" sql operator the same way', | ||
mongoQueryString: "filter[name][$gte]=michael", | ||
ibmQueryString: "filter=greaterOrEqual(name,'michael')" | ||
}, | ||
{ | ||
title: 'both styles should output the "<" sql operator the same way', | ||
mongoQueryString: "filter[name][$lt]=michael", | ||
ibmQueryString: "filter=lessThan(name,'michael')" | ||
}, | ||
{ | ||
title: 'both styles should output the "<=" sql operator the same way', | ||
mongoQueryString: "filter[name][$lte]=michael", | ||
ibmQueryString: "filter=lessOrEqual(name,'michael')" | ||
}, | ||
{ | ||
title: 'both styles should output the "LIKE" sql operator the same way', | ||
mongoQueryString: "filter[name][ilike]=ch", | ||
ibmQueryString: "filter=contains(name,'ch')" | ||
}, | ||
{ | ||
title: 'both styles should output the "IN" sql operator the same way', | ||
mongoQueryString: "filter[name][$in]=michael,brad", | ||
ibmQueryString: "filter=any(name,'michael','brad')" | ||
}, | ||
]) | ||
}) | ||
}) |
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