import { ajustarPorIndice, periodoDe } from './ajuste-indice';

describe('ajustarPorIndice', () => {
  it('ajusta la cuota por la inflación desde la firma', () => {
    // IPC firma 150, vigente 157,5 → +5 %
    expect(ajustarPorIndice(2_000_000, 150, 157.5)).toBe(2_100_000);
  });

  it('con deflación no baja del monto original', () => {
    expect(ajustarPorIndice(2_000_000, 150, 148)).toBe(2_000_000);
  });

  it('redondea a guaraníes enteros', () => {
    expect(ajustarPorIndice(1_000_000, 3, 4)).toBe(1_333_333);
  });

  it('sin índices no inventa: rechaza', () => {
    expect(() => ajustarPorIndice(1_000_000, 0, 150)).toThrow(/índices/);
    expect(() => ajustarPorIndice(1_000_000, 150, 0)).toThrow(/índices/);
  });
});

describe('periodoDe', () => {
  it('lleva cualquier día al 1 del mes', () => {
    expect(periodoDe('2026-10-23').toISOString().slice(0, 10)).toBe('2026-10-01');
    expect(
      periodoDe(new Date(Date.UTC(2026, 0, 31)))
        .toISOString()
        .slice(0, 10),
    ).toBe('2026-01-01');
  });
});
