import { LoggingService } from './logging.service';

describe('LoggingService', () => {
  it('can persist an event through the caller transaction manager', async () => {
    const defaultRepository = { save: jest.fn() };
    const transactionRepository = { save: jest.fn() };
    const manager = {
      getRepository: jest.fn(() => transactionRepository),
    } as any;
    const service = new LoggingService(defaultRepository as any);
    const event = {
      event: 'admin_user_profile_update' as const,
      details: 'targetUserId=2',
      userId: 1,
    };

    await service.info(event, manager);

    expect(transactionRepository.save).toHaveBeenCalledWith({
      ...event,
      level: 'INFO',
    });
    expect(defaultRepository.save).not.toHaveBeenCalled();
  });
});
