77} from '@finos/calm-shared' ;
88import { Command } from 'commander' ;
99import { MockInstance } from 'vitest' ;
10- import { parseDocumentLoaderConfig } from './cli' ;
1110
1211let calmShared : typeof import ( '@finos/calm-shared' ) ;
1312let validateModule : typeof import ( './command-helpers/validate' ) ;
@@ -440,8 +439,18 @@ describe('CLI Commands', () => {
440439} ) ;
441440
442441describe ( 'parseDocumentLoaderConfig' , ( ) => {
442+ const parseDocLoaderConfigForTest = async ( options : {
443+ verbose ?: boolean ;
444+ calmHubUrl ?: string ;
445+ schemaDirectory ?: string ;
446+ allowedRemoteHosts ?: string [ ] ;
447+ } ) => {
448+ const cliModule = await import ( './cli' ) ;
449+ return cliModule . parseDocumentLoaderConfig ( options ) ;
450+ } ;
451+
443452 it ( 'should parse calmhub url when provided' , async ( ) => {
444- const options = await parseDocumentLoaderConfig ( {
453+ const options = await parseDocLoaderConfigForTest ( {
445454 calmHubUrl : 'calmhub'
446455 } ) ;
447456 expect ( options . calmHubUrl ) . toEqual ( 'calmhub' ) ;
@@ -451,29 +460,58 @@ describe('parseDocumentLoaderConfig', () => {
451460 cliConfigModule = await import ( './cli-config' ) ;
452461 vi . spyOn ( cliConfigModule , 'loadCliConfig' ) . mockResolvedValue ( { calmHubUrl : 'calmhub-file' } ) ;
453462
454- const options = await parseDocumentLoaderConfig ( {
463+ const options = await parseDocLoaderConfigForTest ( {
455464 calmHubUrl : 'calmhub-cli'
456465 } ) ;
457466 expect ( options . calmHubUrl ) . toEqual ( 'calmhub-cli' ) ;
458467 } ) ;
459468
460469 it ( 'should parse schemaDirectoryPath when provided' , async ( ) => {
461- const options = await parseDocumentLoaderConfig ( {
470+ const options = await parseDocLoaderConfigForTest ( {
462471 schemaDirectory : 'path'
463472 } ) ;
464473 expect ( options . schemaDirectoryPath ) . toEqual ( 'path' ) ;
465474 } ) ;
466475
476+ it ( 'should parse allowedRemoteHosts when provided' , async ( ) => {
477+ const options = await parseDocLoaderConfigForTest ( {
478+ allowedRemoteHosts : [ 'schemas.example.com' ]
479+ } ) ;
480+ expect ( options . allowedRemoteHosts ) . toEqual ( [ 'schemas.example.com' ] ) ;
481+ } ) ;
482+
483+ it ( 'should use allowedRemoteHosts from config when CLI does not provide them' , async ( ) => {
484+ cliConfigModule = await import ( './cli-config' ) ;
485+ vi . spyOn ( cliConfigModule , 'loadCliConfig' ) . mockResolvedValue ( {
486+ allowedRemoteHosts : [ 'config.example.com' ]
487+ } ) ;
488+
489+ const options = await parseDocLoaderConfigForTest ( { } ) ;
490+ expect ( options . allowedRemoteHosts ) . toEqual ( [ 'config.example.com' ] ) ;
491+ } ) ;
492+
493+ it ( 'should prefer CLI allowedRemoteHosts over config values' , async ( ) => {
494+ cliConfigModule = await import ( './cli-config' ) ;
495+ vi . spyOn ( cliConfigModule , 'loadCliConfig' ) . mockResolvedValue ( {
496+ allowedRemoteHosts : [ 'config.example.com' ]
497+ } ) ;
498+
499+ const options = await parseDocLoaderConfigForTest ( {
500+ allowedRemoteHosts : [ 'cli.example.com' ]
501+ } ) ;
502+ expect ( options . allowedRemoteHosts ) . toEqual ( [ 'cli.example.com' ] ) ;
503+ } ) ;
504+
467505 it ( 'should set debug to true when verbose passed along' , async ( ) => {
468- const options = await parseDocumentLoaderConfig ( {
506+ const options = await parseDocLoaderConfigForTest ( {
469507 verbose : true
470508 } ) ;
471509 expect ( options . debug ) . toBeTruthy ( ) ;
472510 } ) ;
473511
474512 it ( 'should default debug to false' , async ( ) => {
475- const options = await parseDocumentLoaderConfig ( {
513+ const options = await parseDocLoaderConfigForTest ( {
476514 } ) ;
477515 expect ( options . debug ) . toBeFalsy ( ) ;
478516 } ) ;
479- } ) ;
517+ } ) ;
0 commit comments