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 * as fs from 'fs/promises' ;
78import { expect } from '@salesforce/command/lib/test' ;
89import * as sinon from 'sinon' ;
9- import { AuthInfo , ConfigAggregator , fs , Aliases , Org } from '@salesforce/core' ;
10+ import { AuthInfo , ConfigAggregator , Org } from '@salesforce/core' ;
1011import { stubMethod } from '@salesforce/ts-sinon' ;
1112import { OrgListUtil } from '../../src/shared/orgListUtil' ;
1213import * as utils from '../../src/shared/utils' ;
6061
6162describe ( 'orgListUtil tests' , ( ) => {
6263 const spies = new Map ( ) ;
63- let aliasListStub : sinon . SinonStub ;
6464 let determineConnectedStatusForNonScratchOrg : sinon . SinonStub ;
6565 let retrieveScratchOrgInfoFromDevHubStub : sinon . SinonStub ;
6666 let checkNonScratchOrgIsDevHub : sinon . SinonStub ;
@@ -73,7 +73,6 @@ describe('orgListUtil tests', () => {
7373 sandbox . stub ( AuthInfo , 'create' ) ;
7474
7575 stubMethod ( sandbox , OrgListUtil , 'readAuthFiles' ) . resolves ( [ orgAuthConfig , expiredAuthConfig , devHubConfig ] ) ;
76- aliasListStub = stubMethod ( sandbox , Aliases , 'fetch' ) . resolves ( ) ;
7776 determineConnectedStatusForNonScratchOrg = stubMethod (
7877 sandbox ,
7978 OrgListUtil ,
@@ -96,7 +95,6 @@ describe('orgListUtil tests', () => {
9695 } ,
9796 } ) ;
9897
99- sandbox . stub ( fs , 'readFileSync' ) ;
10098 stubMethod ( sandbox , fs , 'stat' ) . resolves ( { atime : 'test' } ) ;
10199
102100 sandbox . stub ( utils , 'getAliasByUsername' ) . withArgs ( '[email protected] ' ) . resolves ( 'gaz' ) ; @@ -117,8 +115,6 @@ describe('orgListUtil tests', () => {
117115 // devhub is updated to be true
118116 expect ( checkNonScratchOrgIsDevHub . called ) . to . be . true ;
119117 expect ( orgs . nonScratchOrgs [ 0 ] . isDevHub ) . to . be . true ;
120-
121- expect ( aliasListStub . calledOnce ) . to . be . false ;
122118 expect ( determineConnectedStatusForNonScratchOrg . calledOnce ) . to . be . true ;
123119 expect ( retrieveScratchOrgInfoFromDevHubStub . calledOnce ) . to . be . true ;
124120 } ) ;
@@ -133,8 +129,6 @@ describe('orgListUtil tests', () => {
133129
134130 expect ( orgs . nonScratchOrgs . every ( ( nonScratchOrg ) => nonScratchOrg . connectedStatus === undefined ) ) . to . be . true ;
135131
136- expect ( aliasListStub . calledOnce ) . to . be . false ;
137- expect ( aliasListStub . calledOnce ) . to . be . false ;
138132 expect ( determineConnectedStatusForNonScratchOrg . called ) . to . be . false ;
139133 } ) ;
140134
@@ -245,9 +239,11 @@ describe('orgListUtil tests', () => {
245239 isOauth : ( ) => false ,
246240 getUsername : ( ) => orgAuthConfigFields . username ,
247241 } ) ;
248- stubMethod ( sandbox , fs , 'readJson' ) . resolves ( {
249- usernames :
[ orgAuthConfigFields . username , '[email protected] ' ] , 250- } ) ;
242+ stubMethod ( sandbox , fs , 'readFile' ) . resolves (
243+ JSON . stringify ( {
244+ usernames :
[ orgAuthConfigFields . username , '[email protected] ' ] , 245+ } )
246+ ) ;
251247 const authFiles = await OrgListUtil . readAuthFiles ( [ `${ orgAuthConfigFields . username } .json` ] ) ;
252248 expect ( authFiles . length ) . to . equal ( 1 ) ;
253249 expect ( authFiles [ 0 ] . getFields ( ) ) . to . have . property ( 'username' ) . equals ( orgAuthConfigFields . username ) ;
@@ -261,9 +257,7 @@ describe('orgListUtil tests', () => {
261257 isOauth : ( ) => false ,
262258 getUsername : ( ) => orgAuthConfigFields . username ,
263259 } ) ;
264- stubMethod ( sandbox , fs , 'readJson' ) . resolves ( {
265- 266- } ) ;
260+ stubMethod ( sandbox , fs , 'readFile' ) . resolves ( '{"usernames":["[email protected] "]}' ) ; 267261 const authFiles = await OrgListUtil . readAuthFiles ( [ `${ orgAuthConfigFields . username } .json` ] ) ;
268262 expect ( authFiles . length ) . to . equal ( 0 ) ;
269263 } ) ;
@@ -276,9 +270,11 @@ describe('orgListUtil tests', () => {
276270 isOauth : ( ) => false ,
277271 getUsername : ( ) => orgAuthConfigFields . username ,
278272 } ) ;
279- stubMethod ( sandbox , fs , 'readJson' ) . resolves ( {
280- usernames :
[ '[email protected] ' , orgAuthConfigFields . username ] , 281- } ) ;
273+ stubMethod ( sandbox , fs , 'readFile' ) . resolves (
274+ JSON . stringify ( {
275+ usernames :
[ '[email protected] ' , orgAuthConfigFields . username ] , 276+ } )
277+ ) ;
282278 const authFiles = await OrgListUtil . readAuthFiles ( [ `${ orgAuthConfigFields . username } .json` ] ) ;
283279 expect ( authFiles . length ) . to . equal ( 0 ) ;
284280 } ) ;
0 commit comments