openpanel/packages/supabase/test/update/index.spec.ts
Stefan Pejcic 09f9f9502d packages
2024-11-07 19:03:37 +01:00

64 lines
1.3 KiB
TypeScript

import { dataProvider } from "../../src";
import supabaseClient from "../supabaseClient";
import "./index.mock";
describe("update", () => {
it("correct response with `select`", async () => {
const { data } = await dataProvider(supabaseClient).update({
id: 1,
resource: "posts",
variables: {
title: "test",
categoryId: 5,
content: "test content",
},
meta: {
select: "*",
},
});
expect(data).toEqual(
expect.objectContaining({
id: 1,
title: "test",
categoryId: 5,
content: "test content",
}),
);
});
it("should change schema", async () => {
const id = 1;
const { data } = await dataProvider(supabaseClient).update({
id,
resource: "posts",
variables: {
title: "IPhone 16",
},
meta: {
select: "*",
},
});
expect(data).toEqual(
expect.objectContaining({ id: 1, title: "IPhone 16" }),
);
const promise = dataProvider(supabaseClient).update({
id,
resource: "posts",
variables: {
title: "IPhone 16",
},
meta: {
schema: "private",
},
});
await expect(promise).rejects.toEqual(
expect.objectContaining({ code: "PGRST106" }),
);
});
});