mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
fork refine
This commit is contained in:
54
packages/supabase/test/utils/mapOperator.spec.ts
Normal file
54
packages/supabase/test/utils/mapOperator.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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);
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user