import { EmailAddress } from "../email-address";

describe("EmailAddress Value Object", () => {
  it("should create a valid email", () => {
    const result = EmailAddress.create("user@example.com");

    expect(result.isSuccess).toBe(true);
    expect(result.data.getProps()).toBe("user@example.com");
  });

  it("should return an error for invalid email format", () => {
    const result = EmailAddress.create("invalid-email");

    expect(result.isFailure).toBe(true);
    expect(result.error.message).toBe("Invalid email format");
  });

  it("should return an error for empty string", () => {
    const result = EmailAddress.create("");

    expect(result.isSuccess).toBe(false);
  });

  it("should compare two equal email objects correctly", () => {
    const email1 = EmailAddress.create("test@example.com");
    const email2 = EmailAddress.create("test@example.com");

    expect(email1.isSuccess).toBe(true);
    expect(email2.isSuccess).toBe(true);
    expect(email1.data.equals(email2.data)).toBe(true);
  });

  it("should compare two different email objects as not equal", () => {
    const email1 = EmailAddress.create("test@example.com");
    const email2 = EmailAddress.create("other@example.com");

    expect(email1.isSuccess).toBe(true);
    expect(email2.isSuccess).toBe(true);
    expect(email1.data.equals(email2.data)).toBe(false);
  });

  it("should detect non-empty email correctly", () => {
    const email = EmailAddress.create("test@example.com");

    expect(email.isSuccess).toBe(true);
    expect(email.data.getProps()).toBe("test@example.com");
  });
});
