@@ -214,4 +214,74 @@ describe('orgListUtil tests', () => {
214214 expect ( checkNonScratchOrgIsDevHub . called ) . to . be . false ;
215215 } ) ;
216216 } ) ;
217+
218+ describe ( 'auth file reading tests' , ( ) => {
219+ // mock reading 2 org files
220+ beforeEach ( ( ) => {
221+ stubMethod ( $$ . SANDBOX , fs , 'readdir' ) . resolves ( [ '00D000000000000001.json' , '00D000000000000002.json' ] ) ;
222+ } ) ;
223+
224+ afterEach ( async ( ) => {
225+ $$ . SANDBOX . restore ( ) ;
226+ } ) ;
227+
228+ it ( 'will return an org with userId without an org file' , async ( ) => {
229+ stubMethod ( $$ . SANDBOX , AuthInfo , 'create' ) . resolves ( {
230+ getFields : ( ) => ( { ...orgAuthConfigFields , userId : '005xxxxxxxxxxxxx' , orgId : '00D000000000000003' } ) ,
231+ getConnectionOptions : ( ) => ( { accessToken : orgAuthConfigFields . accessToken } ) ,
232+ isJwt : ( ) => false ,
233+ isOauth : ( ) => false ,
234+ getUsername : ( ) => orgAuthConfigFields . username ,
235+ } ) ;
236+ const authFiles = await OrgListUtil . readAuthFiles ( [ `${ orgAuthConfigFields . username } .json` ] ) ;
237+ expect ( authFiles . length ) . to . equal ( 1 ) ;
238+ expect ( authFiles [ 0 ] . getFields ( ) ) . to . have . property ( 'username' ) . equals ( orgAuthConfigFields . username ) ;
239+ } ) ;
240+
241+ it ( 'will return an org with userId with an org file where the userid is primary' , async ( ) => {
242+ stubMethod ( $$ . SANDBOX , AuthInfo , 'create' ) . resolves ( {
243+ getFields : ( ) => ( { ...orgAuthConfigFields , userId : '005xxxxxxxxxxxxx' , orgId : '00D000000000000001' } ) ,
244+ getConnectionOptions : ( ) => ( { accessToken : orgAuthConfigFields . accessToken } ) ,
245+ isJwt : ( ) => false ,
246+ isOauth : ( ) => false ,
247+ getUsername : ( ) => orgAuthConfigFields . username ,
248+ } ) ;
249+ stubMethod ( $$ . SANDBOX , fs , 'readJson' ) . resolves ( {
250+ usernames :
[ orgAuthConfigFields . username , '[email protected] ' ] , 251+ } ) ;
252+ const authFiles = await OrgListUtil . readAuthFiles ( [ `${ orgAuthConfigFields . username } .json` ] ) ;
253+ expect ( authFiles . length ) . to . equal ( 1 ) ;
254+ expect ( authFiles [ 0 ] . getFields ( ) ) . to . have . property ( 'username' ) . equals ( orgAuthConfigFields . username ) ;
255+ } ) ;
256+
257+ it ( 'will NOT return an org with userId with an org file where the userid is NOT listed' , async ( ) => {
258+ stubMethod ( $$ . SANDBOX , AuthInfo , 'create' ) . resolves ( {
259+ getFields : ( ) => ( { ...orgAuthConfigFields , userId : '005xxxxxxxxxxxxx' , orgId : '00D000000000000001' } ) ,
260+ getConnectionOptions : ( ) => ( { accessToken : orgAuthConfigFields . accessToken } ) ,
261+ isJwt : ( ) => false ,
262+ isOauth : ( ) => false ,
263+ getUsername : ( ) => orgAuthConfigFields . username ,
264+ } ) ;
265+ stubMethod ( $$ . SANDBOX , fs , 'readJson' ) . resolves ( {
266+ 267+ } ) ;
268+ const authFiles = await OrgListUtil . readAuthFiles ( [ `${ orgAuthConfigFields . username } .json` ] ) ;
269+ expect ( authFiles . length ) . to . equal ( 0 ) ;
270+ } ) ;
271+
272+ it ( 'will NOT return an org with userId with an org file where the userid is listed but not first' , async ( ) => {
273+ stubMethod ( $$ . SANDBOX , AuthInfo , 'create' ) . resolves ( {
274+ getFields : ( ) => ( { ...orgAuthConfigFields , userId : '005xxxxxxxxxxxxx' , orgId : '00D000000000000001' } ) ,
275+ getConnectionOptions : ( ) => ( { accessToken : orgAuthConfigFields . accessToken } ) ,
276+ isJwt : ( ) => false ,
277+ isOauth : ( ) => false ,
278+ getUsername : ( ) => orgAuthConfigFields . username ,
279+ } ) ;
280+ stubMethod ( $$ . SANDBOX , fs , 'readJson' ) . resolves ( {
281+ usernames :
[ '[email protected] ' , orgAuthConfigFields . username ] , 282+ } ) ;
283+ const authFiles = await OrgListUtil . readAuthFiles ( [ `${ orgAuthConfigFields . username } .json` ] ) ;
284+ expect ( authFiles . length ) . to . equal ( 0 ) ;
285+ } ) ;
286+ } ) ;
217287} ) ;
0 commit comments