mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-21 16:00:59 -05:00
Added tests for action-parameter-path-parser
This commit is contained in:
parent
f9426336e6
commit
3c4ae09cb2
1 changed files with 130 additions and 0 deletions
130
tests/unit/utils/actions/action-parameter-path-parser.spec.ts
Normal file
130
tests/unit/utils/actions/action-parameter-path-parser.spec.ts
Normal file
|
@ -0,0 +1,130 @@
|
|||
import { ActionMetadata } from "@/utils/actions";
|
||||
import { IDENTITY_ACTION_PARAMETER_PATH_PARSER, SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER, SPLIT_BY_WORDS_AND_GROUP_ACTION_PARAMETER_PATH_PARSER } from "@/utils/actions/action-parameter-path-parser";
|
||||
|
||||
describe("IDENTITY_ACTION_PARAMETER_PATH_PARSER", () => {
|
||||
test("returns the parameter name as a single-element array", () => {
|
||||
const name = "param1";
|
||||
|
||||
const path = IDENTITY_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([name]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is an empty string", () => {
|
||||
const name = "";
|
||||
|
||||
const path = IDENTITY_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([name]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is null", () => {
|
||||
const name = null;
|
||||
|
||||
const path = SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([""]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is undefined", () => {
|
||||
const name = undefined;
|
||||
|
||||
const path = SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([""]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER", () => {
|
||||
test("splits the parameter name by non-letter and non-number characters and converts each word to lowercase", () => {
|
||||
const name = "param1-param2_param3 param4";
|
||||
|
||||
const path = SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual(["param1", "param2", "param3", "param4"]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is an empty string", () => {
|
||||
const name = "";
|
||||
|
||||
const path = SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([""]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is null", () => {
|
||||
const name = null;
|
||||
|
||||
const path = SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([""]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is undefined", () => {
|
||||
const name = undefined;
|
||||
|
||||
const path = SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([""]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("SPLIT_BY_WORDS_AND_GROUP_ACTION_PARAMETER_PATH_PARSER", () => {
|
||||
test("splits the parameter name by non-letter and non-number characters, converts each word to lowercase, and groups the parameter based on the input/output group specified in the metadata object", () => {
|
||||
const name = "foo-qux-waldo";
|
||||
const parameter = { description: "This is foo-qux-waldo", type: "string" };
|
||||
const metadata = {
|
||||
inputs: { "foo-qux-waldo": parameter },
|
||||
groups: { input: { foo: {} } },
|
||||
} as unknown as ActionMetadata;
|
||||
|
||||
const path = SPLIT_BY_WORDS_AND_GROUP_ACTION_PARAMETER_PATH_PARSER(name, parameter, metadata);
|
||||
|
||||
expect(path).toEqual(["foo", "quxWaldo"]);
|
||||
});
|
||||
|
||||
test("returns the same path as SPLIT_BY_WORDS_ACTION_PARAMETER_PATH_PARSER if the parameter or metadata is not provided", () => {
|
||||
const name = "foo-qux-waldo";
|
||||
|
||||
const path = SPLIT_BY_WORDS_AND_GROUP_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual(["foo", "qux", "waldo"]);
|
||||
});
|
||||
|
||||
test("returns a single word path if the parameter is not a part of a group", () => {
|
||||
const name = "foo-qux-waldo";
|
||||
const parameter = { description: "This is foo-qux-waldo", type: "string" };
|
||||
const metadata = {
|
||||
inputs: { "bar-baz": parameter },
|
||||
groups: { input: { foo: {} } },
|
||||
} as unknown as ActionMetadata;
|
||||
|
||||
const path = SPLIT_BY_WORDS_AND_GROUP_ACTION_PARAMETER_PATH_PARSER(name, parameter, metadata);
|
||||
|
||||
expect(path).toEqual(["fooQuxWaldo"]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is an empty string", () => {
|
||||
const name = "";
|
||||
|
||||
const path = SPLIT_BY_WORDS_AND_GROUP_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([""]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is null", () => {
|
||||
const name = null;
|
||||
|
||||
const path = SPLIT_BY_WORDS_AND_GROUP_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([""]);
|
||||
});
|
||||
|
||||
test("returns an array with an empty string if the parameter name is undefined", () => {
|
||||
const name = undefined;
|
||||
|
||||
const path = SPLIT_BY_WORDS_AND_GROUP_ACTION_PARAMETER_PATH_PARSER(name);
|
||||
|
||||
expect(path).toEqual([""]);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue