2022-12-01 04:55:57 +00:00
|
|
|
import _ from "lodash";
|
|
|
|
|
import { sourceDataArrayValidation } from "./validations";
|
|
|
|
|
|
|
|
|
|
describe("sourceDataArrayValidation", () => {
|
|
|
|
|
it("Should test with valid values", () => {
|
|
|
|
|
const mockSourceData = [
|
|
|
|
|
{
|
|
|
|
|
step: "#1",
|
|
|
|
|
task: "Drop a table",
|
|
|
|
|
status: "✅",
|
|
|
|
|
action: "",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
step: "#2",
|
|
|
|
|
task: "Create a query fetch_users with the Mock DB",
|
|
|
|
|
status: "--",
|
|
|
|
|
action: "",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
step: "#3",
|
|
|
|
|
task: "Bind the query using => fetch_users.data",
|
|
|
|
|
status: "--",
|
|
|
|
|
action: "",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const result = sourceDataArrayValidation(
|
|
|
|
|
mockSourceData,
|
|
|
|
|
undefined as any,
|
|
|
|
|
_,
|
|
|
|
|
);
|
|
|
|
|
const expected = {
|
|
|
|
|
isValid: true,
|
|
|
|
|
parsed: mockSourceData,
|
2023-02-18 12:55:46 +00:00
|
|
|
messages: [{ name: "", message: "" }],
|
2022-12-01 04:55:57 +00:00
|
|
|
};
|
|
|
|
|
expect(result).toStrictEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("Should test when sourceData has a length more than 10", () => {
|
|
|
|
|
const mockSourceData = Array(11).fill((_: null, index: number) => {
|
|
|
|
|
return {
|
|
|
|
|
step: `#${index}`,
|
|
|
|
|
task: `Task ${index}`,
|
|
|
|
|
status: "--",
|
|
|
|
|
action: "",
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = sourceDataArrayValidation(
|
|
|
|
|
mockSourceData,
|
|
|
|
|
undefined as any,
|
|
|
|
|
_,
|
|
|
|
|
);
|
|
|
|
|
const expected = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: [],
|
2023-02-18 12:55:46 +00:00
|
|
|
messages: [
|
|
|
|
|
{
|
|
|
|
|
name: "RangeError",
|
|
|
|
|
message: "Source data cannot have more than 10 items",
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-12-01 04:55:57 +00:00
|
|
|
};
|
|
|
|
|
expect(result).toStrictEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("Should test when sourceData is not an array", () => {
|
|
|
|
|
const mockSourceData = {
|
|
|
|
|
step: "#1",
|
|
|
|
|
task: "Drop a table",
|
|
|
|
|
status: "✅",
|
|
|
|
|
action: "",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const result = sourceDataArrayValidation(
|
|
|
|
|
mockSourceData,
|
|
|
|
|
undefined as any,
|
|
|
|
|
_,
|
|
|
|
|
);
|
|
|
|
|
const expected = {
|
|
|
|
|
isValid: false,
|
|
|
|
|
parsed: [],
|
2023-02-18 12:55:46 +00:00
|
|
|
messages: [
|
|
|
|
|
{
|
|
|
|
|
name: "TypeError",
|
|
|
|
|
message: "This value does not evaluate to type Array",
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-12-01 04:55:57 +00:00
|
|
|
};
|
|
|
|
|
expect(result).toStrictEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
});
|