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