Skip to content

Commit 8abe9d7

Browse files
committed
feat: use StateAggregator [sb-nuts]
1 parent 52a3437 commit 8abe9d7

File tree

11 files changed

+68
-64
lines changed

11 files changed

+68
-64
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
"bugs": "https://github.com/forcedotcom/cli/issues",
88
"dependencies": {
99
"@oclif/core": "^1.7.0",
10-
"@salesforce/command": "^5.1.3",
11-
"@salesforce/core": "^3.19.0",
10+
"@salesforce/command": "^5.2.0",
11+
"@salesforce/core": "^3.20.1",
1212
"@salesforce/kit": "^1.5.17",
1313
"open": "8.4.0",
1414
"tslib": "^2"
1515
},
1616
"devDependencies": {
1717
"@oclif/dev-cli": "^1",
1818
"@oclif/plugin-command-snapshot": "^3.1.3",
19-
"@salesforce/cli-plugins-testkit": "^1.5.3",
19+
"@salesforce/cli-plugins-testkit": "^2.2.0",
2020
"@salesforce/dev-config": "^3.0.1",
2121
"@salesforce/dev-scripts": "^2.0.2",
2222
"@salesforce/plugin-command-reference": "^1.3.0",

src/commands/force/org/beta/create.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
1111
import { Duration } from '@salesforce/kit';
1212
import {
1313
AuthFields,
14-
GlobalInfo,
14+
StateAggregator,
1515
Config,
1616
Lifecycle,
1717
Messages,
@@ -208,9 +208,9 @@ export class Create extends SfdxCommand {
208208
});
209209
if (results.sandboxRes?.authUserName) {
210210
if (this.flags.setalias) {
211-
const globalInfo = await GlobalInfo.getInstance();
212-
globalInfo.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
213-
const result = await globalInfo.write();
211+
const stateAggregator = await StateAggregator.getInstance();
212+
stateAggregator.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
213+
const result = await stateAggregator.aliases.write();
214214
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
215215
}
216216
if (this.flags.setdefaultusername) {
@@ -235,9 +235,9 @@ export class Create extends SfdxCommand {
235235
if (err?.message.includes('The org cannot be found')) {
236236
// there was most likely an issue with DNS when auth'ing to the new sandbox, but it was created.
237237
if (this.flags.setalias && this.sandboxAuth) {
238-
const globalInfo = await GlobalInfo.getInstance();
239-
globalInfo.aliases.set(this.flags.setalias, this.sandboxAuth.authUserName);
240-
const result = await globalInfo.write();
238+
const stateAggregator = await StateAggregator.getInstance();
239+
stateAggregator.aliases.set(this.flags.setalias, this.sandboxAuth.authUserName);
240+
const result = await stateAggregator.aliases.write();
241241
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
242242
}
243243
if (this.flags.setdefaultusername && this.sandboxAuth) {
@@ -262,9 +262,9 @@ export class Create extends SfdxCommand {
262262
}
263263

264264
private async setAliasAndDefaultUsername(username: string): Promise<void> {
265-
const globalInfo = await GlobalInfo.getInstance();
265+
const stateAggregator = await StateAggregator.getInstance();
266266
if (this.flags.setalias) {
267-
globalInfo.aliases.update(this.flags.setalias, username);
267+
stateAggregator.aliases.set(this.flags.setalias, username);
268268
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias);
269269
}
270270
if (this.flags.setdefaultusername) {
@@ -274,7 +274,7 @@ export class Create extends SfdxCommand {
274274
} catch {
275275
config = await Config.create({ isGlobal: true });
276276
}
277-
const value = globalInfo.aliases.get(username) || username;
277+
const value = stateAggregator.aliases.get(username) || username;
278278
const result = config.set(OrgConfigProperties.TARGET_ORG, value);
279279
await config.write();
280280
this.logger.debug('Set defaultUsername: %s result: %s', this.flags.setdefaultusername, result);

src/commands/force/org/clone.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Messages,
1616
OrgTypes,
1717
SfdxPropertyKeys,
18-
GlobalInfo,
18+
StateAggregator,
1919
SandboxEvents,
2020
SandboxRequest,
2121
StatusEvent,
@@ -89,9 +89,9 @@ export class OrgCloneCommand extends SfdxCommand {
8989

9090
if (results?.sandboxRes?.authUserName) {
9191
if (this.flags.setalias) {
92-
const globalInfo = await GlobalInfo.getInstance();
93-
globalInfo.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
94-
const result = globalInfo.aliases.getAll();
92+
const stateAggregator = await StateAggregator.getInstance();
93+
stateAggregator.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
94+
const result = stateAggregator.aliases.getAll();
9595
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
9696
}
9797
if (this.flags.setdefaultusername) {

src/commands/force/org/status.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Config,
1212
Lifecycle,
1313
Messages,
14-
GlobalInfo,
14+
StateAggregator,
1515
SandboxEvents,
1616
SfdxPropertyKeys,
1717
StatusEvent,
@@ -72,8 +72,8 @@ export class OrgStatusCommand extends SfdxCommand {
7272
});
7373
if (results.sandboxRes?.authUserName) {
7474
if (this.flags.setalias) {
75-
const info = await GlobalInfo.getInstance();
76-
info.aliases.update(this.flags.setalias, results.sandboxRes.authUserName);
75+
const stateAggregator = await StateAggregator.getInstance();
76+
stateAggregator.aliases.set(this.flags.setalias, results.sandboxRes.authUserName);
7777
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, results.sandboxRes.authUserName);
7878
}
7979
if (this.flags.setdefaultusername) {

src/shared/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import { ChildProcess } from 'child_process';
8-
import { GlobalInfo } from '@salesforce/core';
8+
import { StateAggregator } from '@salesforce/core';
99
import * as open from 'open';
1010

1111
export const getAliasByUsername = async (username: string): Promise<string> => {
12-
const globalInfo = await GlobalInfo.getInstance();
13-
const keys = globalInfo.aliases.getAll(username);
12+
const stateAggregator = await StateAggregator.getInstance();
13+
const keys = stateAggregator.aliases.getAll(username);
1414
// use the most recently added alias for that username
1515
return keys?.length ? keys[keys.length - 1] : undefined;
1616
};

test/commands/force/org/clone.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { Org, Lifecycle, GlobalInfo, SandboxEvents, SfdxConfigAggregator, SfdxPropertyKeys } from '@salesforce/core';
7+
import {
8+
Org,
9+
Lifecycle,
10+
StateAggregator,
11+
SandboxEvents,
12+
SfdxConfigAggregator,
13+
SfdxPropertyKeys,
14+
} from '@salesforce/core';
815
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
916
import * as sinon from 'sinon';
1017
import { expect } from '@salesforce/command/lib/test';
@@ -124,7 +131,7 @@ describe('org:clone', () => {
124131
on: onStub,
125132
});
126133
aliasSetStub = sinon.spy();
127-
stubMethod(sandbox, GlobalInfo, 'getInstance').returns({
134+
stubMethod(sandbox, StateAggregator, 'getInstance').returns({
128135
aliases: {
129136
set: aliasSetStub,
130137
getAll: () => ({

test/commands/force/org/sandboxCreate.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import {
8-
GlobalInfo,
8+
StateAggregator,
99
Config,
1010
Lifecycle,
1111
Messages,
@@ -271,11 +271,11 @@ describe('org:create', () => {
271271
stubMethod(sandbox, Org.prototype, 'createSandbox');
272272

273273
aliasSetStub = sinon.spy();
274-
stubMethod(sandbox, GlobalInfo, 'getInstance').returns({
274+
stubMethod(sandbox, StateAggregator, 'getInstance').returns({
275275
aliases: {
276276
set: aliasSetStub,
277+
write: sinon.stub(),
277278
},
278-
write: sinon.stub(),
279279
});
280280
const configStub = stubMethod(sandbox, Config.prototype, 'set');
281281
await command.runIt();

test/commands/force/org/scratchOrgCreate.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { Config, GlobalInfo, SfError, Messages, Org, SfProject } from '@salesforce/core';
7+
import { Config, StateAggregator, SfError, Messages, Org, SfProject } from '@salesforce/core';
88
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
99
import * as sinon from 'sinon';
1010
import { expect } from '@salesforce/command/lib/test';
@@ -46,7 +46,6 @@ describe('org:create', () => {
4646
let promptStub: sinon.SinonStub;
4747
let aliasGetStub: sinon.SinonStub;
4848
let aliasSetStub: sinon.SinonSpy;
49-
let aliasUpdateStub: sinon.SinonSpy;
5049
let cmd: TestCreate;
5150

5251
class TestCreate extends Create {
@@ -204,12 +203,10 @@ describe('org:create', () => {
204203
});
205204
aliasGetStub = sinon.stub().returns('');
206205
aliasSetStub = sinon.spy();
207-
aliasUpdateStub = sinon.spy();
208-
stubMethod(sandbox, GlobalInfo, 'getInstance').returns({
206+
stubMethod(sandbox, StateAggregator, 'getInstance').returns({
209207
aliases: {
210208
get: aliasGetStub,
211209
set: aliasSetStub,
212-
update: aliasUpdateStub,
213210
},
214211
});
215212
const configStub = stubMethod(sandbox, Config.prototype, 'set');
@@ -229,7 +226,7 @@ describe('org:create', () => {
229226
retry: 0,
230227
orgConfig: {},
231228
});
232-
expect(aliasUpdateStub.firstCall.args).to.deep.equal(['scratchOrgAlias', 'newScratchUsername']);
229+
expect(aliasSetStub.firstCall.args).to.deep.equal(['scratchOrgAlias', 'newScratchUsername']);
233230
expect(aliasGetStub.firstCall.args).to.deep.equal(['newScratchUsername']);
234231
expect(configStub.firstCall.args).to.deep.equal(['target-org', 'newScratchUsername']);
235232
});
@@ -256,11 +253,11 @@ describe('org:create', () => {
256253
});
257254

258255
aliasGetStub = sinon.stub().returns('scratchOrgAlias');
259-
aliasUpdateStub = sinon.spy();
260-
stubMethod(sandbox, GlobalInfo, 'getInstance').returns({
256+
aliasSetStub = sinon.spy();
257+
stubMethod(sandbox, StateAggregator, 'getInstance').returns({
261258
aliases: {
262259
get: aliasGetStub,
263-
update: aliasUpdateStub,
260+
set: aliasSetStub,
264261
},
265262
});
266263

@@ -281,7 +278,7 @@ describe('org:create', () => {
281278
retry: 0,
282279
orgConfig: {},
283280
});
284-
expect(aliasUpdateStub.firstCall.args).to.deep.equal(['scratchOrgAlias', 'newScratchUsername']);
281+
expect(aliasSetStub.firstCall.args).to.deep.equal(['scratchOrgAlias', 'newScratchUsername']);
285282
expect(aliasGetStub.firstCall.args).to.deep.equal(['newScratchUsername']);
286283
expect(configStub.firstCall.args).to.deep.equal(['target-org', 'scratchOrgAlias']);
287284
});

test/commands/force/org/status.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Org,
1010
SfdxPropertyKeys,
1111
SfdxConfigAggregator,
12-
GlobalInfo,
12+
StateAggregator,
1313
ConfigAggregator,
1414
Lifecycle,
1515
SandboxEvents,
@@ -60,7 +60,7 @@ describe('org:status', () => {
6060
let configSetStub: sinon.SinonStub;
6161
let configWriteStub: sinon.SinonStub;
6262
let onStub: sinon.SinonStub;
63-
let updateValueStub: sinon.SinonStub;
63+
let aliasSetStub: sinon.SinonStub;
6464
let configAggregatorStub;
6565

6666
class TestOrgStatusCommand extends OrgStatusCommand {
@@ -104,10 +104,10 @@ describe('org:status', () => {
104104
uxTableStub = stubMethod(sandbox, UX.prototype, 'table');
105105
stubMethod(sandbox, UX.prototype, 'log');
106106
stubMethod(sandbox, UX.prototype, 'styledHeader');
107-
updateValueStub = sinon.stub();
108-
stubMethod(sandbox, GlobalInfo, 'getInstance').returns({
107+
aliasSetStub = sinon.stub();
108+
stubMethod(sandbox, StateAggregator, 'getInstance').returns({
109109
aliases: {
110-
update: updateValueStub,
110+
set: aliasSetStub,
111111
},
112112
});
113113
return cmd.runIt();
@@ -116,7 +116,7 @@ describe('org:status', () => {
116116
it('will return sandbox process object', async () => {
117117
const res = await runStatusCommand(['--sandboxname', sanboxname]);
118118
expect(uxTableStub.firstCall.args[0].length).to.equal(12);
119-
expect(updateValueStub.callCount).to.be.equal(0);
119+
expect(aliasSetStub.callCount).to.be.equal(0);
120120
expect(configSetStub.callCount).to.be.equal(0);
121121
expect(configWriteStub.callCount).to.be.equal(0);
122122
expect(onStub.callCount).to.be.equal(2);
@@ -131,7 +131,7 @@ describe('org:status', () => {
131131
sandboxalias,
132132
'--setdefaultusername',
133133
]);
134-
expect(updateValueStub.firstCall.args).to.deep.equal([sandboxalias, authUserName]);
134+
expect(aliasSetStub.firstCall.args).to.deep.equal([sandboxalias, authUserName]);
135135
expect(onStub.secondCall.firstArg).to.be.equal(SandboxEvents.EVENT_RESULT);
136136
expect(onStub.callCount).to.be.equal(2);
137137
expect(res).to.deep.equal(sandboxProcessObj);

test/shared/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import { expect } from '@salesforce/command/lib/test';
88
import * as sinon from 'sinon';
9-
import { GlobalInfo } from '@salesforce/core';
9+
import { StateAggregator } from '@salesforce/core';
1010
import { stubMethod } from '@salesforce/ts-sinon';
1111
import { getAliasByUsername } from '../../src/shared/utils';
1212

@@ -17,7 +17,7 @@ describe('getAliasByUsername', () => {
1717
getAllStub.withArgs('username1').returns(['alias1']);
1818
getAllStub.withArgs('username2').returns(['alias2', 'alias2b']);
1919

20-
stubMethod(sandbox, GlobalInfo, 'getInstance').resolves({
20+
stubMethod(sandbox, StateAggregator, 'getInstance').resolves({
2121
aliases: {
2222
getAll: getAllStub,
2323
},

0 commit comments

Comments
 (0)