Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"@oclif/core": "^4",
"@oclif/multi-stage-output": "^0.8.30",
"@oclif/table": "^0.5.1",
"@salesforce/core": "^8.24.0",
"@salesforce/core": "^8.26.3",
"@salesforce/kit": "^3.2.4",
"@salesforce/metadata-enrichment": "^0.0.6",
"@salesforce/metadata-enrichment": "^0.0.8",
"@salesforce/sf-plugins-core": "^12",
"@salesforce/source-deploy-retrieve": "^12.0.1"
},
Expand All @@ -23,7 +23,7 @@
"eslint-plugin-sf-plugin": "^1.20.33",
"oclif": "^4.22.59",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
"typescript": "^5.9.2"
},
"engines": {
"node": ">=20.0.0"
Expand Down
6 changes: 2 additions & 4 deletions src/commands/metadata/enrich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { MultiStageOutput } from '@oclif/multi-stage-output';
import { Messages, SfProject } from '@salesforce/core';
import { Flags, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ComponentSetBuilder } from '@salesforce/source-deploy-retrieve';
import { SourceComponentProcessor, EnrichmentHandler, EnrichmentMetrics, EnrichmentRecords, EnrichmentStatus, FileProcessor } from '@salesforce/metadata-enrichment';
import { SourceComponentProcessor, EnrichmentHandler, EnrichmentMetrics, EnrichmentRecords, FileProcessor } from '@salesforce/metadata-enrichment';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const commandMessages = Messages.loadMessages('@salesforce/plugin-metadata-enrichment', 'metadata.enrich');
Expand Down Expand Up @@ -74,9 +74,7 @@ export default class MetadataEnrich extends SfCommand<EnrichmentMetrics> {
metadataEntries,
project.getPath()
);
enrichmentRecords.addSkippedComponents(componentsToSkip);
enrichmentRecords.updateWithStatus(componentsToSkip, EnrichmentStatus.SKIPPED);
enrichmentRecords.generateSkipReasons(componentsToSkip, projectSourceComponents);
enrichmentRecords.addRecords(componentsToSkip);

const componentsEligibleToProcess = projectSourceComponents.filter((component) => {
const componentName = component.fullName ?? component.name;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/componentProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('ComponentProcessor', () => {
const result = SourceComponentProcessor.getComponentsToSkip(source, ['ApexClass:MyClass'], undefined);
expect(result.size).to.be.greaterThan(0);
const skipEntries = Array.from(result);
expect(skipEntries.some((r) => r.componentName === 'MyClass' && r.typeName === 'ApexClass')).to.be.true;
expect(skipEntries.some((r) => r.componentName === 'MyClass' && r.componentType.name === 'ApexClass')).to.be.true;
});

it('should include LWC without xml in skip set', () => {
Expand Down
57 changes: 17 additions & 40 deletions test/unit/enrichmentRecords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ describe('EnrichmentRecords', () => {
expect(record.requestBody).to.not.be.null;
expect(record.requestBody!.contentBundles).to.deep.equal([]);
expect(record.requestBody!.metadataType).to.equal('Generic');
expect(record.requestBody!.maxTokens).to.equal(50);
});

it('should not create record when component has no name', () => {
Expand All @@ -64,24 +63,37 @@ describe('EnrichmentRecords', () => {
});
});

describe('addSkippedComponents', () => {
describe('addRecords', () => {
it('should add SKIPPED record for component not in recordSet', () => {
const records = new EnrichmentRecords([]);
records.addSkippedComponents(new Set([{ typeName: 'LightningComponentBundle', componentName: 'SkippedCmp' }]));
records.addRecords(new Set([{
componentName: 'SkippedCmp',
componentType: { name: 'LightningComponentBundle' } as SourceComponent['type'],
requestBody: { contentBundles: [], metadataType: 'Generic' },
response: null,
message: null,
status: EnrichmentStatus.SKIPPED,
}]));
expect(records.recordSet.size).to.equal(1);
const record = Array.from(records.recordSet)[0];
expect(record.componentName).to.equal('SkippedCmp');
expect(record.status).to.equal(EnrichmentStatus.SKIPPED);
expect(record.requestBody).to.not.be.null;
expect(record.requestBody!.contentBundles).to.deep.equal([]);
expect(record.requestBody!.metadataType).to.equal('Generic');
expect(record.requestBody!.maxTokens).to.equal(50);
});

it('should not duplicate when record already exists', () => {
const source = [createSourceComponent('Existing', 'LightningComponentBundle')];
const records = new EnrichmentRecords(source);
records.addSkippedComponents(new Set([{ typeName: 'LightningComponentBundle', componentName: 'Existing' }]));
records.addRecords(new Set([{
componentName: 'Existing',
componentType: { name: 'LightningComponentBundle' } as SourceComponent['type'],
requestBody: { contentBundles: [], metadataType: 'Generic' },
response: null,
message: null,
status: EnrichmentStatus.SKIPPED,
}]));
expect(records.recordSet.size).to.equal(1);
});
});
Expand Down Expand Up @@ -189,39 +201,4 @@ describe('EnrichmentRecords', () => {
});
});

describe('generateSkipReasons', () => {
it('should set message for skipped record when component not in source', () => {
const records = new EnrichmentRecords([]);
records.addSkippedComponents(new Set([{ typeName: 'LightningComponentBundle', componentName: 'Missing' }]));
records.generateSkipReasons(new Set([{ typeName: 'LightningComponentBundle', componentName: 'Missing' }]), []);
const record = Array.from(records.recordSet)[0];
expect(record.message).to.equal('Component not found in project.');
});

it('should set LWC-only message for skipped non-LWC component', () => {
const source = [createSourceComponent('MyClass', 'ApexClass')];
const records = new EnrichmentRecords(source);
records.addSkippedComponents(new Set([{ typeName: 'ApexClass', componentName: 'MyClass' }]));
records.updateWithStatus(
new Set([{ typeName: 'ApexClass', componentName: 'MyClass' }]),
EnrichmentStatus.SKIPPED
);
records.generateSkipReasons(new Set([{ typeName: 'ApexClass', componentName: 'MyClass' }]), source);
const record = Array.from(records.recordSet)[0];
expect(record.message).to.equal('Component type \'ApexClass\' is not currently supported for enrichment.');
});

it('should set lwc.configuration.not.found for LWC without xml', () => {
const source = [createSourceComponent('NoMeta', 'LightningComponentBundle')];
const records = new EnrichmentRecords(source);
records.addSkippedComponents(new Set([{ typeName: 'LightningComponentBundle', componentName: 'NoMeta' }]));
records.updateWithStatus(
new Set([{ typeName: 'LightningComponentBundle', componentName: 'NoMeta' }]),
EnrichmentStatus.SKIPPED
);
records.generateSkipReasons(new Set([{ typeName: 'LightningComponentBundle', componentName: 'NoMeta' }]), source);
const record = Array.from(records.recordSet)[0];
expect(record.message).to.equal('The component\'s metadata configuration file doesn\'t exist.');
});
});
});
Loading