openpanel/packages/supabase/test/utils/mapOperator.spec.ts
Stefan Pejcic 8595a9f4e5 back
2024-05-08 19:58:53 +02:00

55 lines
1.7 KiB
TypeScript

import { mapOperator } from "../../src/utils";
import { CrudOperators } from "@refinedev/core";
describe("mapOperator", () => {
it("should correctly map CrudOperators to their corresponding string values", () => {
const testCases: Record<CrudOperators, string> = {
eq: "eq",
ne: "neq",
lt: "lt",
gt: "gt",
lte: "lte",
gte: "gte",
in: "in",
nin: "not.in",
contains: "ilike",
ncontains: "not.ilike",
containss: "like",
ncontainss: "not.like",
null: "is",
nnull: "not.is",
or: "or",
and: "and",
between: "",
nbetween: "",
startswith: "startswith",
nstartswith: "nstartswith",
endswith: "endswith",
nendswith: "nendswith",
startswiths: "startswiths",
nstartswiths: "nstartswiths",
endswiths: "endswiths",
nendswiths: "nendswiths",
};
for (const operator in testCases) {
if (operator === "between" || operator === "nbetween") {
expect(() =>
mapOperator(operator as CrudOperators),
).toThrowError(`Operator ${operator} is not supported`);
} else {
expect(mapOperator(operator as CrudOperators)).toBe(
testCases[operator as CrudOperators],
);
}
}
});
it.each(["unsupported", null, undefined])(
"should unsupported operator returns self",
(operator) => {
expect(mapOperator(operator as CrudOperators)).toBe(operator);
},
);
});