import { describe, it, expect } from 'vitest';
import { trialDaysRemaining, formatPlanBadge } from '@/lib/billing/plan';

describe('plan', () => {
  it('calcula días de trial restantes (redondeo hacia arriba, nunca negativo)', () => {
    const now = new Date('2026-05-30T12:00:00Z');
    expect(trialDaysRemaining(new Date('2026-06-05T12:00:00Z'), now)).toBe(6);
    expect(trialDaysRemaining(new Date('2026-05-30T18:00:00Z'), now)).toBe(1);
    expect(trialDaysRemaining(new Date('2026-05-29T12:00:00Z'), now)).toBe(0);
    expect(trialDaysRemaining(null, now)).toBe(0);
  });

  it('formatea el badge según estado', () => {
    const now = new Date('2026-05-30T12:00:00Z');
    expect(formatPlanBadge('Pro', 'trial', new Date('2026-06-05T12:00:00Z'), now))
      .toBe('Plan Pro · trial, 6 días restantes');
    expect(formatPlanBadge('Pro', 'activo', null, now)).toBe('Plan Pro · activo');
    expect(formatPlanBadge(null, 'trial', new Date('2026-06-05T12:00:00Z'), now))
      .toBe('Sin plan · trial, 6 días restantes');
  });
});
