@@ -10,6 +10,11 @@ import { ResourceService } from "../../services/resourceService";
1010import { Site } from "@azure/arm-appservice/esm/models" ;
1111
1212describe ( "Deploy plugin" , ( ) => {
13+
14+ afterEach ( ( ) => {
15+ jest . resetAllMocks ( ) ;
16+ } )
17+
1318 it ( "calls deploy hook" , async ( ) => {
1419 const deployResourceGroup = jest . fn ( ) ;
1520 const functionAppStub : Site = MockFactory . createTestSite ( ) ;
@@ -30,4 +35,33 @@ describe("Deploy plugin", () => {
3035 expect ( deploy ) . toBeCalled ( ) ;
3136 expect ( uploadFunctions ) . toBeCalledWith ( functionAppStub ) ;
3237 } ) ;
38+
39+ it ( "lists deployments" , async ( ) => {
40+ const deployments = MockFactory . createTestDeployments ( ) ;
41+ ResourceService . prototype . getDeployments = jest . fn ( ( ) => Promise . resolve ( deployments ) ) ;
42+ const sls = MockFactory . createTestServerless ( ) ;
43+ const options = MockFactory . createTestServerlessOptions ( ) ;
44+ const plugin = new AzureDeployPlugin ( sls , options ) ;
45+ await invokeHook ( plugin , "deploy:list:list" ) ;
46+ let expectedLogStatement = "\n\nDeployments" ;
47+ for ( const dep of deployments ) {
48+ expectedLogStatement += "\n-----------\n"
49+ expectedLogStatement += `Name: ${ dep . name } \n`
50+ expectedLogStatement += `Timestamp: ${ dep . properties . timestamp . getTime ( ) } \n` ;
51+ expectedLogStatement += `Datetime: ${ dep . properties . timestamp . toISOString ( ) } \n`
52+ }
53+ expectedLogStatement += "-----------\n"
54+ expect ( sls . cli . log ) . lastCalledWith ( expectedLogStatement ) ;
55+ } ) ;
56+
57+ it ( "logs empty deployment list" , async ( ) => {
58+ const sls = MockFactory . createTestServerless ( ) ;
59+ const resourceGroup = "rg1" ;
60+ ResourceService . prototype . getDeployments = jest . fn ( ( ) => Promise . resolve ( [ ] ) ) as any ;
61+ ResourceService . prototype . getResourceGroup = jest . fn ( ( ) => resourceGroup ) ;
62+ const options = MockFactory . createTestServerlessOptions ( ) ;
63+ const plugin = new AzureDeployPlugin ( sls , options ) ;
64+ await invokeHook ( plugin , "deploy:list:list" ) ;
65+ expect ( sls . cli . log ) . lastCalledWith ( `No deployments found for resource group '${ resourceGroup } '` ) ;
66+ } ) ;
3367} ) ;
0 commit comments