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

48 lines
1.6 KiB
TypeScript

import { transformErrorMessages } from "../../src/utils";
describe("transformErrorMessages", () => {
it("should transform error messages", () => {
const errorMessages = [
{
path: ["title"],
message: "title must be at most 5 characters",
name: "ValidatorError",
},
{
path: ["slug"],
message: "This attribute must be unique",
name: "ValidatorError",
},
{
path: ["status"],
message:
'status must be a `string` type, but the final value was: `[\n "\\"draft\\""\n]`.',
name: "ValidatorError",
},
{
path: ["status"],
message:
"status must be one of the following values: draft, rejected, approved",
name: "ValidatorError",
},
];
expect(transformErrorMessages(errorMessages)).toEqual({
title: ["title must be at most 5 characters"],
slug: ["This attribute must be unique"],
status: [
'status must be a `string` type, but the final value was: `[\n "\\"draft\\""\n]`.',
"status must be one of the following values: draft, rejected, approved",
],
});
});
it("should not throw an error with an empty array", () => {
const errorMessages: any = [];
const expectedOutput = {};
expect(transformErrorMessages(errorMessages)).toEqual(expectedOutput);
});
});