From 2a1dcb04075c7ced1088cdf6bf5b8dd05a03a70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristina=20Isabel=20Ca=C3=B1izales?= Date: Thu, 2 Jan 2025 18:57:10 -0300 Subject: [PATCH] chore: renaming after pr comments --- .../src/commands/apexActionController.ts | 20 +++++++++++-------- .../src/commands/metadataOrchestrator.ts | 4 ++-- .../src/messages/i18n.ja.ts | 6 +++--- .../src/messages/i18n.ts | 6 +++--- .../commands/metadataOrchestrator.test.ts | 10 +++++----- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/salesforcedx-vscode-apex/src/commands/apexActionController.ts b/packages/salesforcedx-vscode-apex/src/commands/apexActionController.ts index c18f181993..e4580ba210 100644 --- a/packages/salesforcedx-vscode-apex/src/commands/apexActionController.ts +++ b/packages/salesforcedx-vscode-apex/src/commands/apexActionController.ts @@ -27,7 +27,7 @@ export class ApexActionController { const command = isClass ? 'SFDX: Create Apex Action from This Class' : 'SFDX: Create Apex Action from Selected Method'; - let metadata; + let eligibilityResult; let context; let name; const telemetryService = await getTelemetryService(); @@ -39,12 +39,14 @@ export class ApexActionController { cancellable: true }, async progress => { - // Step 1: Extract Metadata - progress.report({ message: nls.localize('extract_metadata') }); - metadata = await this.metadataOrchestrator.extractMetadata(sourceUri, !isClass); - if (!metadata) { - throw new Error(nls.localize('extraction_failed', type)); + // Step 1: Validate eligibility + progress.report({ message: nls.localize('validate_eligibility') }); + eligibilityResult = await this.metadataOrchestrator.validateMetadata(sourceUri, !isClass); + if (!eligibilityResult) { + throw new Error(nls.localize('class_validation_failed', type)); } + + // Step 2: Gather context context = await this.metadataOrchestrator.gatherContext(sourceUri); if (!context) { throw new Error(nls.localize('cannot_gather_context')); @@ -52,10 +54,12 @@ export class ApexActionController { // Step 3: Generate OpenAPI Document progress.report({ message: nls.localize('generate_openapi_document') }); - const openApiDocument = await this.generateOpenAPIDocument(metadata, context); + const openApiDocument = await this.generateOpenAPIDocument(eligibilityResult, context); // Step 4: Write OpenAPI Document to File - name = isClass ? path.basename(metadata.resourceUri, '.cls') : metadata?.symbols?.[0]?.docSymbol?.name; + name = isClass + ? path.basename(eligibilityResult.resourceUri, '.cls') + : eligibilityResult?.symbols?.[0]?.docSymbol?.name; const openApiFileName = `${name}_openapi.yml`; progress.report({ message: nls.localize('write_openapi_document_to_file') }); await this.saveAndOpenDocument(openApiFileName, openApiDocument); diff --git a/packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts b/packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts index 1a74f33a9c..25ab9d1a9d 100644 --- a/packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts +++ b/packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts @@ -46,10 +46,10 @@ export interface Parameter { */ export class MetadataOrchestrator { /** - * Extracts metadata for the method at the current cursor position. + * Validates and extracts metadata for the method at the current cursor position. * @returns The metadata of the method, or undefined if no method is found. */ - public extractMetadata = async ( + public validateMetadata = async ( sourceUri: vscode.Uri | vscode.Uri[], isMethodSelected: boolean = false ): Promise => { diff --git a/packages/salesforcedx-vscode-apex/src/messages/i18n.ja.ts b/packages/salesforcedx-vscode-apex/src/messages/i18n.ja.ts index 24e2ba8294..196f902d76 100644 --- a/packages/salesforcedx-vscode-apex/src/messages/i18n.ja.ts +++ b/packages/salesforcedx-vscode-apex/src/messages/i18n.ja.ts @@ -52,9 +52,9 @@ export const messages = { apex_test_run_description_text: 'Apex テストを実行', apex_test_run_text: 'SFDX: Apex テストを呼び出す', create_apex_action_failed: 'Failed to create Apex Action', - extract_metadata: 'Extracting metadata.', - extraction_failed: 'Failed to extract metadata from %s', - validation_failed: 'Failed to validate metadata.', + validate_eligibility: 'Validating eligibility.', + class_validation_failed: 'Failed to validate eligibility from %s', + validation_failed: 'Failed to validate eligibility.', apex_class_not_valid: 'The Apex Class %s is not valid for Open AI document generation.', apex_action_created: 'Apex Action created for %s: %s.', generate_openapi_document: 'Generating OpenAPI document.', diff --git a/packages/salesforcedx-vscode-apex/src/messages/i18n.ts b/packages/salesforcedx-vscode-apex/src/messages/i18n.ts index 696329a6c9..7255951a64 100644 --- a/packages/salesforcedx-vscode-apex/src/messages/i18n.ts +++ b/packages/salesforcedx-vscode-apex/src/messages/i18n.ts @@ -55,9 +55,9 @@ export const messages = { apex_test_run_codeAction_no_method_test_param_text: 'Test method not provided. Run the code action on a method annotated with @isTest or testMethod.', create_apex_action_failed: 'Failed to create Apex Action', - extract_metadata: 'Extracting metadata.', - extraction_failed: 'Failed to extract metadata from %s', - validation_failed: 'Failed to validate metadata.', + validate_eligibility: 'Validating eligibility.', + class_validation_failed: 'Failed to validate eligibility from %s', + validation_failed: 'Failed to validate eligibility.', apex_class_not_valid: 'The Apex Class %s is not valid for Open AI document generation.', apex_action_created: 'Apex Action created for %s: %s.', generate_openapi_document: 'Generating OpenAPI document.', diff --git a/packages/salesforcedx-vscode-apex/test/jest/commands/metadataOrchestrator.test.ts b/packages/salesforcedx-vscode-apex/test/jest/commands/metadataOrchestrator.test.ts index bf43bf16ae..fa615ab0a7 100644 --- a/packages/salesforcedx-vscode-apex/test/jest/commands/metadataOrchestrator.test.ts +++ b/packages/salesforcedx-vscode-apex/test/jest/commands/metadataOrchestrator.test.ts @@ -47,8 +47,8 @@ describe('MetadataOrchestrator', () => { }); it('should throw an error if no eligible responses are returned', async () => { jest.spyOn(orchestrator, 'validateEligibility').mockResolvedValue(undefined); - await expect(orchestrator.extractMetadata(editorStub.document.uri)).rejects.toThrow( - 'Failed to validate metadata.' + await expect(orchestrator.validateMetadata(editorStub.document.uri)).rejects.toThrow( + 'Failed to validate eligibility.' ); }); @@ -57,7 +57,7 @@ describe('MetadataOrchestrator', () => { { isApexOasEligible: false, isEligible: false, symbols: [{ docSymbol: { name: 'someMethod' } }] } ]; jest.spyOn(orchestrator, 'validateEligibility').mockResolvedValue(mockResponse); - await expect(orchestrator.extractMetadata(editorStub.document.uri, true)).rejects.toThrow( + await expect(orchestrator.validateMetadata(editorStub.document.uri, true)).rejects.toThrow( 'Method someMethod is not eligible for Apex Action creation. It is not annotated with @AuraEnabled or has wrong access modifiers.' ); }); @@ -65,7 +65,7 @@ describe('MetadataOrchestrator', () => { it('should throw an error if the first eligible response is not eligible and method is not selected', async () => { const mockResponse: any = [{ isApexOasEligible: false, isEligible: false, resourceUri: '/hello/world.cls' }]; jest.spyOn(orchestrator, 'validateEligibility').mockResolvedValue(mockResponse); - await expect(orchestrator.extractMetadata(editorStub.document.uri)).rejects.toThrow( + await expect(orchestrator.validateMetadata(editorStub.document.uri)).rejects.toThrow( 'The Apex Class world is not valid for Open AI document generation.' ); }); @@ -79,7 +79,7 @@ describe('MetadataOrchestrator', () => { } ]; jest.spyOn(orchestrator, 'validateEligibility').mockResolvedValue(mockResponse); - const result = await orchestrator.extractMetadata(editorStub.document.uri); + const result = await orchestrator.validateMetadata(editorStub.document.uri); expect(result).toEqual(mockResponse[0]); }); });