More tests

This commit is contained in:
Adria Navarro 2024-10-11 12:29:34 +02:00
parent 37450823bb
commit f192a30da0
1 changed files with 118 additions and 68 deletions

View File

@ -2331,82 +2331,132 @@ describe.each([
}) })
describe("logical filters", () => { describe("logical filters", () => {
it("should allow nested ands with single conditions", async () => { describe("just $ands", () => {
await expectQuery({ it("should allow nested ands with single conditions", async () => {
$and: { await expectQuery({
conditions: [ $and: {
{ conditions: [
$and: { {
conditions: [ $and: {
{ conditions: [
equal: { ["productCat.name"]: "foo" }, {
}, 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 () => {
await expectQuery({
$and: {
conditions: [
{
$and: {
conditions: [
{
equal: { ["productCat.name"]: "foo" },
notEqual: { ["productCat.name"]: "foo" },
},
],
},
},
],
},
}).toContainExactly([])
})
it("should allow nested ands with multiple conditions", async () => {
await expectQuery({
$and: {
conditions: [
{
$and: {
conditions: [
{
equal: { ["productCat.name"]: "foo" },
},
],
},
notEqual: { ["productCat.name"]: "foo" },
},
],
},
}).toContainExactly([])
})
}) })
it("should allow nested ands with exclusive conditions", async () => { describe("just $ors", () => {
await expectQuery({ it("should allow nested ands with single conditions", async () => {
$and: { await expectQuery({
conditions: [ $or: {
{ conditions: [
$and: { {
conditions: [ $or: {
{ conditions: [
equal: { ["productCat.name"]: "foo" }, {
notEqual: { ["productCat.name"]: "foo" }, equal: { ["productCat.name"]: "foo" },
}, },
], ],
},
}, },
}, ],
], },
}, }).toContainExactly([
}).toContainExactly([]) { name: "foo", productCat: [{ _id: productCatRows[0]._id }] },
}) ])
})
it("should allow nested ands with multiple conditions", async () => { it("should allow nested ands with exclusive conditions", async () => {
await expectQuery({ await expectQuery({
$and: { $or: {
conditions: [ conditions: [
{ {
$and: { $or: {
conditions: [ conditions: [
{ {
equal: { ["productCat.name"]: "foo" }, 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: "baz", productCat: undefined },
])
})
it("should allow nesting or under and with single conditions", async () => { it("should allow nested ands with multiple conditions", async () => {
await expectQuery({ await expectQuery({
$and: { $or: {
conditions: [ conditions: [
{ {
$or: { $or: {
conditions: [ conditions: [
{ {
equal: { ["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: "baz", productCat: undefined },
])
})
}) })
}) })
}) })