11import { Command } from 'commander' ;
2- import { setupCLI } from './cli' ;
32
43let calmShared : typeof import ( '@finos/calm-shared' ) ;
54let validateModule : typeof import ( './command-helpers/validate' ) ;
65let serverModule : typeof import ( './server/cli-server' ) ;
76let templateModule : typeof import ( './command-helpers/template' ) ;
7+ let fileReaderModule : typeof import ( './command-helpers/file-input' ) ;
8+ let optionsModule : typeof import ( './command-helpers/generate-options' ) ;
9+ let setupCLI : typeof import ( './cli' ) . setupCLI ;
810
911describe ( 'CLI Commands' , ( ) => {
1012 let program : Command ;
@@ -13,10 +15,16 @@ describe('CLI Commands', () => {
1315 vi . resetModules ( ) ;
1416 vi . clearAllMocks ( ) ;
1517
18+ fileReaderModule = await import ( './command-helpers/file-input' ) ;
19+ const loadFileSpy = vi . spyOn ( fileReaderModule , 'loadJsonFromFile' ) ;
20+ loadFileSpy . mockReset ( ) ;
21+ loadFileSpy . mockImplementation ( ( ) => Promise . resolve ( { } ) ) ;
22+
1623 calmShared = await import ( '@finos/calm-shared' ) ;
1724 validateModule = await import ( './command-helpers/validate' ) ;
1825 serverModule = await import ( './server/cli-server' ) ;
1926 templateModule = await import ( './command-helpers/template' ) ;
27+ optionsModule = await import ( './command-helpers/generate-options' ) ;
2028
2129 vi . spyOn ( calmShared , 'runGenerate' ) . mockResolvedValue ( undefined ) ;
2230 vi . spyOn ( calmShared . TemplateProcessor . prototype , 'processTemplate' ) . mockResolvedValue ( undefined ) ;
@@ -28,6 +36,11 @@ describe('CLI Commands', () => {
2836 vi . spyOn ( serverModule , 'startServer' ) . mockImplementation ( vi . fn ( ) ) ;
2937 vi . spyOn ( templateModule , 'getUrlToLocalFileMap' ) . mockReturnValue ( new Map ( ) ) ;
3038
39+ vi . spyOn ( optionsModule , 'promptUserForOptions' ) . mockResolvedValue ( [ ] ) ;
40+
41+ const cliModule = await import ( './cli' ) ;
42+ setupCLI = cliModule . setupCLI ;
43+
3144 program = new Command ( ) ;
3245 setupCLI ( program ) ;
3346 } ) ;
@@ -42,8 +55,11 @@ describe('CLI Commands', () => {
4255 '--schemaDirectory' , 'schemas' ,
4356 ] ) ;
4457
58+ expect ( fileReaderModule . loadJsonFromFile ) . toHaveBeenCalledWith ( 'pattern.json' , true ) ;
59+ expect ( optionsModule . promptUserForOptions ) . toHaveBeenCalled ( ) ;
60+
4561 expect ( calmShared . runGenerate ) . toHaveBeenCalledWith (
46- 'pattern.json' , 'output.json' , true , 'schemas'
62+ { } , 'output.json' , true , [ ] , 'schemas'
4763 ) ;
4864 } ) ;
4965 } ) ;
@@ -79,7 +95,7 @@ describe('CLI Commands', () => {
7995 verbose : true ,
8096 } ) ;
8197 } ) ;
82- } ) ;
98+ } ) ;
8399
84100 describe ( 'Template Command' , ( ) => {
85101 it ( 'should instantiate TemplateProcessor and call processTemplate' , async ( ) => {
0 commit comments