import { PostalAddress } from "../postal-address";

describe("PostalAddress Value Object", () => {
  const validAddress = {
    street: "123 Main St",
    city: "Springfield",
    postalCode: "12345",
    state: "IL",
    country: "USA",
  };

  test("✅ Debería crear un PostalAddress con valores válidos", () => {
    const result = PostalAddress.create(validAddress);

    expect(result.isSuccess).toBe(true);
    expect(result.data).toBeInstanceOf(PostalAddress);
  });

  test("❌ Debería fallar al crear un PostalAddress con código postal inválido", () => {
    const invalidAddress = { ...validAddress, postalCode: "abc" }; // Código postal inválido
    const result = PostalAddress.create(invalidAddress);

    expect(result.isFailure).toBe(true);
    expect(result.error?.message).toBe("Invalid postal code format");
  });

  test("✅ Métodos getters deberían devolver valores esperados", () => {
    const address = PostalAddress.create(validAddress).data;

    expect(address.street).toBe(validAddress.street);
    expect(address.city).toBe(validAddress.city);
    expect(address.postalCode).toBe(validAddress.postalCode);
    expect(address.state).toBe(validAddress.state);
    expect(address.country).toBe(validAddress.country);
  });

  test("✅ `toString()` debería devolver la representación correcta", () => {
    const address = PostalAddress.create(validAddress).data;
    const expectedString = `${validAddress.street}, ${validAddress.city}, ${validAddress.postalCode}, ${validAddress.state}, ${validAddress.country}`;

    expect(address.toString()).toBe(expectedString);
  });
});
