Skip to content

Commit

Permalink
chore: renaming after pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CristiCanizales committed Jan 2, 2025
1 parent 394326d commit 2a1dcb0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -39,23 +39,27 @@ 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'));
}

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApexClassOASEligibleResponse | undefined> => {
Expand Down
6 changes: 3 additions & 3 deletions packages/salesforcedx-vscode-apex/src/messages/i18n.ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
6 changes: 3 additions & 3 deletions packages/salesforcedx-vscode-apex/src/messages/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
});

Expand All @@ -57,15 +57,15 @@ 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.'
);
});

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.'
);
});
Expand All @@ -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]);
});
});
Expand Down

0 comments on commit 2a1dcb0

Please sign in to comment.