@@ -52,13 +52,15 @@ const workflowOverview = createWorkflowOverviewMock(1);
52
52
const workflowOverviews = createWorkflowOverviewsMock ( 3 ) ;
53
53
const instance = createInstanceMock ( 1 ) ;
54
54
const instances = createInstancesMock ( 3 ) ;
55
+ const serviceUrl = 'http://localhost' ;
56
+ const inputData = { foo : 'bar' } ;
55
57
56
58
// Mocked dependencies
57
59
const sonataFlowServiceMock = { } as SonataFlowService ;
58
60
const workflowCacheServiceMock = { } as WorkflowCacheService ;
59
61
const dataIndexServiceMock = { } as DataIndexService ;
60
62
61
- // Target service
63
+ // Target
62
64
const orchestratorService = new OrchestratorService (
63
65
sonataFlowServiceMock ,
64
66
dataIndexServiceMock ,
@@ -87,10 +89,8 @@ describe('OrchestratorService', () => {
87
89
88
90
expect (
89
91
dataIndexServiceMock . fetchDefinitionIdByInstanceId ,
90
- ) . toHaveBeenCalledWith ( instanceId ) ;
91
- expect ( dataIndexServiceMock . abortWorkflowInstance ) . toHaveBeenCalledWith (
92
- instanceId ,
93
- ) ;
92
+ ) . toHaveBeenCalled ( ) ;
93
+ expect ( dataIndexServiceMock . abortWorkflowInstance ) . toHaveBeenCalled ( ) ;
94
94
} ) ;
95
95
96
96
it ( 'should skip and not execute the operation when the workflow is not available' , async ( ) => {
@@ -106,7 +106,7 @@ describe('OrchestratorService', () => {
106
106
107
107
expect (
108
108
dataIndexServiceMock . fetchDefinitionIdByInstanceId ,
109
- ) . toHaveBeenCalledWith ( instanceId ) ;
109
+ ) . toHaveBeenCalled ( ) ;
110
110
expect ( dataIndexServiceMock . abortWorkflowInstance ) . not . toHaveBeenCalled ( ) ;
111
111
} ) ;
112
112
@@ -129,11 +129,8 @@ describe('OrchestratorService', () => {
129
129
130
130
expect (
131
131
dataIndexServiceMock . fetchDefinitionIdByInstanceId ,
132
- ) . toHaveBeenCalledWith ( instanceId ) ;
133
- expect ( workflowCacheServiceMock . isAvailable ) . toHaveBeenCalledWith (
134
- definitionId ,
135
- 'throw' ,
136
- ) ;
132
+ ) . toHaveBeenCalled ( ) ;
133
+ expect ( workflowCacheServiceMock . isAvailable ) . toHaveBeenCalled ( ) ;
137
134
expect ( dataIndexServiceMock . abortWorkflowInstance ) . not . toHaveBeenCalled ( ) ;
138
135
} ) ;
139
136
} ) ;
@@ -433,7 +430,6 @@ describe('OrchestratorService', () => {
433
430
} ) ;
434
431
435
432
describe ( 'fetchWorkflowInfoOnService' , ( ) => {
436
- const serviceUrl = 'http://localhost' ;
437
433
beforeEach ( ( ) => {
438
434
jest . clearAllMocks ( ) ;
439
435
} ) ;
@@ -602,8 +598,6 @@ describe('OrchestratorService', () => {
602
598
} ) ;
603
599
604
600
describe ( 'executeWorkflow' , ( ) => {
605
- const serviceUrl = 'http://localhost' ;
606
- const inputData = { } ;
607
601
const executeResponse : WorkflowExecutionResponse = {
608
602
id : createInstanceIdMock ( 1 ) ,
609
603
} ;
@@ -661,4 +655,129 @@ describe('OrchestratorService', () => {
661
655
expect ( sonataFlowServiceMock . executeWorkflow ) . not . toHaveBeenCalled ( ) ;
662
656
} ) ;
663
657
} ) ;
658
+
659
+ describe ( 'retriggerInstanceInError' , ( ) => {
660
+ beforeEach ( ( ) => {
661
+ jest . clearAllMocks ( ) ;
662
+ } ) ;
663
+
664
+ it ( 'should execute the operation when the workflow is available' , async ( ) => {
665
+ workflowCacheServiceMock . isAvailable = jest . fn ( ) . mockReturnValue ( true ) ;
666
+ sonataFlowServiceMock . retriggerInstanceInError = jest
667
+ . fn ( )
668
+ . mockResolvedValue ( true ) ;
669
+
670
+ await orchestratorService . retriggerInstanceInError ( {
671
+ definitionId,
672
+ serviceUrl,
673
+ instanceId,
674
+ cacheHandler : 'skip' ,
675
+ } ) ;
676
+
677
+ expect ( workflowCacheServiceMock . isAvailable ) . toHaveBeenCalled ( ) ;
678
+ expect ( sonataFlowServiceMock . retriggerInstanceInError ) . toHaveBeenCalled ( ) ;
679
+ } ) ;
680
+
681
+ it ( 'should skip and not execute the operation when the workflow is not available' , async ( ) => {
682
+ workflowCacheServiceMock . isAvailable = jest . fn ( ) . mockReturnValue ( false ) ;
683
+
684
+ await orchestratorService . retriggerInstanceInError ( {
685
+ definitionId,
686
+ serviceUrl,
687
+ instanceId,
688
+ cacheHandler : 'skip' ,
689
+ } ) ;
690
+
691
+ expect ( workflowCacheServiceMock . isAvailable ) . toHaveBeenCalled ( ) ;
692
+ expect (
693
+ sonataFlowServiceMock . retriggerInstanceInError ,
694
+ ) . not . toHaveBeenCalled ( ) ;
695
+ } ) ;
696
+
697
+ it ( 'should throw an error and not execute the operation when the workflow is not available' , async ( ) => {
698
+ workflowCacheServiceMock . isAvailable = jest
699
+ . fn ( )
700
+ . mockImplementation ( ( ) => {
701
+ throw new Error ( ) ;
702
+ } ) ;
703
+
704
+ const promise = orchestratorService . retriggerInstanceInError ( {
705
+ definitionId,
706
+ serviceUrl,
707
+ instanceId,
708
+ cacheHandler : 'throw' ,
709
+ } ) ;
710
+
711
+ await expect ( promise ) . rejects . toThrow ( ) ;
712
+
713
+ expect ( workflowCacheServiceMock . isAvailable ) . toHaveBeenCalled ( ) ;
714
+ expect (
715
+ sonataFlowServiceMock . retriggerInstanceInError ,
716
+ ) . not . toHaveBeenCalled ( ) ;
717
+ } ) ;
718
+ } ) ;
719
+
720
+ describe ( 'updateInstanceInputData' , ( ) => {
721
+ beforeEach ( ( ) => {
722
+ jest . clearAllMocks ( ) ;
723
+ } ) ;
724
+
725
+ it ( 'should execute the operation when the workflow is available' , async ( ) => {
726
+ workflowCacheServiceMock . isAvailable = jest . fn ( ) . mockReturnValue ( true ) ;
727
+ sonataFlowServiceMock . updateInstanceInputData = jest
728
+ . fn ( )
729
+ . mockResolvedValue ( true ) ;
730
+
731
+ await orchestratorService . updateInstanceInputData ( {
732
+ definitionId,
733
+ serviceUrl,
734
+ instanceId,
735
+ inputData,
736
+ cacheHandler : 'skip' ,
737
+ } ) ;
738
+
739
+ expect ( workflowCacheServiceMock . isAvailable ) . toHaveBeenCalled ( ) ;
740
+ expect ( sonataFlowServiceMock . updateInstanceInputData ) . toHaveBeenCalled ( ) ;
741
+ } ) ;
742
+
743
+ it ( 'should skip and not execute the operation when the workflow is not available' , async ( ) => {
744
+ workflowCacheServiceMock . isAvailable = jest . fn ( ) . mockReturnValue ( false ) ;
745
+
746
+ await orchestratorService . updateInstanceInputData ( {
747
+ definitionId,
748
+ serviceUrl,
749
+ instanceId,
750
+ inputData,
751
+ cacheHandler : 'skip' ,
752
+ } ) ;
753
+
754
+ expect ( workflowCacheServiceMock . isAvailable ) . toHaveBeenCalled ( ) ;
755
+ expect (
756
+ sonataFlowServiceMock . updateInstanceInputData ,
757
+ ) . not . toHaveBeenCalled ( ) ;
758
+ } ) ;
759
+
760
+ it ( 'should throw an error and not execute the operation when the workflow is not available' , async ( ) => {
761
+ workflowCacheServiceMock . isAvailable = jest
762
+ . fn ( )
763
+ . mockImplementation ( ( ) => {
764
+ throw new Error ( ) ;
765
+ } ) ;
766
+
767
+ const promise = orchestratorService . updateInstanceInputData ( {
768
+ definitionId,
769
+ serviceUrl,
770
+ instanceId,
771
+ inputData,
772
+ cacheHandler : 'throw' ,
773
+ } ) ;
774
+
775
+ await expect ( promise ) . rejects . toThrow ( ) ;
776
+
777
+ expect ( workflowCacheServiceMock . isAvailable ) . toHaveBeenCalled ( ) ;
778
+ expect (
779
+ sonataFlowServiceMock . updateInstanceInputData ,
780
+ ) . not . toHaveBeenCalled ( ) ;
781
+ } ) ;
782
+ } ) ;
664
783
} ) ;
0 commit comments