import { COMPETITOR_PRICES, getStaleEntries } from './competitor-pricing';

describe('competitor-pricing', () => {
  it('has lastVerified date within 6 months for all entries', () => {
    const sixMonthsAgo = new Date();
    sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);

    for (const entry of COMPETITOR_PRICES) {
      const verified = new Date(entry.lastVerified);
      expect(verified.getTime()).toBeGreaterThan(sixMonthsAgo.getTime());
    }
  });

  it('has at least 3 competitors', () => {
    expect(COMPETITOR_PRICES.length).toBeGreaterThanOrEqual(3);
  });

  it('all entries have sourceUrl', () => {
    for (const entry of COMPETITOR_PRICES) {
      expect(entry.sourceUrl).toBeTruthy();
      expect(entry.sourceUrl).toMatch(/^https?:\/\//);
    }
  });

  it('getStaleEntries returns empty when all recent', () => {
    const stale = getStaleEntries(365);
    expect(stale).toHaveLength(0);
  });

  it('enforces 90-day refresh policy — no entry older than 90 days', () => {
    // This test is the CI enforcement for the 90-day review requirement documented
    // in competitor-pricing.ts. It will fail when any lastVerified date exceeds 90
    // days ago, forcing a manual pricing review before the build can pass.
    const stale = getStaleEntries(90);
    expect(stale).toHaveLength(0);
  });
});
