More tests

This commit is contained in:
Adria Navarro 2024-10-11 13:06:37 +02:00
parent bfdead820c
commit f73b7d4824
1 changed files with 135 additions and 114 deletions

View File

@ -23,6 +23,7 @@ import {
EmptyFilterOption, EmptyFilterOption,
FieldType, FieldType,
JsonFieldSubType, JsonFieldSubType,
LogicalOperator,
RelationshipType, RelationshipType,
Row, Row,
RowSearchParams, RowSearchParams,
@ -2331,7 +2332,9 @@ describe.each([
}) })
describe("logical filters", () => { describe("logical filters", () => {
describe("just $ands", () => { const logicalOperators = [LogicalOperator.AND, LogicalOperator.OR]
describe("$and", () => {
it("should allow single conditions", async () => { it("should allow single conditions", async () => {
await expectQuery({ await expectQuery({
$and: { $and: {
@ -2359,66 +2362,75 @@ describe.each([
}).toContainExactly([]) }).toContainExactly([])
}) })
it("should allow nested ands with single conditions", async () => { it.each([logicalOperators])(
await expectQuery({ "should allow nested ands with single conditions (with %s as root)",
$and: { async rootOperator => {
conditions: [ await expectQuery({
{ [rootOperator]: {
$and: { conditions: [
conditions: [ {
{ $and: {
equal: { ["productCat.name"]: "foo" }, conditions: [
}, {
], equal: { ["productCat.name"]: "foo" },
},
],
},
}, },
}, ],
], },
}, }).toContainExactly([
}).toContainExactly([ { name: "foo", productCat: [{ _id: productCatRows[0]._id }] },
{ name: "foo", productCat: [{ _id: productCatRows[0]._id }] }, ])
]) }
}) )
it("should allow nested ands with exclusive conditions", async () => { it.each([logicalOperators])(
await expectQuery({ "should allow nested ands with exclusive conditions (with %s as root)",
$and: { async rootOperator => {
conditions: [ await expectQuery({
{ [rootOperator]: {
$and: { conditions: [
conditions: [ {
{ $and: {
equal: { ["productCat.name"]: "foo" }, conditions: [
notEqual: { ["productCat.name"]: "foo" }, {
}, equal: { ["productCat.name"]: "foo" },
], notEqual: { ["productCat.name"]: "foo" },
},
],
},
}, },
}, ],
], },
}, }).toContainExactly([])
}).toContainExactly([]) }
}) )
it("should allow nested ands with multiple conditions", async () => { it.each([logicalOperators])(
await expectQuery({ "should allow nested ands with multiple conditions (with %s as root)",
$and: { async rootOperator => {
conditions: [ await expectQuery({
{ [rootOperator]: {
$and: { conditions: [
conditions: [ {
{ $and: {
equal: { ["productCat.name"]: "foo" }, conditions: [
}, {
], equal: { ["productCat.name"]: "foo" },
},
],
},
notEqual: { ["productCat.name"]: "foo" },
}, },
notEqual: { ["productCat.name"]: "foo" }, ],
}, },
], }).toContainExactly([])
}, }
}).toContainExactly([]) )
})
}) })
describe("just $ors", () => { describe("$ors", () => {
it("should allow single conditions", async () => { it("should allow single conditions", async () => {
await expectQuery({ await expectQuery({
$or: { $or: {
@ -2450,71 +2462,80 @@ describe.each([
]) ])
}) })
it("should allow nested ors with single conditions", async () => { it.each([logicalOperators])(
await expectQuery({ "should allow nested ors with single conditions (with %s as root)",
$or: { async rootOperator => {
conditions: [ await expectQuery({
{ [rootOperator]: {
$or: { conditions: [
conditions: [ {
{ $or: {
equal: { ["productCat.name"]: "foo" }, conditions: [
}, {
], equal: { ["productCat.name"]: "foo" },
},
],
},
}, },
}, ],
], },
}, }).toContainExactly([
}).toContainExactly([ { name: "foo", productCat: [{ _id: productCatRows[0]._id }] },
{ name: "foo", productCat: [{ _id: productCatRows[0]._id }] }, ])
]) }
}) )
it("should allow nested ors with exclusive conditions", async () => { it.each([logicalOperators])(
await expectQuery({ "should allow nested ors with exclusive conditions (with %s as root)",
$or: { async rootOperator => {
conditions: [ await expectQuery({
{ [rootOperator]: {
$or: { conditions: [
conditions: [ {
{ $or: {
equal: { ["productCat.name"]: "foo" }, conditions: [
notEqual: { ["productCat.name"]: "foo" }, {
}, equal: { ["productCat.name"]: "foo" },
], notEqual: { ["productCat.name"]: "foo" },
},
],
},
}, },
}, ],
], },
}, }).toContainExactly([
}).toContainExactly([ { name: "foo", productCat: [{ _id: productCatRows[0]._id }] },
{ name: "foo", productCat: [{ _id: productCatRows[0]._id }] }, { name: "bar", productCat: [{ _id: productCatRows[1]._id }] },
{ name: "bar", productCat: [{ _id: productCatRows[1]._id }] }, // { name: "baz", productCat: undefined }, // TODO
// { name: "baz", productCat: undefined }, // TODO ])
]) }
}) )
it("should allow nested ors with multiple conditions", async () => { it.each([logicalOperators])(
await expectQuery({ "should allow nested ors with multiple conditions (with %s as root)",
$or: { async rootOperator => {
conditions: [ await expectQuery({
{ [rootOperator]: {
$or: { conditions: [
conditions: [ {
{ $or: {
equal: { ["productCat.name"]: "foo" }, conditions: [
}, {
], equal: { ["productCat.name"]: "foo" },
},
],
},
notEqual: { ["productCat.name"]: "foo" },
}, },
notEqual: { ["productCat.name"]: "foo" }, ],
}, },
], }).toContainExactly([
}, { name: "foo", productCat: [{ _id: productCatRows[0]._id }] },
}).toContainExactly([ { name: "bar", productCat: [{ _id: productCatRows[1]._id }] },
{ name: "foo", productCat: [{ _id: productCatRows[0]._id }] }, // { name: "baz", productCat: undefined }, // TODO
{ name: "bar", productCat: [{ _id: productCatRows[1]._id }] }, ])
// { name: "baz", productCat: undefined }, // TODO }
]) )
})
}) })
}) })
}) })