import { test } from 'node:test';
import assert from 'node:assert/strict';
import { toWeekStartIso } from '@/shared/constants/week';

test('normalizes any date to its Sunday week-start (American style)', () => {
  // 2026-06-10 is a Wednesday → Sunday 2026-06-07.
  assert.equal(toWeekStartIso('2026-06-10'), '2026-06-07');
  // A Sunday maps to itself; a Saturday maps back to that Sunday.
  assert.equal(toWeekStartIso('2026-06-07'), '2026-06-07');
  assert.equal(toWeekStartIso('2026-06-13'), '2026-06-07');
});

test('rejects non-date / malformed input', () => {
  assert.equal(toWeekStartIso('Week of June 1, 2026'), null);
  assert.equal(toWeekStartIso('2026-13-01'), null);
  assert.equal(toWeekStartIso('2026-02-31'), null);
  assert.equal(toWeekStartIso(''), null);
  assert.equal(toWeekStartIso(null), null);
  assert.equal(toWeekStartIso(42), null);
});
