FactuGES_ERP/apps/server/src/common/domain/value-objects/name.spec.ts
2025-02-20 19:55:24 +01:00

42 lines
1.5 KiB
TypeScript

import { Name } from "./name";
describe("Name Value Object", () => {
test("Debe crear un Name válido", () => {
const nameResult = Name.create("John Doe");
expect(nameResult.isSuccess).toBe(true);
expect(nameResult.data.getValue()).toBe("John Doe");
});
test("Debe fallar si el nombre excede los 255 caracteres", () => {
const longName = "A".repeat(256);
const nameResult = Name.create(longName);
expect(nameResult.isSuccess).toBe(false);
expect(nameResult.error).toBeInstanceOf(Error);
});
test("Debe permitir un Name nullable vacío", () => {
const nullableNameResult = Name.createNullable("");
expect(nullableNameResult.isSuccess).toBe(true);
expect(nullableNameResult.data.isSome()).toBe(false);
});
test("Debe permitir un Name nullable con un valor válido", () => {
const nullableNameResult = Name.createNullable("Alice");
expect(nullableNameResult.isSuccess).toBe(true);
expect(nullableNameResult.data.isSome()).toBe(true);
expect(nullableNameResult.data.getValue()).toBe("Alice");
});
test("Debe generar acrónimos correctamente", () => {
expect(Name.generateAcronym("John Doe")).toBe("JDXX");
expect(Name.generateAcronym("Alice Bob Charlie")).toBe("ABCX");
expect(Name.generateAcronym("A B C D E")).toBe("ABCD");
expect(Name.generateAcronym("SingleWord")).toBe("SXXX");
});
test("Debe obtener el acrónimo de una instancia de Name", () => {
const name = Name.create("John Doe").data;
expect(name.getAcronym()).toBe("JDXX");
});
});