Convert presets preconditions to use expressions
This commit is contained in:
1 parent
152d8f5283
commit
edadfe54c8
7 files changed
+123
-174
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import ava from "ava";
|
||||
import * as mongodbFunctions from "../lib/mongodb-functions";
|
||||
import { stringify } from "../lib/common/expression-parser";
|
||||
|
||||
ava("mongoQueryToFilter", t => {
|
||||
const tests = [
|
||||
[{}, "true"],
|
||||
[{ test: "test" }, 'test = "test"'],
|
||||
[{ test: { $eq: "test" } }, 'test = "test"'],
|
||||
[{ test: { $ne: "test" } }, 'test <> "test"'],
|
||||
[{ test: { $gte: "test" } }, 'test >= "test"'],
|
||||
[{ "Tags.test": true }, "Tags.test IS NOT NULL"],
|
||||
[{ "Tags.test": false }, "Tags.test IS NULL"],
|
||||
[{ "Tags.test": { $exists: true } }, "Tags.test IS NOT NULL"],
|
||||
[{ "Tags.test": { $exists: false } }, "Tags.test IS NULL"],
|
||||
[{ "Tags.test": { $ne: true } }, "Tags.test IS NULL"],
|
||||
[{ "Tags.test": { $ne: false } }, "Tags.test IS NOT NULL"],
|
||||
[{ _tags: "test" }, "Tags.test IS NOT NULL"],
|
||||
[{ _tags: { $ne: "test" } }, "Tags.test IS NULL"],
|
||||
[
|
||||
{ $and: [{ test: "test" }, { test: { $ne: "test" } }] },
|
||||
'test = "test" AND test <> "test"'
|
||||
],
|
||||
[{ test: "test", test2: "test2" }, 'test = "test" AND test2 = "test2"'],
|
||||
[
|
||||
{ $or: [{ test: "test" }, { test: { $ne: "test" } }] },
|
||||
'test = "test" OR test <> "test"'
|
||||
],
|
||||
[
|
||||
{ test: { $gte: "test1", $ne: "test2" } },
|
||||
'test >= "test1" AND test <> "test2"'
|
||||
]
|
||||
];
|
||||
|
||||
const shouldFailTests = [
|
||||
[{ test: { $gee: "test" } }, "Operator $gee not supported"],
|
||||
[{ test: [] }, "Invalid type"],
|
||||
[{ "Tags.test": { $eq: true } }, "Invalid tag query"],
|
||||
[{ _tags: [] }, "Invalid type"],
|
||||
[{ _tags: { $eq: "test" } }, "Invalid tag query"],
|
||||
[{ $nor: [] }, "Operator $nor not supported"]
|
||||
];
|
||||
|
||||
t.plan(tests.length + 2 * shouldFailTests.length);
|
||||
for (const test of tests)
|
||||
t.is(stringify(mongodbFunctions.mongoQueryToFilter(test[0])), test[1]);
|
||||
|
||||
for (const test of shouldFailTests) {
|
||||
const func = (): void => {
|
||||
mongodbFunctions.mongoQueryToFilter(test[0]);
|
||||
};
|
||||
const error = t.throws(func, Error);
|
||||
t.is(error.message, test[1]);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user