1+ /*---------------------------------------------------------------------------------------------
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License. See License.txt in the project root for license information.
4+ *--------------------------------------------------------------------------------------------*/
5+
6+ import { type Site } from '@azure/arm-appservice' ;
7+ import { type ParsedSite } from '@microsoft/vscode-azext-azureappservice' ;
8+ import * as assert from 'assert' ;
9+
10+ suite ( 'Deploy Stopped Function App Tests' , ( ) => {
11+ test ( 'Should block deployment to stopped function app' , ( ) => {
12+ // Create mock site with STOPPED state
13+ const mockSite : Site = {
14+ name : 'test-function-app' ,
15+ state : 'STOPPED' ,
16+ id : '/subscriptions/test/resourceGroups/test/providers/Microsoft.Web/sites/test-function-app' ,
17+ kind : 'functionapp' ,
18+ location : 'East US' ,
19+ type : 'Microsoft.Web/sites'
20+ } ;
21+
22+ const mockParsedSite = {
23+ fullName : 'test-function-app' ,
24+ rawSite : mockSite
25+ } as ParsedSite ;
26+
27+ // Simulate the check that should happen in the deploy function
28+ try {
29+ if ( mockParsedSite . rawSite . state === 'STOPPED' ) {
30+ throw new Error ( 'Cannot deploy to function app "test-function-app" because it is currently stopped. Please start the function app before deploying.' ) ;
31+ }
32+ assert . fail ( 'Expected deployment to fail for stopped function app' ) ;
33+ } catch ( error ) {
34+ // Verify the error message is user-friendly and contains expected keywords
35+ assert . ok ( error instanceof Error ) ;
36+ assert . ok ( error . message . includes ( 'Cannot deploy to function app' ) ) ;
37+ assert . ok ( error . message . includes ( 'currently stopped' ) ) ;
38+ assert . ok ( error . message . includes ( 'Please start the function app' ) ) ;
39+ }
40+ } ) ;
41+
42+ test ( 'Should allow deployment to running function app' , ( ) => {
43+ // Create mock site with READY state
44+ const mockSite : Site = {
45+ name : 'test-function-app' ,
46+ state : 'READY' ,
47+ id : '/subscriptions/test/resourceGroups/test/providers/Microsoft.Web/sites/test-function-app' ,
48+ kind : 'functionapp' ,
49+ location : 'East US' ,
50+ type : 'Microsoft.Web/sites'
51+ } ;
52+
53+ const mockParsedSite = {
54+ fullName : 'test-function-app' ,
55+ rawSite : mockSite
56+ } as ParsedSite ;
57+
58+ // Simulate the check that should happen in the deploy function
59+ // This should not throw an error for READY state
60+ if ( mockParsedSite . rawSite . state === 'STOPPED' ) {
61+ throw new Error ( 'Cannot deploy to function app "test-function-app" because it is currently stopped. Please start the function app before deploying.' ) ;
62+ }
63+
64+ // If we reach here, the check passed as expected
65+ assert . ok ( true , 'Deployment should proceed for READY function app' ) ;
66+ } ) ;
67+
68+ test ( 'Should allow deployment to function app with unknown state' , ( ) => {
69+ // Create mock site with UNKNOWN state - should not block deployment
70+ const mockSite : Site = {
71+ name : 'test-function-app' ,
72+ state : 'UNKNOWN' ,
73+ id : '/subscriptions/test/resourceGroups/test/providers/Microsoft.Web/sites/test-function-app' ,
74+ kind : 'functionapp' ,
75+ location : 'East US' ,
76+ type : 'Microsoft.Web/sites'
77+ } ;
78+
79+ const mockParsedSite = {
80+ fullName : 'test-function-app' ,
81+ rawSite : mockSite
82+ } as ParsedSite ;
83+
84+ // Simulate the check that should happen in the deploy function
85+ // This should not throw an error for UNKNOWN state
86+ if ( mockParsedSite . rawSite . state === 'STOPPED' ) {
87+ throw new Error ( 'Cannot deploy to function app "test-function-app" because it is currently stopped. Please start the function app before deploying.' ) ;
88+ }
89+
90+ // If we reach here, the check passed as expected
91+ assert . ok ( true , 'Deployment should proceed for UNKNOWN function app' ) ;
92+ } ) ;
93+ } ) ;
0 commit comments