Skip to content

Commit 18565ad

Browse files
authored
Merge pull request #124 from salesforcecli/sm/fix-multiple-alias-9351642
fix: use most recent alias
2 parents ca639bb + 904ba3e commit 18565ad

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/shared/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import * as open from 'open';
1111
export const getAliasByUsername = async (username: string): Promise<string> => {
1212
const alias = await Aliases.create(Aliases.getDefaultOptions());
1313
const keys = alias.getKeysByValue(username);
14-
return keys?.length ? keys[0] : undefined;
14+
// use the most recently added alias for that username
15+
return keys?.length ? keys[keys.length - 1] : undefined;
1516
};
1617

1718
export const openUrl = async (url: string): Promise<ChildProcess> => {

test/shared/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ describe('getAliasByUsername', () => {
2727
expect(await getAliasByUsername('username1')).to.equal('alias1');
2828
});
2929

30-
it('returns first alias for a username that has multiple aliases', async () => {
31-
expect(await getAliasByUsername('username2')).to.equal('alias2');
30+
it('returns most recent alias for a username that has multiple aliases', async () => {
31+
expect(await getAliasByUsername('username2')).to.equal('alias2b');
3232
});
3333

3434
it('returns undefined when no matching username is found', async () => {

0 commit comments

Comments
 (0)