import { describe, expect, it } from 'vitest';
import { rememberLabel } from './rememberLabel';

const DAY = 86400;
const NOW = 1_800_000_000;

describe('rememberLabel', () => {
  it('counts whole days remaining, rounding partial days up', () => {
    expect(rememberLabel(NOW + 90 * DAY, NOW)).toBe('Remembered for 90 days');
    // 1.9 days left rounds up to 2, not down to 1 — see the freshly-issued
    // case below for why floor is wrong here.
    expect(rememberLabel(NOW + 1.9 * DAY, NOW)).toBe('Remembered for 2 days');
  });

  it('reads "90 days" the moment a 90-day token is issued, not "89"', () => {
    // A token issued for exactly 90 days already has a second or two off its
    // expiry by the time this runs — flooring that would read "89 days" on
    // day zero, which is the bug this rounding fixes.
    expect(rememberLabel(NOW + 90 * DAY - 5, NOW)).toBe('Remembered for 90 days');
  });

  it('uses the singular for exactly one day', () => {
    expect(rememberLabel(NOW + DAY, NOW)).toBe('Remembered for 1 day');
  });

  it('says today rather than "0 days" on the last day', () => {
    expect(rememberLabel(NOW + 60, NOW)).toBe('Remembered until today');
  });

  it('returns null when there is nothing remembered or it has expired', () => {
    expect(rememberLabel(null, NOW)).toBeNull();
    expect(rememberLabel(undefined, NOW)).toBeNull();
    expect(rememberLabel(NOW - DAY, NOW)).toBeNull();
  });
});
