diff --git a/src/m365/flow/commands/environment/environment-list.spec.ts b/src/m365/flow/commands/environment/environment-list.spec.ts index 306c2c72c9b..4a918771b7e 100644 --- a/src/m365/flow/commands/environment/environment-list.spec.ts +++ b/src/m365/flow/commands/environment/environment-list.spec.ts @@ -456,6 +456,135 @@ describe(commands.ENVIRONMENT_LIST, () => { ])); }); + it('retrieves Microsoft Flow environments with output json', async () => { + sinon.stub(request, 'get').callsFake(async (opts) => { + if ((opts.url as string).indexOf(`/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01`) > -1) { + if (opts.headers && + opts.headers.accept && + (opts.headers.accept as string).indexOf('application/json') === 0) { + return { + value: [ + { + "name": "Default-d87a7535-dd31-4437-bfe1-95340acd55c5", + "location": "europe", + "type": "Microsoft.ProcessSimple/environments", + "id": "/providers/Microsoft.ProcessSimple/environments/Default-d87a7535-dd31-4437-bfe1-95340acd55c5", + "properties": { + "displayName": "Contoso (default)", + "createdTime": "2018-03-22T20:20:46.08653Z", + "createdBy": { + "id": "SYSTEM", + "displayName": "SYSTEM", + "type": "NotSpecified" + }, + "provisioningState": "Succeeded", + "creationType": "DefaultTenant", + "environmentSku": "Default", + "environmentType": "Production", + "isDefault": true, + "azureRegionHint": "westeurope", + "runtimeEndpoints": { + "microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com", + "microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com", + "microsoft.PowerApps": "https://europe.api.powerapps.com", + "microsoft.Flow": "https://europe.api.flow.microsoft.com" + } + } + }, + { + "name": "Test-d87a7535-dd31-4437-bfe1-95340acd55c5", + "location": "europe", + "type": "Microsoft.ProcessSimple/environments", + "id": "/providers/Microsoft.ProcessSimple/environments/Test-d87a7535-dd31-4437-bfe1-95340acd55c5", + "properties": { + "displayName": "Contoso (test)", + "createdTime": "2018-03-22T20:20:46.08653Z", + "createdBy": { + "id": "SYSTEM", + "displayName": "SYSTEM", + "type": "NotSpecified" + }, + "provisioningState": "Succeeded", + "creationType": "DefaultTenant", + "environmentSku": "Default", + "environmentType": "Production", + "isDefault": false, + "azureRegionHint": "westeurope", + "runtimeEndpoints": { + "microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com", + "microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com", + "microsoft.PowerApps": "https://europe.api.powerapps.com", + "microsoft.Flow": "https://europe.api.flow.microsoft.com" + } + } + } + ] + }; + } + } + + throw 'Invalid request'; + }); + + await command.action(logger, { options: { output: 'json' } }); + assert(loggerLogSpy.calledWith([ + { + "name": "Default-d87a7535-dd31-4437-bfe1-95340acd55c5", + "location": "europe", + "type": "Microsoft.ProcessSimple/environments", + "id": "/providers/Microsoft.ProcessSimple/environments/Default-d87a7535-dd31-4437-bfe1-95340acd55c5", + "properties": { + "displayName": "Contoso (default)", + "createdTime": "2018-03-22T20:20:46.08653Z", + "createdBy": { + "id": "SYSTEM", + "displayName": "SYSTEM", + "type": "NotSpecified" + }, + "provisioningState": "Succeeded", + "creationType": "DefaultTenant", + "environmentSku": "Default", + "environmentType": "Production", + "isDefault": true, + "azureRegionHint": "westeurope", + "runtimeEndpoints": { + "microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com", + "microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com", + "microsoft.PowerApps": "https://europe.api.powerapps.com", + "microsoft.Flow": "https://europe.api.flow.microsoft.com" + } + } + }, + { + "name": "Test-d87a7535-dd31-4437-bfe1-95340acd55c5", + "location": "europe", + "type": "Microsoft.ProcessSimple/environments", + "id": "/providers/Microsoft.ProcessSimple/environments/Test-d87a7535-dd31-4437-bfe1-95340acd55c5", + "properties": { + "displayName": "Contoso (test)", + "createdTime": "2018-03-22T20:20:46.08653Z", + "createdBy": { + "id": "SYSTEM", + "displayName": "SYSTEM", + "type": "NotSpecified" + }, + "provisioningState": "Succeeded", + "creationType": "DefaultTenant", + "environmentSku": "Default", + "environmentType": "Production", + "isDefault": false, + "azureRegionHint": "westeurope", + "runtimeEndpoints": { + "microsoft.BusinessAppPlatform": "https://europe.api.bap.microsoft.com", + "microsoft.CommonDataModel": "https://europe.api.cds.microsoft.com", + "microsoft.PowerApps": "https://europe.api.powerapps.com", + "microsoft.Flow": "https://europe.api.flow.microsoft.com" + } + } + } + ])); + }); + it('correctly handles no environments', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { if ((opts.url as string).indexOf(`/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01`) > -1) { diff --git a/src/m365/flow/commands/environment/environment-list.ts b/src/m365/flow/commands/environment/environment-list.ts index a389e568968..92efe4ed08d 100644 --- a/src/m365/flow/commands/environment/environment-list.ts +++ b/src/m365/flow/commands/environment/environment-list.ts @@ -25,10 +25,12 @@ class FlowEnvironmentListCommand extends AzmgmtCommand { try { const res = await odata.getAllItems<{ name: string, displayName: string; properties: { displayName: string } }>(`${this.resource}providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01`); - if (args.options.output !== 'json' && res.length > 0) { - res.forEach(e => { - e.displayName = e.properties.displayName; - }); + if (res.length > 0) { + if (args.options.output !== 'json') { + res.forEach(e => { + e.displayName = e.properties.displayName; + }); + } await logger.log(res); }