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

48 lines
1.4 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);
});
});