import { describe, it, expect } from 'vitest';
import { matchPublicRoute } from './publicRoute';

// パスマッチは純関数。DOM 非依存なので node 環境でそのままテストできる。
describe('matchPublicRoute', () => {
  it('matches the public app route', () => {
    expect(matchPublicRoute('/ui/app/abc')).toEqual({ kind: 'app', token: 'abc' });
  });

  it('matches the shared task route', () => {
    expect(matchPublicRoute('/ui/shared/tok123')).toEqual({ kind: 'shared', token: 'tok123' });
  });

  it('matches the invite route', () => {
    expect(matchPublicRoute('/ui/invite/inv9')).toEqual({ kind: 'invite', token: 'inv9' });
  });

  it('decodes percent-encoded tokens', () => {
    expect(matchPublicRoute('/ui/app/a%2Fb')).toEqual({ kind: 'app', token: 'a/b' });
  });

  it('ignores trailing path segments after the token', () => {
    expect(matchPublicRoute('/ui/app/abc/extra')).toEqual({ kind: 'app', token: 'abc' });
  });

  it('returns null for non-public paths', () => {
    expect(matchPublicRoute('/ui/spaces')).toBeNull();
    expect(matchPublicRoute('/ui/app/')).toBeNull();
    expect(matchPublicRoute('/')).toBeNull();
  });
});
