mirror of
https://github.com/nvms/prsm.git
synced 2025-12-16 16:10:54 +00:00
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { testSuite, expect } from "manten";
|
|
import { stripBooleanModifiers } from "../../../src/collection";
|
|
|
|
export default testSuite(async ({ test }) => {
|
|
test("should strip boolean modifiers", () => {
|
|
const query = { name: "A", title: { $oneOf: ["Captain", "Commander"] } };
|
|
const stripped = stripBooleanModifiers(query);
|
|
expect(stripped).toEqual({ name: "A" });
|
|
});
|
|
|
|
test("should strip multiple boolean modifers", () => {
|
|
const query = {
|
|
name: "A",
|
|
title: {
|
|
$oneOf: ["Captain", "Commander"],
|
|
$not: { $has: "Lieutenant" },
|
|
},
|
|
age: { $gt: 30 },
|
|
};
|
|
const stripped = stripBooleanModifiers(query);
|
|
expect(stripped).toEqual({ name: "A" });
|
|
});
|
|
|
|
test("should strip boolean modifiers, preserving other keys", () => {
|
|
const query = {
|
|
name: "A",
|
|
title: {
|
|
$oneOf: ["Captain", "Commander"],
|
|
$not: { $has: "Lieutenant" },
|
|
thing: "C",
|
|
},
|
|
age: { $gt: 30 },
|
|
other: "B",
|
|
};
|
|
const stripped = stripBooleanModifiers(query);
|
|
expect(stripped).toEqual({ name: "A", title: { thing: "C" }, other: "B" });
|
|
});
|
|
});
|