/**
 * User Impersonation module — unit tests.
 */

import { describe, it, expect } from 'vitest';
import { StartImpersonationSchema, StopImpersonationSchema } from './types.js';

describe('StartImpersonationSchema', () => {
  it('accepts valid input', () => {
    const result = StartImpersonationSchema.parse({
      targetUserId: 'user-123',
      reason: 'Debugging timer sync issue',
    });
    expect(result.targetUserId).toBe('user-123');
    expect(result.reason).toBe('Debugging timer sync issue');
  });

  it('rejects empty targetUserId', () => {
    expect(() => StartImpersonationSchema.parse({ targetUserId: '', reason: 'test' })).toThrow();
  });

  it('rejects empty reason', () => {
    expect(() => StartImpersonationSchema.parse({ targetUserId: 'u1', reason: '' })).toThrow();
  });

  it('rejects reason over 500 chars', () => {
    expect(() =>
      StartImpersonationSchema.parse({ targetUserId: 'u1', reason: 'x'.repeat(501) })
    ).toThrow();
  });
});

describe('StopImpersonationSchema', () => {
  it('accepts valid sessionId', () => {
    const result = StopImpersonationSchema.parse({ sessionId: 'imp-abc123' });
    expect(result.sessionId).toBe('imp-abc123');
  });

  it('rejects empty sessionId', () => {
    expect(() => StopImpersonationSchema.parse({ sessionId: '' })).toThrow();
  });
});
