Skip to content

Commit 691fd23

Browse files
authored
fix(orchestrator): fix Tests (#587)
* fixTests Signed-off-by: Lior Soffer <liorsoffer1@gmail.com> * openapi generate files Signed-off-by: Lior Soffer <liorsoffer1@gmail.com> * run prettier Signed-off-by: Lior Soffer <liorsoffer1@gmail.com> * add changeset Signed-off-by: Lior Soffer <liorsoffer1@gmail.com> * openapi generate files Signed-off-by: Lior Soffer <liorsoffer1@gmail.com> * yarn build:api-reports Signed-off-by: Lior Soffer <liorsoffer1@gmail.com> --------- Signed-off-by: Lior Soffer <liorsoffer1@gmail.com>
1 parent 8ec549c commit 691fd23

16 files changed

Lines changed: 371 additions & 257 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator-backend': patch
3+
'@red-hat-developer-hub/backstage-plugin-orchestrator-common': patch
4+
---
5+
6+
fix tests

workspaces/orchestrator/plugins/orchestrator-backend/src/service/OrchestratorService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616

1717
import {
18+
AuthToken,
1819
Filter,
1920
ProcessInstance,
2021
ProcessInstanceVariables,
2122
WorkflowDefinition,
2223
WorkflowExecutionResponse,
2324
WorkflowInfo,
2425
WorkflowOverview,
25-
AuthToken,
2626
} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
2727

2828
import { Pagination } from '../types/pagination';

workspaces/orchestrator/plugins/orchestrator-backend/src/service/SonataFlowService.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 The Backstage Authors
2+
* Copyright Red Hat, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
import { LoggerService } from '@backstage/backend-plugin-api';
1718

1819
import { WorkflowExecutionResponse } from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
@@ -131,7 +132,7 @@ describe('SonataFlowService', () => {
131132
return {
132133
method: 'POST',
133134
body: JSON.stringify(inputData),
134-
headers: { 'content-type': 'application/json' },
135+
headers: { 'Content-Type': 'application/json' },
135136
};
136137
};
137138

@@ -185,7 +186,7 @@ describe('SonataFlowService', () => {
185186
'Execute workflow successful. Response: {"id":"workflow-123","status":"completed"}',
186187
);
187188
// Verify that all other logger methods were not called
188-
expect(loggerMock.debug).toHaveBeenCalledTimes(1);
189+
expect(loggerMock.debug).toHaveBeenCalledTimes(2);
189190
expect(loggerMock.info).not.toHaveBeenCalled();
190191
expect(loggerMock.error).not.toHaveBeenCalled();
191192
expect(loggerMock.warn).not.toHaveBeenCalled();

workspaces/orchestrator/plugins/orchestrator-backend/src/service/SonataFlowService.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { LoggerService } from '@backstage/backend-plugin-api';
1818

1919
import {
20+
AuthToken,
2021
extractWorkflowFormat,
2122
Filter,
2223
fromWorkflowSource,
@@ -27,7 +28,6 @@ import {
2728
WorkflowExecutionResponse,
2829
WorkflowInfo,
2930
WorkflowOverview,
30-
AuthToken,
3131
} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
3232

3333
import { Pagination } from '../types/pagination';
@@ -111,19 +111,19 @@ export class SonataFlowService {
111111
'Content-Type': 'application/json',
112112
};
113113

114-
// Add X-Authentication headers from authTokens
115-
if (args.authTokens && Array.isArray(args.authTokens)) {
116-
args.authTokens.forEach((tokenObj) => {
117-
if (tokenObj.provider && tokenObj.token) {
118-
const headerKey = `X-Authentication-${tokenObj.provider}`;
119-
headers[headerKey] = String(tokenObj.token); // Ensure token is a string
120-
}
114+
// Add X-Authentication headers from authTokens
115+
if (args.authTokens && Array.isArray(args.authTokens)) {
116+
args.authTokens.forEach(tokenObj => {
117+
if (tokenObj.provider && tokenObj.token) {
118+
const headerKey = `X-Authentication-${tokenObj.provider}`;
119+
headers[headerKey] = String(tokenObj.token); // Ensure token is a string
120+
}
121121
});
122-
}
123-
124-
else {
125-
this.logger.debug('No authTokens provided or authTokens is not an array.');
126-
}
122+
} else {
123+
this.logger.debug(
124+
'No authTokens provided or authTokens is not an array.',
125+
);
126+
}
127127

128128
const response = await fetch(urlToFetch, {
129129
method: 'POST',

workspaces/orchestrator/plugins/orchestrator-backend/src/service/api/v2.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ export class V2 {
177177
definitionId: workflowId,
178178
inputData:
179179
executeWorkflowRequestDTO.inputData as ProcessInstanceVariables,
180-
authTokens:
181-
executeWorkflowRequestDTO.authTokens as Array<AuthToken>,
180+
authTokens: executeWorkflowRequestDTO.authTokens as Array<AuthToken>,
182181
serviceUrl: definition.serviceUrl,
183182
businessKey,
184183
cacheHandler: 'throw',

workspaces/orchestrator/plugins/orchestrator-common/report.api.md

Lines changed: 255 additions & 232 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
51adf79657d741a8cf1777c6336f9b8aea276fd5
1+
9b9af1749d23e78871a55d78b89cb0e2462d6a3b

workspaces/orchestrator/plugins/orchestrator-common/src/generated/api/definition.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

workspaces/orchestrator/plugins/orchestrator-common/src/generated/client/api.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ export interface AssessedProcessInstanceDTO {
4242
*/
4343
'assessedBy'?: ProcessInstanceDTO;
4444
}
45+
/**
46+
*
47+
* @export
48+
* @interface AuthToken
49+
*/
50+
export interface AuthToken {
51+
/**
52+
* The auth token provider name
53+
* @type {string}
54+
* @memberof AuthToken
55+
*/
56+
'provider': string;
57+
/**
58+
* The auth token itself retrieved from the above specified provider name
59+
* @type {string}
60+
* @memberof AuthToken
61+
*/
62+
'token': string;
63+
}
4564
/**
4665
* The ErrorResponse object represents a common structure for handling errors in API responses. It includes essential information about the error, such as the error message and additional optional details.
4766
* @export
@@ -73,6 +92,12 @@ export interface ExecuteWorkflowRequestDTO {
7392
* @memberof ExecuteWorkflowRequestDTO
7493
*/
7594
'inputData'?: object;
95+
/**
96+
*
97+
* @type {Array<AuthToken>}
98+
* @memberof ExecuteWorkflowRequestDTO
99+
*/
100+
'authTokens'?: Array<AuthToken>;
76101
}
77102
/**
78103
*

workspaces/orchestrator/plugins/orchestrator-common/src/generated/docs/api-doc/orchestrator-api.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,25 @@ spec:
587587
inputData:
588588
type: object
589589
additionalProperties: true
590+
authTokens:
591+
type: array
592+
items:
593+
$ref: '#/components/schemas/AuthToken'
594+
minItems: 1
595+
additionalProperties: true
596+
AuthToken:
597+
type: object
598+
properties:
599+
provider:
600+
description: The auth token provider name
601+
type: string
602+
token:
603+
description: The auth token itself retrieved from the above specified provider name
604+
type: string
605+
required:
606+
- provider
607+
- token
608+
additionalProperties: false
590609
ExecuteWorkflowResponseDTO:
591610
type: object
592611
properties:

0 commit comments

Comments
 (0)