@@ -3,32 +3,45 @@ import { TemplateFormat } from '../../src/types';
33import { jsonTemplate , yamlTemplate } from '../fixtures/templateFixture' ;
44
55const mockedLogger = jest . fn ( ) ;
6+ const mockedIamInfo = jest . fn ( ) ;
7+
68jest . mock ( '../../src/common/logger' , ( ) => ( {
79 logger : { info : ( ...args : unknown [ ] ) => mockedLogger ( ...args ) , debug : jest . fn ( ) } ,
810} ) ) ;
11+
12+ jest . mock ( '../../src/common/imsClient' , ( ) => ( {
13+ getIamInfo : ( ...rags : unknown [ ] ) => mockedIamInfo ( ...rags ) ,
14+ } ) ) ;
15+
916const stackName = 'printTemplateStack' ;
1017const location = 'tests/fixtures/serverless-insight.yml' ;
1118
1219describe ( 'Unit test for template command' , ( ) => {
1320 beforeEach ( ( ) => {
21+ mockedIamInfo . mockResolvedValue ( { accountId : '123456789012' , region : 'cn-hangzhou' } ) ;
22+ } ) ;
23+
24+ afterEach ( ( ) => {
1425 mockedLogger . mockRestore ( ) ;
26+ mockedIamInfo . mockRestore ( ) ;
1527 } ) ;
16- it ( 'should print the template in JSON format by default' , ( ) => {
28+
29+ it ( 'should print the template in JSON format by default' , async ( ) => {
1730 const options = {
1831 format : TemplateFormat . JSON ,
1932 location,
2033 stage : undefined ,
2134 } ;
2235
23- template ( stackName , options ) ;
36+ await template ( stackName , options ) ;
2437
2538 expect ( mockedLogger ) . toHaveBeenCalledWith ( `\n${ JSON . stringify ( jsonTemplate , null , 2 ) } ` ) ;
2639 } ) ;
2740
28- it ( 'should print the template in YAML format when specified' , ( ) => {
41+ it ( 'should print the template in YAML format when specified' , async ( ) => {
2942 const options = { format : TemplateFormat . YAML , location, stage : undefined } ;
3043
31- template ( stackName , options ) ;
44+ await template ( stackName , options ) ;
3245
3346 expect ( mockedLogger ) . toHaveBeenCalledWith ( yamlTemplate ) ;
3447 } ) ;
0 commit comments