@@ -261,6 +261,16 @@ test('parseEnvironmentUrl returns null when no URL label is present (and on empt
261261 assert . equal ( parseEnvironmentUrl ( null ) , null ) ;
262262} ) ;
263263
264+ test ( 'parseActiveAuthListEnvironmentUrl extracts the active auth profile Environment Url' , ( ) => {
265+ const { parseActiveAuthListEnvironmentUrl } = require ( helpersPath ) ;
266+ const output = [
267+ 'Index Active Kind Name User Cloud Type Environment Environment Url' ,
268+ '[1] * UNIVERSAL user@contoso.com Public OperatingSystem PowerPagesProDev https://powerpagesprodev.crm.dynamics.com/' ,
269+ '[2] UNIVERSAL user@contoso.com Public OperatingSystem OtherEnv https://other.crm.dynamics.com/' ,
270+ ] . join ( '\n' ) ;
271+ assert . equal ( parseActiveAuthListEnvironmentUrl ( output ) , 'https://powerpagesprodev.crm.dynamics.com' ) ;
272+ } ) ;
273+
264274test ( 'getEnvironmentUrl parses the 2.8.x "Org URL:" output via mocked execSync' , ( t ) => {
265275 const originalExecSync = childProcess . execSync ;
266276 childProcess . execSync = ( ) => ' Org URL: https://orgABC.crm.dynamics.com/\n' ;
@@ -271,3 +281,24 @@ test('getEnvironmentUrl parses the 2.8.x "Org URL:" output via mocked execSync',
271281 assert . equal ( getEnvironmentUrl ( ) , 'https://orgabc.crm.dynamics.com' ) ;
272282 delete require . cache [ require . resolve ( helpersPath ) ] ;
273283} ) ;
284+
285+ test ( 'getEnvironmentUrl falls back to active pac auth list Environment Url when pac env who has no URL' , ( t ) => {
286+ const originalExecSync = childProcess . execSync ;
287+ childProcess . execSync = ( command ) => {
288+ if ( command === 'pac env who' ) return 'No organization selected\n' ;
289+ if ( command === 'pac auth list' ) {
290+ return [
291+ 'Index Active Kind Name User Cloud Type Environment Environment Url' ,
292+ '[1] * UNIVERSAL user@contoso.com Public OperatingSystem PowerPagesProDev https://powerpagesprodev.crm.dynamics.com/' ,
293+ ] . join ( '\n' ) ;
294+ }
295+ throw new Error ( `unexpected command: ${ command } ` ) ;
296+ } ;
297+ t . after ( ( ) => { childProcess . execSync = originalExecSync ; } ) ;
298+ delete require . cache [ require . resolve ( helpersPath ) ] ;
299+
300+ const { getEnvironmentUrl } = require ( helpersPath ) ;
301+
302+ assert . equal ( getEnvironmentUrl ( ) , 'https://powerpagesprodev.crm.dynamics.com' ) ;
303+ delete require . cache [ require . resolve ( helpersPath ) ] ;
304+ } ) ;
0 commit comments