mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
48 lines
1.4 KiB
TypeScript
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);
|
|
});
|
|
});
|