Skip to content

Commit 2519710

Browse files
authored
Merge pull request #588 from salesforcecli/mdonnalley/refactor-tests
refactor: use best practices
2 parents 7927f49 + c9d018e commit 2519710

17 files changed

+410
-1114
lines changed

CHANGELOG.md

Lines changed: 106 additions & 340 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,4 @@
228228
"output": []
229229
}
230230
}
231-
}
231+
}

src/commands/force/org/clone.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from '@salesforce/sf-plugins-core';
1616
import {
1717
SfError,
18-
Config,
1918
Lifecycle,
2019
Messages,
2120
OrgTypes,
@@ -79,9 +78,11 @@ export class OrgCloneCommand extends SfCommand<SandboxProcessObject> {
7978
loglevel,
8079
};
8180

81+
private logger!: Logger;
82+
8283
public async run(): Promise<SandboxProcessObject> {
8384
const { flags, args, argv } = await this.parse(OrgCloneCommand);
84-
const logger = await Logger.child(this.constructor.name);
85+
this.logger = await Logger.child(this.constructor.name);
8586
const varargs = parseVarArgs(args, argv as string[]);
8687

8788
const lifecycle = Lifecycle.getInstance();
@@ -105,24 +106,19 @@ export class OrgCloneCommand extends SfCommand<SandboxProcessObject> {
105106
});
106107

107108
if (results?.sandboxRes?.authUserName) {
108-
if (flags.setalias) {
109-
const stateAggregator = await StateAggregator.getInstance();
110-
stateAggregator.aliases.set(flags.setalias, results.sandboxRes.authUserName);
111-
const result = stateAggregator.aliases.getAll();
112-
logger.debug('Set Alias: %s result: %s', flags.setalias, result);
113-
}
114-
if (flags.setdefaultusername) {
115-
const globalConfig: Config = this.configAggregator.getGlobalConfig();
116-
globalConfig.set(OrgConfigProperties.TARGET_ORG, results.sandboxRes.authUserName);
117-
const result = await globalConfig.write();
118-
logger.debug('Set defaultUsername: %s result: %s', flags.setdefaultusername, result);
119-
}
109+
if (flags.setalias) await this.setAlias(flags.setalias, results.sandboxRes.authUserName);
110+
if (flags.setdefaultusername) await this.setDefaultUsername(results.sandboxRes.authUserName);
120111
}
121112
});
122113

123-
const { sandboxReq, srcSandboxName } = await createSandboxRequest(true, flags.definitionfile, logger, varargs);
114+
const { sandboxReq, srcSandboxName } = await createSandboxRequest(
115+
true,
116+
flags.definitionfile,
117+
this.logger,
118+
varargs
119+
);
124120

125-
logger.debug('Calling clone with SandboxRequest: %s and SandboxName: %s ', sandboxReq, srcSandboxName);
121+
this.logger.debug('Calling clone with SandboxRequest: %s and SandboxName: %s ', sandboxReq, srcSandboxName);
126122
flags['target-org'].getConnection(flags['api-version']);
127123
return flags['target-org'].cloneSandbox(sandboxReq, srcSandboxName, { wait: flags.wait });
128124
} else {
@@ -132,4 +128,18 @@ export class OrgCloneCommand extends SfCommand<SandboxProcessObject> {
132128
);
133129
}
134130
}
131+
132+
public async setAlias(alias: string, username: string): Promise<void> {
133+
const stateAggregator = await StateAggregator.getInstance();
134+
stateAggregator.aliases.set(alias, username);
135+
const result = stateAggregator.aliases.getAll();
136+
this.logger.debug('Set Alias: %s result: %s', alias, result);
137+
}
138+
139+
public async setDefaultUsername(username: string): Promise<void> {
140+
const globalConfig = this.configAggregator.getGlobalConfig();
141+
globalConfig.set(OrgConfigProperties.TARGET_ORG, username);
142+
const result = await globalConfig.write();
143+
this.logger.debug('Set defaultUsername: %s result: %s', username, result);
144+
}
135145
}

src/commands/force/org/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class Create extends SfCommand<CreateResult> {
214214
try {
215215
return await this.flags['target-org'].createSandbox(sandboxReq, { wait });
216216
} catch (e) {
217-
// guaranteed to be SfdxError from core;
217+
// guaranteed to be SfError from core;
218218
const err = e as SfError;
219219
if (err?.message.includes('The org cannot be found')) {
220220
// there was most likely an issue with DNS when auth'ing to the new sandbox, but it was created.

src/commands/org/display.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,12 @@ export class OrgDisplayCommand extends SfCommand<OrgDisplayReturn> {
8080
alias: await getAliasByUsername(fields.username),
8181
};
8282
this.warn(sharedMessages.getMessage('SecurityWarning'));
83-
84-
if (!flags.json) {
85-
this.print(returnValue);
86-
}
83+
this.print(returnValue);
8784
return returnValue;
8885
}
8986

9087
private print(result: OrgDisplayReturn): void {
91-
this.log('');
88+
this.log();
9289
const tableRows = Object.entries(result)
9390
.filter(([, value]) => value !== undefined && value !== null) // some values won't exist
9491
.sort() // this command always alphabetizes the table rows

test/unit/createSandbox.test.ts

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)