import { describe, expect, it } from 'vitest';
import {
  formatWeekOf,
  isCurrentWeek,
  toWeekStartIso,
} from '@/shared/business/week';

describe('shared week util (American / Sunday start)', () => {
  it('snaps any day to its week-start Sunday', () => {
    // 2026-06-10 is a Wednesday → week starts Sunday 2026-06-07.
    expect(toWeekStartIso(new Date('2026-06-10T12:00:00'))).toBe('2026-06-07');
    // A Sunday maps to itself.
    expect(toWeekStartIso(new Date('2026-06-07T08:00:00'))).toBe('2026-06-07');
    // A Saturday is the last day of the week.
    expect(toWeekStartIso(new Date('2026-06-13T23:00:00'))).toBe('2026-06-07');
  });

  it('formats a week-start ISO as "Month D, YYYY"', () => {
    expect(formatWeekOf('2026-06-07')).toBe('June 7, 2026');
  });

  it('detects the current week relative to a reference date', () => {
    const now = new Date('2026-06-10T09:00:00');
    expect(isCurrentWeek('2026-06-07', now)).toBe(true);
    expect(isCurrentWeek('2026-06-14', now)).toBe(false);
  });
});
