Skip to content

Commit df7e195

Browse files
chore: added only related fix
1 parent 939d599 commit df7e195

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
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 flags 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 flags 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
@@ -84,6 +84,13 @@ export default class Assess extends OmniStudioBaseCommand {
8484
// To-Do: Add LWC to valid options when GA is released
8585
const validOptions = [Constants.Apex, Constants.ExpSites, Constants.FlexiPage, Constants.LWC];
8686
const apiVersion = conn.getApiVersion();
87+
88+
// Validate that --only and --relatedobjects flags are not used together
89+
if (assessOnly && relatedObjects) {
90+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
91+
process.exit(1);
92+
}
93+
8794
const orgs: OmnistudioOrgDetails = await OrgUtils.getOrgDetails(conn);
8895

8996
// 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
@@ -100,6 +100,12 @@ export default class Migrate extends OmniStudioBaseCommand {
100100
const conn = this.org.getConnection();
101101
const apiVersion = conn.getApiVersion();
102102

103+
// Validate that --only and --relatedobjects flags are not used together
104+
if (migrateOnly && relatedObjects) {
105+
Logger.error(messages.getMessage('relatedFlagsNotSupportedWithOnly'));
106+
process.exit(1);
107+
}
108+
103109
const orgs: OmnistudioOrgDetails = await OrgUtils.getOrgDetails(conn);
104110

105111
// Initialize global data model service
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+
});

0 commit comments

Comments
 (0)