Skip to content

Commit 4a6492e

Browse files
authored
Refactor benchmark wizard (#2183)
Part of OPS-4044.
1 parent 13e5784 commit 4a6492e

17 files changed

Lines changed: 50 additions & 54 deletions

packages/server/api/src/app/benchmark/common-resolvers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { AppConnectionStatus, BenchmarkWizardOption } from '@openops/shared';
1+
import {
2+
AppConnectionStatus,
3+
BenchmarkWizardOption,
4+
WizardContext,
5+
} from '@openops/shared';
26
import { appConnectionService } from '../app-connection/app-connection-service/app-connection-service';
37
import { getAuthProviderMetadata } from '../app-connection/connection-providers-resolver';
48
import { throwValidationError } from './errors';
5-
import type { WizardContext } from './provider-adapter';
69

710
export async function getAuthProviderLogoUrl(
811
authProviderKey: string,

packages/server/api/src/app/benchmark/providers/aws/aws-condition-resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { WizardContext } from '@openops/shared';
12
import { throwValidationError } from '../../errors';
2-
import type { WizardContext } from '../../provider-adapter';
33
import { getConnectionAccounts } from './aws-option-resolver';
44

55
export async function evaluateCondition(

packages/server/api/src/app/benchmark/providers/aws/aws-option-resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import {
33
BenchmarkWizardOption,
44
CustomAuthConnectionValue,
55
REGION_IMAGE_LOGO_URL,
6+
WizardContext,
67
} from '@openops/shared';
78
import { appConnectionService } from '../../../app-connection/app-connection-service/app-connection-service';
89
import {
910
getAuthProviderLogoUrl,
1011
listConnections,
1112
} from '../../common-resolvers';
1213
import { throwValidationError } from '../../errors';
13-
import type { WizardContext } from '../../provider-adapter';
1414

1515
type AwsAuthProps = {
1616
roles?: Array<{ assumeRoleArn: string; accountName: string }>;

packages/server/api/src/app/benchmark/providers/aws/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ProviderAdapter, WizardConfig } from '../../provider-adapter';
1+
import type { ProviderAdapter, WizardConfig } from '@openops/shared';
22
import { evaluateCondition } from './aws-condition-resolver';
33
import { resolveOptions } from './aws-option-resolver';
44
import awsConfig from './aws.json';

packages/server/api/src/app/benchmark/providers/azure/azure-option-resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import {
88
BenchmarkWizardOption,
99
CustomAuthConnectionValue,
1010
REGION_IMAGE_LOGO_URL,
11+
WizardContext,
1112
} from '@openops/shared';
1213
import { appConnectionService } from '../../../app-connection/app-connection-service/app-connection-service';
1314
import {
1415
getAuthProviderLogoUrl,
1516
listConnections,
1617
} from '../../common-resolvers';
1718
import { throwValidationError } from '../../errors';
18-
import type { WizardContext } from '../../provider-adapter';
1919

2020
export async function resolveOptions(
2121
method: string,

packages/server/api/src/app/benchmark/providers/azure/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ProviderAdapter, WizardConfig } from '../../provider-adapter';
1+
import type { ProviderAdapter, WizardConfig } from '@openops/shared';
22
import { resolveOptions } from './azure-option-resolver';
33
import azureConfig from './azure.json';
44

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { BenchmarkProviders, ProviderAdapter } from '@openops/shared';
2+
import { throwValidationError } from '../errors';
3+
import { awsProviderAdapter } from './aws';
4+
import { azureProviderAdapter } from './azure';
5+
6+
const providers = new Map<string, ProviderAdapter>();
7+
8+
export function getProvider(provider: string): ProviderAdapter {
9+
const adapter = providers.get(provider);
10+
11+
if (!adapter) {
12+
throwValidationError(`Provider not found: ${provider}`);
13+
}
14+
15+
return adapter;
16+
}
17+
18+
function registerProviders(): void {
19+
providers.set(BenchmarkProviders.AWS, awsProviderAdapter);
20+
providers.set(BenchmarkProviders.AZURE, azureProviderAdapter);
21+
}
22+
23+
registerProviders();

packages/server/api/src/app/benchmark/register-providers.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/server/api/src/app/benchmark/wizard.service.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ import {
22
BenchmarkWizardOption,
33
BenchmarkWizardRequest,
44
BenchmarkWizardStepResponse,
5+
ProviderAdapter,
6+
StaticOptionValue,
7+
WizardConfig,
8+
WizardConfigStep,
9+
WizardContext,
510
} from '@openops/shared';
611
import { throwValidationError } from './errors';
7-
import {
8-
getProvider,
9-
type ProviderAdapter,
10-
type StaticOptionValue,
11-
type WizardConfig,
12-
type WizardConfigStep,
13-
type WizardContext,
14-
} from './provider-adapter';
15-
import './register-providers';
12+
import { getProvider } from './providers/providers-registry';
1613

1714
function getStepProgress(
1815
config: WizardConfig,

packages/server/api/test/unit/benchmark/wizard.service.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import type { ProviderAdapter } from '../../../src/app/benchmark/provider-adapter';
1+
import type { ProviderAdapter } from '@openops/shared';
22
import { resolveWizardNavigation } from '../../../src/app/benchmark/wizard.service';
33

4-
jest.mock('../../../src/app/benchmark/register-providers', () => ({}));
5-
64
const mockResolveOptions = jest.fn().mockResolvedValue([]);
75
const mockEvaluateCondition = jest.fn().mockResolvedValue(true);
86

@@ -66,14 +64,15 @@ adapters.set('test', mockProviderAdapter);
6664

6765
const mockGetProvider = jest.fn((provider: string): ProviderAdapter => {
6866
const adapter = adapters.get(provider);
67+
6968
if (!adapter) {
7069
throw new Error(`Provider not found: ${provider}`);
7170
}
71+
7272
return adapter;
7373
});
7474

75-
jest.mock('../../../src/app/benchmark/provider-adapter', () => ({
76-
...jest.requireActual('../../../src/app/benchmark/provider-adapter'),
75+
jest.mock('../../../src/app/benchmark/providers/providers-registry', () => ({
7776
getProvider: (p: string): ProviderAdapter => mockGetProvider(p),
7877
}));
7978

0 commit comments

Comments
 (0)