import { ReportingCore } from '../..' ; import { RunContext } from '../../../../task_manager/server' ; import { taskManagerMock } from '../../../../task_manager/server/mocks' ; import { ReportingConfigType } from '../../config' ; import { createMockConfigSchema , createMockLevelLogger , createMockReportingCore , } from '../../test_helpers' ; import { ExecuteReportTask } from './' ; const logger = createMockLevelLogger ( ) ; describe ( 'Execute Report Task' , ( ) => { let mockReporting ; let configType ; beforeAll ( async ( ) => { configType = createMockConfigSchema ( ) ; mockReporting = await createMockReportingCore ( configType ) ; } ) ; it ( 'Instance setup' , ( ) => { const task = new ExecuteReportTask ( mockReporting , configType , logger ) ; expect ( task . getStatus ( ) ) . toBe ( 'uninitialized' ) ; expect ( task . getTaskDefinition ( ) ) . toMatchInlineSnapshot ( `
      Object {
        "createTaskRunner": [Function],
        "maxAttempts": 1,
        "maxConcurrency": 1,
        "timeout": "120s",
        "title": "Reporting: execute job",
        "type": "report:execute",
      }
    ` ) ; } ) ; it ( 'Instance start' , ( ) => { const mockTaskManager = taskManagerMock . createStart ( ) ; const task = new ExecuteReportTask ( mockReporting , configType , logger ) ; expect ( task . init ( mockTaskManager ) ) ; expect ( task . getStatus ( ) ) . toBe ( 'initialized' ) ; } ) ; it ( 'create task runner' , async ( ) => { logger . info = jest . fn ( ) ; logger . error = jest . fn ( ) ; const task = new ExecuteReportTask ( mockReporting , configType , logger ) ; const taskDef = task . getTaskDefinition ( ) ; const taskRunner = taskDef . createTaskRunner ( { taskInstance : { id : 'random-task-id' , params : { index : 'cool-reporting-index' , id : 'cool-reporting-id' } , } , } as unknown as RunContext ) ; expect ( taskRunner ) . toHaveProperty ( 'run' ) ; expect ( taskRunner ) . toHaveProperty ( 'cancel' ) ; } ) ; it ( 'Max Concurrency is 0 if pollEnabled is false' , ( ) => { const queueConfig = { queue : { pollEnabled : false , timeout : 55000 } , } as unknown as ReportingConfigType [ 'queue' ] ; const task = new ExecuteReportTask ( mockReporting , { ... configType , ... queueConfig } , logger ) ; expect ( task . getStatus ( ) ) . toBe ( 'uninitialized' ) ; expect ( task . getTaskDefinition ( ) ) . toMatchInlineSnapshot ( `
      Object {
        "createTaskRunner": [Function],
        "maxAttempts": 1,
        "maxConcurrency": 0,
        "timeout": "55s",
        "title": "Reporting: execute job",
        "type": "report:execute",
      }
    ` ) ; } ) ; } ) ;