import { describe, it, expect } from 'vitest';
import { spacesFolderRoot, resolveSpaceFolder } from './folder-resolver.js';

describe('spacesFolderRoot', () => {
  it('is the sibling "spaces" dir of the user folder root', () => {
    expect(spacesFolderRoot('/srv/data/users')).toBe('/srv/data/spaces');
    expect(spacesFolderRoot('./data/users')).toBe('data/spaces');
  });
});

describe('resolveSpaceFolder', () => {
  const userFolderRoot = '/srv/data/users';
  it('personal space resolves to the legacy user folder (rootDir=userFolderRoot, leafId=ownerId)', () => {
    const r = resolveSpaceFolder({ kind: 'personal', id: 'sp-1', ownerId: 'user-9' }, userFolderRoot);
    expect(r).toEqual({ rootDir: '/srv/data/users', leafId: 'user-9' });
  });
  it('case space resolves to data/spaces with leafId=spaceId', () => {
    const r = resolveSpaceFolder({ kind: 'case', id: 'sp-2', ownerId: 'user-9' }, userFolderRoot);
    expect(r).toEqual({ rootDir: '/srv/data/spaces', leafId: 'sp-2' });
  });
  it('personal space without ownerId falls back to local', () => {
    const r = resolveSpaceFolder({ kind: 'personal', id: 'sp-3', ownerId: null }, userFolderRoot);
    expect(r).toEqual({ rootDir: '/srv/data/users', leafId: 'local' });
  });
});
