Skip to content

Commit 99c77f0

Browse files
committed
fix: for set alias
1 parent e26b84a commit 99c77f0

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/commands/force/org/status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export class OrgStatusCommand extends SfdxCommand {
7373
});
7474
if (results.sandboxRes?.authUserName) {
7575
if (this.flags.setalias) {
76-
const alias = await Aliases.create({});
77-
const result = alias.set(this.flags.setalias, results.sandboxRes.authUserName);
76+
const aliases = await Aliases.create(Aliases.getDefaultOptions());
77+
const result = await aliases.updateValue(this.flags.setalias, results.sandboxRes.authUserName);
7878
this.logger.debug('Set Alias: %s result: %s', this.flags.setalias, result);
7979
}
8080
if (this.flags.setdefaultusername) {

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ describe('org:status', () => {
4848
// stubs
4949
let uxTableStub: sinon.SinonStub;
5050
let cmd: TestOrgStatusCommand;
51-
let aliasSetStub: sinon.SinonStub;
5251
let configSetStub: sinon.SinonStub;
5352
let configWriteStub: sinon.SinonStub;
5453
let onStub: sinon.SinonStub;
54+
let updateValueStub: sinon.SinonStub;
5555
let configAggregatorStub;
5656

5757
class TestOrgStatusCommand extends OrgStatusCommand {
@@ -92,37 +92,42 @@ describe('org:status', () => {
9292
stubMethod(sandbox, Lifecycle, 'getInstance').returns({
9393
on: onStub,
9494
});
95-
aliasSetStub = stubMethod(sandbox, Aliases.prototype, 'set').returns(sandboxalias);
9695
uxTableStub = stubMethod(sandbox, UX.prototype, 'table');
96+
updateValueStub = stubMethod(sandbox, Aliases.prototype, 'updateValue');
9797
return cmd.runIt();
9898
};
9999

100100
it('will return sandbox process object', async () => {
101101
const res = await runStatusCommand(['--sandboxname', sanboxname]);
102102
expect(uxTableStub.firstCall.args[0].length).to.equal(12);
103-
expect(aliasSetStub.callCount).to.be.equal(0);
103+
expect(updateValueStub.callCount).to.be.equal(0);
104104
expect(configSetStub.callCount).to.be.equal(0);
105105
expect(configWriteStub.callCount).to.be.equal(0);
106106
expect(onStub.callCount).to.be.equal(2);
107107
expect(res).to.deep.equal(sandboxProcessObj);
108108
});
109109

110-
it('will set alias and default username', async () => {
110+
it('will set alias', async () => {
111111
const res = await runStatusCommand([
112112
'--sandboxname',
113113
sanboxname,
114114
'--setalias',
115115
sandboxalias,
116116
'--setdefaultusername',
117117
]);
118-
expect(aliasSetStub.callCount).to.be.equal(1);
119-
expect(aliasSetStub.firstCall.args[0]).to.be.equal(sandboxalias);
120-
expect(aliasSetStub.firstCall.args[1]).to.be.equal(authUserName);
118+
expect(updateValueStub.firstCall.args).to.deep.equal([sandboxalias, authUserName]);
119+
expect(onStub.secondCall.firstArg).to.be.equal(SandboxEvents.EVENT_RESULT);
120+
expect(onStub.callCount).to.be.equal(2);
121+
expect(res).to.deep.equal(sandboxProcessObj);
122+
});
123+
124+
it('will set default username', async () => {
125+
const res = await runStatusCommand(['--sandboxname', sanboxname, '--setdefaultusername']);
121126
expect(configSetStub.firstCall.args[0]).to.be.equal(Config.DEFAULT_USERNAME);
122127
expect(configSetStub.firstCall.args[1]).to.be.equal(authUserName);
128+
expect(configWriteStub.calledOnce).to.be.true;
123129
expect(onStub.secondCall.firstArg).to.be.equal(SandboxEvents.EVENT_RESULT);
124130
expect(onStub.callCount).to.be.equal(2);
125-
expect(configWriteStub.calledOnce).to.be.true;
126131
expect(res).to.deep.equal(sandboxProcessObj);
127132
});
128133

0 commit comments

Comments
 (0)