Made DependencyType enum

This commit is contained in:
Kir_Antipov 2023-02-24 05:23:13 +00:00
parent a7049ca420
commit 989ccf0c87
2 changed files with 92 additions and 0 deletions

View file

@ -0,0 +1,63 @@
import { Enum, EnumOptions } from "@/utils/enum";
/**
* Represents different dependency types.
*
* @partial
*/
enum DependencyTypeValues {
/**
* The dependency is required for the project to function.
*/
REQUIRED = "required",
/**
* The dependency is recommended for the project but not required.
*/
RECOMMENDED = "recommended",
/**
* The dependency is embedded within the project.
*/
EMBEDDED = "embedded",
/**
* The dependency is optional and provides additional features.
*/
OPTIONAL = "optional",
/**
* The dependency conflicts with the project and both should not be used together.
*/
CONFLICTING = "conflicting",
/**
* The dependency is incompatible with the project.
*/
INCOMPATIBLE = "incompatible",
}
/**
* Options for configuring the behavior of the DependencyType enum.
*
* @partial
*/
const DependencyTypeOptions: EnumOptions = {
/**
* The case should be ignored while parsing the dependency type.
*/
ignoreCase: true,
};
/**
* Represents different dependency types.
*/
export const DependencyType = Enum.create(
DependencyTypeValues,
DependencyTypeOptions,
);
/**
* Represents different dependency types.
*/
export type DependencyType = Enum<typeof DependencyTypeValues>;

View file

@ -0,0 +1,29 @@
import { DependencyType } from "@/dependencies/dependency-type";
describe("DependencyType", () => {
describe("parse", () => {
test("parses all its own formatted values", () => {
for (const value of DependencyType.values()) {
expect(DependencyType.parse(DependencyType.format(value))).toBe(value);
}
});
test("parses all friendly names of its own values", () => {
for (const value of DependencyType.values()) {
expect(DependencyType.parse(DependencyType.friendlyNameOf(value))).toBe(value);
}
});
test("parses all its own formatted values in lowercase", () => {
for (const value of DependencyType.values()) {
expect(DependencyType.parse(DependencyType.format(value).toLowerCase())).toBe(value);
}
});
test("parses all its own formatted values in UPPERCASE", () => {
for (const value of DependencyType.values()) {
expect(DependencyType.parse(DependencyType.format(value).toUpperCase())).toBe(value);
}
});
});
});