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

describe('parsePostcode', () => {
  it('normalises to "1234 AB" (uppercase, single space, trimmed)', () => {
    for (const raw of ['1234ab', '1234 AB', ' 1234ab ', '1234AB']) {
      const r = parsePostcode(raw);
      expect(r.ok).toBe(true);
      if (r.ok) expect(r.value).toBe('1234 AB');
    }
  });

  it('rejects malformed postcodes', () => {
    expect(parsePostcode('').ok).toBe(false);
    expect(parsePostcode('0234AB').ok).toBe(false); // leading zero
    expect(parsePostcode('123AB').ok).toBe(false); // 3 digits
    expect(parsePostcode('1234A').ok).toBe(false); // 1 letter
    expect(parsePostcode('1234ABC').ok).toBe(false); // 3 letters
  });
});
