import { Slug } from "./slug"; // Ajusta la ruta según corresponda

describe("Slug Value Object", () => {
  test("Debe crear un Slug válido", () => {
    const slugResult = Slug.create("valid-slug-123");
    expect(slugResult.isSuccess).toBe(true);
    expect(slugResult.data.getValue()).toBe("valid-slug-123");
  });

  test("Debe fallar si el Slug contiene caracteres inválidos", () => {
    const slugResult = Slug.create("Invalid_Slug!");
    expect(slugResult.isSuccess).toBe(false);
    expect(slugResult.error).toBeInstanceOf(Error);
  });

  test("Debe fallar si el Slug tiene menos de 2 caracteres", () => {
    const slugResult = Slug.create("a");
    expect(slugResult.isSuccess).toBe(false);
    expect(slugResult.error).toBeInstanceOf(Error);
  });

  test("Debe fallar si el Slug tiene más de 100 caracteres", () => {
    const longSlug = "a".repeat(101);
    const slugResult = Slug.create(longSlug);
    expect(slugResult.isSuccess).toBe(false);
    expect(slugResult.error).toBeInstanceOf(Error);
  });

  test("Debe permitir un Slug nullable vacío", () => {
    const nullableSlugResult = Slug.createNullable("");
    expect(nullableSlugResult.isSuccess).toBe(true);
    expect(nullableSlugResult.data.isSome()).toBe(false);
  });

  test("Debe permitir un Slug nullable con un valor válido", () => {
    const nullableSlugResult = Slug.createNullable("my-slug");
    expect(nullableSlugResult.isSuccess).toBe(true);
    expect(nullableSlugResult.data.isSome()).toBe(true);
    expect(nullableSlugResult.data.getOrUndefined()?.toString()).toBe("my-slug");
  });
});
