openpanel/packages/appwrite/test/utils/replaceIdWithAppwriteId.spec.ts
Stefan Pejcic 09f9f9502d packages
2024-11-07 19:03:37 +01:00

56 lines
1.3 KiB
TypeScript

import type { CrudFilter } from "@refinedev/core";
import { replaceIdWithAppwriteId } from "../../src/utils/replaceIdWithAppwriteId";
describe("replaceIdWithAppwriteId", () => {
it("should replace the id with appwrite id", () => {
const result = replaceIdWithAppwriteId({
field: "id",
operator: "eq",
value: "John Doe",
} satisfies CrudFilter);
expect(result).toStrictEqual({
field: "$id",
operator: "eq",
value: "John Doe",
});
});
it("should only replace the first layer of id with appwrite id", () => {
const result = replaceIdWithAppwriteId({
field: "id",
operator: "eq",
value: [
{
field: "id",
operator: "eq",
value: "John Doe",
},
],
} satisfies CrudFilter);
expect(result).toStrictEqual({
field: "$id",
operator: "eq",
value: [
{
field: "id",
operator: "eq",
value: "John Doe",
},
],
});
});
it("should not replace the other field value with appwrite id", () => {
const result = replaceIdWithAppwriteId({
field: "name",
operator: "eq",
value: "John Doe",
} satisfies CrudFilter);
expect(result).toStrictEqual({
field: "name",
operator: "eq",
value: "John Doe",
});
});
});