import { WebSiteManagementModels as Models } from '@azure/arm-appservice' ; import * as assert from 'assert' ; import * as vscode from 'vscode' ; import { tryGetWebApp } from 'vscode-azureappservice' ; import { runWithInputs , runWithTestActionContext } from 'vscode-azureextensiondev' ; import { createFunctionAppAdvanced , deleteFunctionApp , DialogResponses , getRandomHexString , ProjectLanguage , registerOnActionStartHandler } from '../../extension.bundle' ; import { cleanTestWorkspace , longRunningTestsEnabled } from '../global.test' ; import { runWithFuncSetting } from '../runWithSetting' ; import { getRotatingLocation , getRotatingNodeVersion } from './getRotatingValue' ; import { resourceGroupsToDelete , testAccount , testClient } from './global.nightly.test' ; suite ( 'Function App Operations' , function ( this ) : void { this . timeout ( 7 * 60 * 1000 ) ; let appName ; let app2Name ; let rgName ; let saName ; let aiName ; let location ; suiteSetup ( async function ( this ) : Promise < void > { if ( ! longRunningTestsEnabled ) { this . skip ( ) ; } await cleanTestWorkspace ( ) ; appName = getRandomHexString ( ) ; app2Name = getRandomHexString ( ) ; rgName = getRandomHexString ( ) ; resourceGroupsToDelete . push ( rgName ) ; saName = getRandomHexString ( ) . toLowerCase ( ) ; aiName = getRandomHexString ( ) ; location = getRotatingLocation ( ) ; } ) ; test ( 'Create - Advanced' , async ( ) => { const testInputs = [ appName , /\.net/i , 'Windows' , '$(plus) Create new resource group' , rgName , location , 'Consumption' , '$(plus) Create new storage account' , saName , '$(plus) Create new Application Insights resource' , aiName ] ; await runWithTestActionContext ( 'createFunctionAppAdvanced' , async ( context ) => { await context . ui . runWithInputs ( testInputs , async ( ) => { await createFunctionAppAdvanced ( context ) ; } ) ; } ) ; const createdApp = await tryGetWebApp ( testClient , rgName , appName ) ; assert . ok ( createdApp ) ; } ) ; test ( 'Create - Advanced - Existing RG/SA/AI' , async ( ) => { const testInputs = [ app2Name , /\.net/i , 'Windows' , rgName , location , 'Consumption' , saName , aiName ] ; await runWithTestActionContext ( 'createFunctionAppAdvanced' , async ( context ) => { await context . ui . runWithInputs ( testInputs , async ( ) => { await createFunctionAppAdvanced ( context ) ; } ) ; } ) ; const createdApp = await tryGetWebApp ( testClient , rgName , app2Name ) ; assert . ok ( createdApp ) ; } ) ; test ( 'Create - API (deprecated)' , async ( ) => { const apiRgName = getRandomHexString ( ) ; resourceGroupsToDelete . push ( apiRgName ) ; const apiAppName = getRandomHexString ( ) ; const inputs = [ apiAppName , getRotatingNodeVersion ( ) , getRotatingLocation ( ) ] ; const commandId = 'azureFunctions.createFunctionApp' ; await runWithFuncSetting ( 'projectLanguage' , ProjectLanguage . JavaScript , async ( ) => { await runWithInputs ( commandId , inputs , registerOnActionStartHandler , async ( ) => { const actualFuncAppId = < string > await vscode . commands . executeCommand ( commandId , testAccount . getSubscriptionContext ( ) . subscriptionId , apiRgName ) ; const site = await tryGetWebApp ( testClient , apiRgName , apiAppName ) ; assert . ok ( site ) ; assert . equal ( actualFuncAppId , site . id ) ; } ) ; } ) ; } ) ; test ( 'Delete' , async ( ) => { await runWithTestActionContext ( 'deleteFunctionApp' , async ( context ) => { await context . ui . runWithInputs ( [ appName , DialogResponses . deleteResponse . title , DialogResponses . yes . title ] , async ( ) => { await deleteFunctionApp ( context ) ; } ) ; } ) ; const site = await tryGetWebApp ( testClient , rgName , appName ) ; assert . equal ( site , undefined ) ; } ) ; test ( 'Delete - Existing RG/SA/AI' , async ( ) => { await runWithTestActionContext ( 'deleteFunctionApp' , async ( context ) => { await context . ui . runWithInputs ( [ app2Name , DialogResponses . deleteResponse . title , DialogResponses . yes . title ] , async ( ) => { await deleteFunctionApp ( context ) ; } ) ; } ) ; const site = await tryGetWebApp ( testClient , rgName , app2Name ) ; assert . equal ( site , undefined ) ; } ) ; } ) ;