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

27 lines
763 B
TypeScript

import { handleError } from "../../src/utils";
import type { PostgrestError } from "@supabase/supabase-js";
import type { HttpError } from "@refinedev/core";
describe("handleError", () => {
it("should transform PostgrestError into HttpError and reject the promise", async () => {
const postgrestError: PostgrestError = {
message: "Test error message",
code: "404",
details: "Not found",
hint: "Check your endpoint",
};
const expectedHttpError: HttpError = {
...postgrestError,
message: postgrestError.message,
statusCode: Number.parseInt(postgrestError.code),
};
try {
await handleError(postgrestError);
} catch (error) {
expect(error).toEqual(expectedHttpError);
}
});
});