import { BackgroundJobWorker } from '../jobs/background-job.worker';
import { XiaobaoRiskWorker } from './xiaobao-risk.worker';

describe('XiaobaoRiskWorker', () => {
  it('registers the summary refresh handler on module init', async () => {
    const worker = {
      registerHandler: jest.fn(),
    };
    const risk = {
      refreshSummary: jest.fn().mockResolvedValue({ versionId: 'version-1' }),
    };
    const service = new XiaobaoRiskWorker(worker as unknown as BackgroundJobWorker, risk as any);

    service.onModuleInit();

    expect(worker.registerHandler).toHaveBeenCalledWith('xiaobao.summary.refresh', expect.any(Function));
    const handler = worker.registerHandler.mock.calls[0][1];
    await handler({ versionId: 'version-1' }, { id: 'job-1' });
    expect(risk.refreshSummary).toHaveBeenCalledWith('version-1');
  });
});
