|
1 | 1 | /*
|
2 |
| - * Copyright 2024 The Backstage Authors |
| 2 | + * Copyright Red Hat, Inc. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
| 16 | + |
16 | 17 | import {
|
17 | 18 | ProcessInstance,
|
18 | 19 | WorkflowDefinition,
|
@@ -88,64 +89,56 @@ describe('OrchestratorService', () => {
|
88 | 89 | });
|
89 | 90 |
|
90 | 91 | it('should execute the operation when the workflow is available', async () => {
|
91 |
| - dataIndexServiceMock.fetchDefinitionIdByInstanceId = jest |
92 |
| - .fn() |
93 |
| - .mockResolvedValue(definitionId); |
94 | 92 | workflowCacheServiceMock.isAvailable = jest.fn().mockReturnValue(true);
|
95 |
| - dataIndexServiceMock.abortWorkflowInstance = jest.fn( |
96 |
| - (_instanceId: string) => Promise.resolve(), |
| 93 | + sonataFlowServiceMock.abortInstance = jest.fn( |
| 94 | + (_args: { |
| 95 | + definitionId: string; |
| 96 | + instanceId: string; |
| 97 | + serviceUrl: string; |
| 98 | + }) => Promise.resolve(), |
97 | 99 | );
|
98 | 100 |
|
99 | 101 | await orchestratorService.abortWorkflowInstance({
|
| 102 | + definitionId, |
100 | 103 | instanceId,
|
| 104 | + serviceUrl, |
101 | 105 | cacheHandler: 'skip',
|
102 | 106 | });
|
103 | 107 |
|
104 |
| - expect( |
105 |
| - dataIndexServiceMock.fetchDefinitionIdByInstanceId, |
106 |
| - ).toHaveBeenCalled(); |
107 |
| - expect(dataIndexServiceMock.abortWorkflowInstance).toHaveBeenCalled(); |
| 108 | + expect(sonataFlowServiceMock.abortInstance).toHaveBeenCalled(); |
108 | 109 | });
|
109 | 110 |
|
110 | 111 | it('should skip and not execute the operation when the workflow is not available', async () => {
|
111 |
| - dataIndexServiceMock.fetchDefinitionIdByInstanceId = jest |
112 |
| - .fn() |
113 |
| - .mockResolvedValue(definitionId); |
114 | 112 | workflowCacheServiceMock.isAvailable = jest.fn().mockReturnValue(false);
|
115 | 113 |
|
116 | 114 | await orchestratorService.abortWorkflowInstance({
|
| 115 | + definitionId, |
117 | 116 | instanceId,
|
| 117 | + serviceUrl, |
118 | 118 | cacheHandler: 'skip',
|
119 | 119 | });
|
120 | 120 |
|
121 |
| - expect( |
122 |
| - dataIndexServiceMock.fetchDefinitionIdByInstanceId, |
123 |
| - ).toHaveBeenCalled(); |
124 |
| - expect(dataIndexServiceMock.abortWorkflowInstance).not.toHaveBeenCalled(); |
| 121 | + expect(sonataFlowServiceMock.abortInstance).not.toHaveBeenCalled(); |
125 | 122 | });
|
126 | 123 |
|
127 | 124 | it('should throw an error and not execute the operation when the workflow is not available', async () => {
|
128 |
| - dataIndexServiceMock.fetchDefinitionIdByInstanceId = jest |
129 |
| - .fn() |
130 |
| - .mockResolvedValue(definitionId); |
131 | 125 | workflowCacheServiceMock.isAvailable = jest
|
132 | 126 | .fn()
|
133 | 127 | .mockImplementation(() => {
|
134 | 128 | throw new Error();
|
135 | 129 | });
|
136 | 130 |
|
137 | 131 | const promise = orchestratorService.abortWorkflowInstance({
|
| 132 | + definitionId, |
138 | 133 | instanceId,
|
| 134 | + serviceUrl, |
139 | 135 | cacheHandler: 'throw',
|
140 | 136 | });
|
141 | 137 |
|
142 | 138 | await expect(promise).rejects.toThrow();
|
143 | 139 |
|
144 |
| - expect( |
145 |
| - dataIndexServiceMock.fetchDefinitionIdByInstanceId, |
146 |
| - ).toHaveBeenCalled(); |
147 | 140 | expect(workflowCacheServiceMock.isAvailable).toHaveBeenCalled();
|
148 |
| - expect(dataIndexServiceMock.abortWorkflowInstance).not.toHaveBeenCalled(); |
| 141 | + expect(sonataFlowServiceMock.abortInstance).not.toHaveBeenCalled(); |
149 | 142 | });
|
150 | 143 | });
|
151 | 144 |
|
|
0 commit comments