@@ -135,9 +135,6 @@ describe('Run Scheduled Report Task', () => {
135135 mockReporting = await createMockReportingCore ( configType ) ;
136136
137137 soClient = await mockReporting . getInternalSoClient ( ) ;
138- soClient . get = jest . fn ( ) . mockImplementation ( async ( ) => {
139- return reportSO ;
140- } ) ;
141138
142139 mockReporting . getExportTypesRegistry ( ) . register ( {
143140 id : 'test1' ,
@@ -153,6 +150,9 @@ describe('Run Scheduled Report Task', () => {
153150 } ) ;
154151
155152 beforeEach ( async ( ) => {
153+ soClient . get = jest . fn ( ) . mockImplementation ( async ( ) => {
154+ return reportSO ;
155+ } ) ;
156156 reportStore = await mockReporting . getStore ( ) ;
157157 reportStore . addReport = jest . fn ( ) . mockImplementation ( async ( ) => {
158158 return savedReport ;
@@ -468,12 +468,57 @@ describe('Run Scheduled Report Task', () => {
468468 } ) ;
469469 const mockTaskManager = taskManagerMock . createStart ( ) ;
470470 await task . init ( mockTaskManager , emailNotificationService ) ;
471- const runAt = new Date ( '2025-06-04T00:00:00Z' ) ;
471+ const taskInstance = {
472+ id : 'task-id' ,
473+ runAt : new Date ( '2025-06-04T00:00:00Z' ) ,
474+ params : { id : 'report-so-id' , jobtype : 'test1' } ,
475+ } ;
476+ const byteSize = 2097152 ; // 2MB
477+ const output = { content_type : 'application/pdf' } ;
478+
479+ // @ts -expect-error
480+ await task . notify ( savedReport , taskInstance , output , byteSize , reportSO , 'default' ) ;
481+ expect ( soClient . get ) . not . toHaveBeenCalled ( ) ;
482+ expect ( emailNotificationService . notify ) . toHaveBeenCalledWith ( {
483+ contentType : 'application/pdf' ,
484+ emailParams : {
485+ bcc : [ 'test2@test.com' ] ,
486+ cc : undefined ,
487+ spaceId : 'default' ,
488+ subject : 'Test Report [2025-06-04T00:00:00.000Z] scheduled report' ,
489+ to : [ 'test1@test.com' ] ,
490+ } ,
491+ id : '290357209345723095' ,
492+ index : '.reporting-fantastic' ,
493+ jobType : 'test1' ,
494+ relatedObject : {
495+ id : 'report-so-id' ,
496+ namespace : 'default' ,
497+ type : 'scheduled-report' ,
498+ } ,
499+ reporting : mockReporting ,
500+ } ) ;
501+ } ) ;
502+
503+ it ( "gets the report SO if it's not defined" , async ( ) => {
504+ const task = new RunScheduledReportTask ( {
505+ reporting : mockReporting ,
506+ config : configType ,
507+ logger,
508+ } ) ;
509+ const mockTaskManager = taskManagerMock . createStart ( ) ;
510+ await task . init ( mockTaskManager , emailNotificationService ) ;
511+ const taskInstance = {
512+ id : 'task-id' ,
513+ runAt : new Date ( '2025-06-04T00:00:00Z' ) ,
514+ params : { id : 'report-so-id' , jobtype : 'test1' } ,
515+ } ;
472516 const byteSize = 2097152 ; // 2MB
473517 const output = { content_type : 'application/pdf' } ;
474518
475519 // @ts -expect-error
476- await task . notify ( savedReport , output , runAt , byteSize , reportSO , 'default' ) ;
520+ await task . notify ( savedReport , taskInstance , output , byteSize , undefined , 'default' ) ;
521+ expect ( soClient . get ) . toHaveBeenCalled ( ) ;
477522 expect ( emailNotificationService . notify ) . toHaveBeenCalledWith ( {
478523 contentType : 'application/pdf' ,
479524 emailParams : {
@@ -486,6 +531,11 @@ describe('Run Scheduled Report Task', () => {
486531 id : '290357209345723095' ,
487532 index : '.reporting-fantastic' ,
488533 jobType : 'test1' ,
534+ relatedObject : {
535+ id : 'report-so-id' ,
536+ namespace : 'default' ,
537+ type : 'scheduled-report' ,
538+ } ,
489539 reporting : mockReporting ,
490540 } ) ;
491541 } ) ;
@@ -498,19 +548,24 @@ describe('Run Scheduled Report Task', () => {
498548 } ) ;
499549 const mockTaskManager = taskManagerMock . createStart ( ) ;
500550 await task . init ( mockTaskManager , emailNotificationService ) ;
501- const runAt = new Date ( '2025-06-04T00:00:00Z' ) ;
551+ const taskInstance = {
552+ id : 'task-id' ,
553+ runAt : new Date ( '2025-06-04T00:00:00Z' ) ,
554+ params : { id : 'report-so-id' , jobtype : 'test1' } ,
555+ } ;
502556 const byteSize = 11534336 ; // 11MB
503557 const output = { content_type : 'application/pdf' } ;
504558
505559 // @ts -expect-error
506- await task . notify ( savedReport , output , runAt , byteSize , reportSO , 'default' ) ;
560+ await task . notify ( savedReport , taskInstance , output , byteSize , reportSO , 'default' ) ;
507561 expect ( emailNotificationService . notify ) . not . toHaveBeenCalled ( ) ;
508562 expect ( logger . warn ) . toHaveBeenCalledWith (
509- 'Error sending scheduled report: The report is larger than the 10MB limit.'
563+ 'Error sending notification for scheduled report: The report is larger than the 10MB limit.'
510564 ) ;
511565 expect ( reportStore . setReportWarning ) . toHaveBeenCalledWith ( savedReport , {
512566 output : { content_type : 'application/pdf' , size : 11534336 } ,
513- warning : 'Error sending scheduled report: The report is larger than the 10MB limit.' ,
567+ warning :
568+ 'Error sending notification for scheduled report: The report is larger than the 10MB limit.' ,
514569 } ) ;
515570 } ) ;
516571
@@ -522,20 +577,24 @@ describe('Run Scheduled Report Task', () => {
522577 } ) ;
523578 const mockTaskManager = taskManagerMock . createStart ( ) ;
524579 await task . init ( mockTaskManager ) ;
525- const runAt = new Date ( '2025-06-04T00:00:00Z' ) ;
580+ const taskInstance = {
581+ id : 'task-id' ,
582+ runAt : new Date ( '2025-06-04T00:00:00Z' ) ,
583+ params : { id : 'report-so-id' , jobtype : 'test1' } ,
584+ } ;
526585 const byteSize = 2097152 ; // 2MB
527586 const output = { content_type : 'application/pdf' } ;
528587
529588 // @ts -expect-error
530- await task . notify ( savedReport , output , runAt , byteSize , reportSO , 'default' ) ;
589+ await task . notify ( savedReport , taskInstance , output , byteSize , reportSO , 'default' ) ;
531590 expect ( emailNotificationService . notify ) . not . toHaveBeenCalled ( ) ;
532591 expect ( logger . warn ) . toHaveBeenCalledWith (
533- 'Error sending scheduled report: Reporting notification service has not been initialized.'
592+ 'Error sending notification for scheduled report: Reporting notification service has not been initialized.'
534593 ) ;
535594 expect ( reportStore . setReportWarning ) . toHaveBeenCalledWith ( savedReport , {
536595 output : { content_type : 'application/pdf' , size : 2097152 } ,
537596 warning :
538- 'Error sending scheduled report: Reporting notification service has not been initialized.' ,
597+ 'Error sending notification for scheduled report: Reporting notification service has not been initialized.' ,
539598 } ) ;
540599 } ) ;
541600
@@ -550,12 +609,16 @@ describe('Run Scheduled Report Task', () => {
550609 } ) ;
551610 const mockTaskManager = taskManagerMock . createStart ( ) ;
552611 await task . init ( mockTaskManager , emailNotificationService ) ;
553- const runAt = new Date ( '2025-06-04T00:00:00Z' ) ;
612+ const taskInstance = {
613+ id : 'task-id' ,
614+ runAt : new Date ( '2025-06-04T00:00:00Z' ) ,
615+ params : { id : 'report-so-id' , jobtype : 'test1' } ,
616+ } ;
554617 const byteSize = 2097152 ; // 2MB
555618 const output = { content_type : 'application/pdf' } ;
556619
557620 // @ts -expect-error
558- await task . notify ( savedReport , output , runAt , byteSize , reportSO , 'default' ) ;
621+ await task . notify ( savedReport , taskInstance , output , byteSize , reportSO , 'default' ) ;
559622 expect ( emailNotificationService . notify ) . toHaveBeenCalledWith ( {
560623 contentType : 'application/pdf' ,
561624 emailParams : {
@@ -568,14 +631,19 @@ describe('Run Scheduled Report Task', () => {
568631 id : '290357209345723095' ,
569632 index : '.reporting-fantastic' ,
570633 jobType : 'test1' ,
634+ relatedObject : {
635+ id : 'report-so-id' ,
636+ namespace : 'default' ,
637+ type : 'scheduled-report' ,
638+ } ,
571639 reporting : mockReporting ,
572640 } ) ;
573641 expect ( logger . warn ) . toHaveBeenCalledWith (
574- 'Error sending scheduled report: This is a test error!'
642+ 'Error sending notification for scheduled report: This is a test error!'
575643 ) ;
576644 expect ( reportStore . setReportWarning ) . toHaveBeenCalledWith ( savedReport , {
577645 output : { content_type : 'application/pdf' , size : 2097152 } ,
578- warning : 'Error sending scheduled report: This is a test error!' ,
646+ warning : 'Error sending notification for scheduled report: This is a test error!' ,
579647 } ) ;
580648 } ) ;
581649 } ) ;
0 commit comments