Skip to content

Commit 953856e

Browse files
Merge pull request #456 from sf-aastha-paruthi/u/aparuthi/relatedflagandonlyflag
@W-20471492 Execution should be stopped - If the assessment command is run with related objects with only single components
2 parents 4596bfd + f1bfd7e commit 953856e

File tree

8 files changed

+169
-4
lines changed

8 files changed

+169
-4
lines changed

messages/assess.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"noPackageInstalled": "No valid package found in your org.",
3434
"alreadyStandardModel": "Your org already uses the standard data model.",
3535
"invalidRelatedObjectsOption": "Invalid entry for -r: %s. Enter either apex, lwc, flexipage or expsites.",
36+
"relatedFlagsNotSupportedWithOnly": "Related objects [ex: Apex, lwc, expsites and flexipages] are not supported with only flag.",
3637
"formulaSyntaxError": "We couldn't update the syntax of this formula. Verify the syntax and try again: %s",
3738
"errorDuringFlexCardAssessment": "We've encountered errors during the Flexcard assessment: %s",
3839
"errorDuringOmniScriptAssessment": "We've encountered errors during the Omniscript assessment: %s",

messages/migrate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"unknownNamespace": "A valid namespace is not configured in this org. Configure the namespace and try again",
3636
"noOmniStudioLicenses": "OmniStudio licenses are not found in the org. OmniStudio licenses are required for migration",
3737
"invalidRelatedObjectsOption": "Invalid option provided for -r: %s. Valid options are apex, lwc, expsites, flexipage.",
38+
"relatedFlagsNotSupportedWithOnly": "Related objects [ex: Apex, lwc, expsites and flexipages] are not supported with only flag.",
3839
"userConsentMessage": "By proceeding further, you hereby consent to accept changes to your custom code, and the accompanying terms and conditions associated with the use of the Omnistudio Migration Tool. Do you want to proceed? [y/n]",
3940
"existingApexPrompt": "Do you have a sfdc project that already contains the related objects retrieved from your org? [y/n]",
4041
"enterExistingProjectPath": "Enter the path to the project folder that contains the retrieved APEX classes",

src/commands/omnistudio/migration/assess.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ export default class Assess extends SfCommand<AssessmentInfo> {
115115
// To-Do: Add LWC to valid options when GA is released
116116
const validOptions = [Constants.Apex, Constants.ExpSites, Constants.FlexiPage, Constants.LWC];
117117
const apiVersion = conn.getApiVersion();
118+
119+
// Validate that --only and --relatedobjects flags are not used together
120+
if (assessOnly && relatedObjects) {
121+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
122+
process.exit(1);
123+
}
124+
118125
const orgs: OmnistudioOrgDetails = await OrgUtils.getOrgDetails(conn);
119126

120127
// Initialize global data model service

src/commands/omnistudio/migration/migrate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ export default class Migrate extends SfCommand<MigrateResult> {
130130
const conn = org.getConnection();
131131
const apiVersion = conn.getApiVersion();
132132

133+
// Validate that --only and --relatedobjects flags are not used together
134+
if (migrateOnly && relatedObjects) {
135+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
136+
process.exit(1);
137+
}
138+
133139
const orgs: OmnistudioOrgDetails = await OrgUtils.getOrgDetails(conn);
134140

135141
// Initialize global data model service

src/migration/dataraptor.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,6 @@ export class DataRaptorMigrationTool extends BaseMigrationTool implements Migrat
296296
public async assess(): Promise<DataRaptorAssessmentInfo[]> {
297297
try {
298298
if (isStandardDataModelWithMetadataAPIEnabled()) {
299-
Logger.log(
300-
this.messages.getMessage('skippingAssessmentForStandardOrgWithMetadataAPIEnabled', [Constants.DataMapper])
301-
);
302299
return [];
303300
}
304301
DebugTimer.getInstance().lap('Query data raptors');
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
3+
import { Messages } from '@salesforce/core';
4+
import { Logger } from '../../../../src/utils/logger';
5+
6+
Messages.importMessagesDirectory(__dirname);
7+
const messages = Messages.loadMessages('@salesforce/plugin-omnistudio-migration-tool', 'assess');
8+
9+
describe('Assess command flags validation', () => {
10+
let loggerErrorStub: sinon.SinonStub;
11+
let processExitStub: sinon.SinonStub;
12+
13+
beforeEach(() => {
14+
loggerErrorStub = sinon.stub(Logger, 'error');
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
processExitStub = sinon.stub(process, 'exit' as any);
17+
});
18+
19+
afterEach(() => {
20+
loggerErrorStub.restore();
21+
processExitStub.restore();
22+
});
23+
24+
it('should validate that --only and --relatedobjects flags cannot be used together', () => {
25+
// Simulate the validation logic
26+
const assessOnly = 'os';
27+
const relatedObjects = 'lwc';
28+
29+
if (assessOnly && relatedObjects) {
30+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
31+
process.exit(1);
32+
}
33+
34+
expect(loggerErrorStub.calledOnce).to.be.true;
35+
expect(loggerErrorStub.firstCall.args[0]).to.equal('Related flags are not supported with only flag.');
36+
expect(processExitStub.calledWith(1)).to.be.true;
37+
});
38+
39+
it('should allow --only flag without --relatedobjects', () => {
40+
const assessOnly = 'os';
41+
const relatedObjects = '';
42+
43+
if (assessOnly && relatedObjects) {
44+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
45+
process.exit(1);
46+
}
47+
48+
expect(loggerErrorStub.called).to.be.false;
49+
expect(processExitStub.called).to.be.false;
50+
});
51+
52+
it('should allow --relatedobjects flag without --only', () => {
53+
const assessOnly = '';
54+
const relatedObjects = 'lwc';
55+
56+
if (assessOnly && relatedObjects) {
57+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
58+
process.exit(1);
59+
}
60+
61+
expect(loggerErrorStub.called).to.be.false;
62+
expect(processExitStub.called).to.be.false;
63+
});
64+
65+
it('should allow neither flag to be set', () => {
66+
const assessOnly = '';
67+
const relatedObjects = '';
68+
69+
if (assessOnly && relatedObjects) {
70+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
71+
process.exit(1);
72+
}
73+
74+
expect(loggerErrorStub.called).to.be.false;
75+
expect(processExitStub.called).to.be.false;
76+
});
77+
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
3+
import { Messages } from '@salesforce/core';
4+
import { Logger } from '../../../../src/utils/logger';
5+
6+
Messages.importMessagesDirectory(__dirname);
7+
const messages = Messages.loadMessages('@salesforce/plugin-omnistudio-migration-tool', 'migrate');
8+
9+
describe('Migrate command flags validation', () => {
10+
let loggerErrorStub: sinon.SinonStub;
11+
let processExitStub: sinon.SinonStub;
12+
13+
beforeEach(() => {
14+
loggerErrorStub = sinon.stub(Logger, 'error');
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
processExitStub = sinon.stub(process, 'exit' as any);
17+
});
18+
19+
afterEach(() => {
20+
loggerErrorStub.restore();
21+
processExitStub.restore();
22+
});
23+
24+
it('should validate that --only and --relatedobjects flags cannot be used together', () => {
25+
// Simulate the validation logic
26+
const migrateOnly = 'os';
27+
const relatedObjects = 'lwc';
28+
29+
if (migrateOnly && relatedObjects) {
30+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
31+
process.exit(1);
32+
}
33+
34+
expect(loggerErrorStub.calledOnce).to.be.true;
35+
expect(loggerErrorStub.firstCall.args[0]).to.equal('Related flags are not supported with only flag.');
36+
expect(processExitStub.calledWith(1)).to.be.true;
37+
});
38+
39+
it('should allow --only flag without --relatedobjects', () => {
40+
const migrateOnly = 'os';
41+
const relatedObjects = '';
42+
43+
if (migrateOnly && relatedObjects) {
44+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
45+
process.exit(1);
46+
}
47+
48+
expect(loggerErrorStub.called).to.be.false;
49+
expect(processExitStub.called).to.be.false;
50+
});
51+
52+
it('should allow --relatedobjects flag without --only', () => {
53+
const migrateOnly = '';
54+
const relatedObjects = 'lwc';
55+
56+
if (migrateOnly && relatedObjects) {
57+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
58+
process.exit(1);
59+
}
60+
61+
expect(loggerErrorStub.called).to.be.false;
62+
expect(processExitStub.called).to.be.false;
63+
});
64+
65+
it('should allow neither flag to be set', () => {
66+
const migrateOnly = '';
67+
const relatedObjects = '';
68+
69+
if (migrateOnly && relatedObjects) {
70+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
71+
process.exit(1);
72+
}
73+
74+
expect(loggerErrorStub.called).to.be.false;
75+
expect(processExitStub.called).to.be.false;
76+
});
77+
});

test/migration/metadata-api-enabled-standard-datamodel.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe('Standard Data Model with Metadata API Enabled - Storage Preparation On
6565
foundDataRaptorsToAssess: `Found ${params?.[0]} DataRaptors to assess`,
6666
preparingStorageForMetadataEnabledOrg: `Preparing storage for ${params?.[0]} in Metadata API enabled org`,
6767
updatingStorageForOmniscipt: `Updating storage for OmniScript (${params?.[0]})`,
68-
skippingAssessmentForStandardOrgWithMetadataAPIEnabled: `Skipping ${params?.[0]} assessment for Standard org with Metadata API enabled`,
6968
unexpectedError: 'An unexpected error occurred',
7069
};
7170
return messages[key] || `Mock message for ${key}`;

0 commit comments

Comments
 (0)