import { describe, it, expect } from 'vitest';
import { ownerDisplayName } from './owner';

describe('ownerDisplayName', () => {
  it('shows the real user name when present', () => {
    expect(ownerDisplayName('u123', 'Alice')).toBe('Alice');
  });

  it('shows "local" for the no-auth local owner', () => {
    expect(ownerDisplayName('local', null)).toBe('local');
  });

  it('shows "local" for legacy NULL owner (no-auth rows created before the owner fix)', () => {
    expect(ownerDisplayName(null, null)).toBe('local');
    expect(ownerDisplayName(undefined, undefined)).toBe('local');
  });

  it('falls back to "system" for an owner id with no matching user (e.g. deleted account)', () => {
    expect(ownerDisplayName('u-deleted', null)).toBe('system');
  });
});
