import { describe, expect, it } from 'vitest';
import { encodeWtKey, decodeWtKey } from '../src/lib/wt-key';

describe('wt-key (base64url)', () => {
  const paths = [
    '/home/johan/WebstormProjects/arboretum',
    '/srv/code/feature-branch',
    '/tmp/with space/and-dash',
    '/projets/accentué/café/é',
    '/a/b/c/d/e/f/g',
  ];

  it('round-trip encode → decode pour divers chemins', () => {
    for (const p of paths) expect(decodeWtKey(encodeWtKey(p))).toBe(p);
  });

  it('produit un segment d’URL sûr (pas de + / =)', () => {
    for (const p of paths) {
      const key = encodeWtKey(p);
      expect(key).not.toMatch(/[+/=]/);
      expect(encodeURIComponent(key)).toBe(key); // déjà URL-safe
    }
  });
});
