import { describe, it, expect } from "vitest";
import { formatPhoneNumber, isValidPhoneNumber } from "./formatPhoneNumber";

describe("formatPhoneNumber", () => {
  it("should add + when phone does not start with +", () => {
    expect(formatPhoneNumber("11 1234 1234")).toBe("+5491112341234");
  });

  it("should remove + when phone already starts with +", () => {
    expect(formatPhoneNumber("+11 1234 1234")).toBe("+5491112341234");
  });

  it("should add + to a phone without spaces", () => {
    expect(formatPhoneNumber("123456789")).toBe("+549123456789");
  });

  it("should remove + from a phone without spaces", () => {
    expect(formatPhoneNumber("+123456789")).toBe("+549123456789");
  });

  it("should remove multiple spaces between numbers", () => {
    expect(formatPhoneNumber("11   1234    1234")).toBe("+5491112341234");
  });

  it("should handle leading and trailing spaces", () => {
    expect(formatPhoneNumber(" 11 1234 1234 ")).toBe("+5491112341234");
  });
});

describe("isValidNumber", () => {
  it("should return true", () => {
    expect(isValidPhoneNumber("5491171987773")).toBe(true);
  });
  it("should return false", () => {
    expect(isValidPhoneNumber("54911719")).toBe(false);
  });
});
