prsm/packages/arc/tests/specs/utils/stripBooleanModifiers.test.ts
2024-08-28 09:08:33 -04:00

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" });
});
});