import { describe, it, expect } from "vitest";
import { formatDuration } from "./format_duration";

const MIN = 60_000;
const HOUR = 60 * MIN;
const DAY = 24 * HOUR;
const WEEK = 7 * DAY;
const MONTH = 30 * DAY;

describe("formatDuration", () => {
  it("menos de un minuto retorna 0m", () => {
    expect(formatDuration(0)).toBe("0m");
    expect(formatDuration(30_000)).toBe("0m");
    expect(formatDuration(59_999)).toBe("0m");
  });

  it("exactamente 1 hora retorna 1h", () => {
    expect(formatDuration(HOUR)).toBe("1h");
  });

  it("1h 30m retorna 1h 30m", () => {
    expect(formatDuration(HOUR + 30 * MIN)).toBe("1h 30m");
  });

  it("1 dia sin horas retorna 1D", () => {
    expect(formatDuration(DAY)).toBe("1D");
  });

  it("2 dias 3 horas retorna 2D 3h", () => {
    expect(formatDuration(2 * DAY + 3 * HOUR)).toBe("2D 3h");
  });

  it("1 semana sin dias retorna 1S", () => {
    expect(formatDuration(WEEK)).toBe("1S");
  });

  it("2 semanas 3 dias retorna 2S 3D", () => {
    expect(formatDuration(2 * WEEK + 3 * DAY)).toBe("2S 3D");
  });

  it("1 mes sin semanas retorna 1M", () => {
    expect(formatDuration(MONTH)).toBe("1M");
  });

  it("2 meses 1 semana retorna 2M 1S", () => {
    expect(formatDuration(2 * MONTH + WEEK)).toBe("2M 1S");
  });

  it("NaN retorna 0m", () => {
    expect(formatDuration(NaN)).toBe("0m");
  });

  it("negativo retorna 0m", () => {
    expect(formatDuration(-1)).toBe("0m");
    expect(formatDuration(-999)).toBe("0m");
  });

  it("Infinity retorna 0m", () => {
    expect(formatDuration(Infinity)).toBe("0m");
  });
});
