File tree Expand file tree Collapse file tree 3 files changed +11
-14
lines changed
Expand file tree Collapse file tree 3 files changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,6 @@ export class OrgListUtil {
132132
133133 for ( const authInfo of authInfos ) {
134134 const currentValue = OrgListUtil . removeRestrictedInfoFromConfig ( authInfo . getFields ( ) ) as ExtendedAuthFields ;
135-
136135 const [ alias , lastUsed ] = await Promise . all ( [
137136 getAliasByUsername ( currentValue . username ) ,
138137 fs . stat ( join ( Global . DIR , `${ currentValue . username } .json` ) ) ,
Original file line number Diff line number Diff line change @@ -8,13 +8,8 @@ import { Aliases } from '@salesforce/core';
88
99export const getAliasByUsername = async ( username : string ) : Promise < string > => {
1010 const alias = await Aliases . create ( Aliases . getDefaultOptions ( ) ) ;
11- const aliasContent = alias . getContents ( ) . orgs ;
12- if ( aliasContent ) {
13- for ( const aliasedName of Object . keys ( aliasContent ) ) {
14- if ( aliasContent [ aliasedName ] === username ) return aliasedName ;
15- }
16- }
17- return undefined ;
11+ const keys = alias . getKeysByValue ( username ) ;
12+ return keys ?. length ? keys [ 0 ] : undefined ;
1813} ;
1914
2015export const camelCaseToTitleCase = ( text : string ) : string => {
Original file line number Diff line number Diff line change @@ -13,21 +13,24 @@ describe('getAliasByUsername', () => {
1313 beforeEach ( async ( ) => {
1414 stubMethod ( $$ . SANDBOX , Aliases , 'create' ) . resolves ( Aliases . prototype ) ;
1515 stubMethod ( $$ . SANDBOX , Aliases , 'getDefaultOptions' ) . returns ( { } ) ;
16- stubMethod ( $$ . SANDBOX , Aliases . prototype , 'getContents' ) . returns ( {
17- orgs : {
18- alias1 : 'username1' ,
19- alias2 : 'username2' ,
20- } ,
21- } ) ;
16+ stubMethod ( $$ . SANDBOX , Aliases . prototype , 'getKeysByValue' )
17+ . withArgs ( 'username1' )
18+ . returns ( [ 'alias1' ] )
19+ . withArgs ( 'username2' )
20+ . returns ( [ 'alias2' , 'alias2b' ] ) ;
2221 } ) ;
2322 afterEach ( ( ) => {
2423 $$ . SANDBOX . restore ( ) ;
2524 } ) ;
2625
2726 it ( 'returns alias for a username that exists' , async ( ) => {
2827 expect ( await getAliasByUsername ( 'username1' ) ) . to . equal ( 'alias1' ) ;
28+ } ) ;
29+
30+ it ( 'returns first alias for a username that has multiple aliases' , async ( ) => {
2931 expect ( await getAliasByUsername ( 'username2' ) ) . to . equal ( 'alias2' ) ;
3032 } ) ;
33+
3134 it ( 'returns undefined when no matching username is found' , async ( ) => {
3235 expect ( await getAliasByUsername ( 'username3' ) ) . to . be . undefined ;
3336 } ) ;
You can’t perform that action at this time.
0 commit comments