11import { yellow } from 'colorette' ;
22import { detectSpec } from '@redocly/openapi-core' ;
33import { handleJoin } from '../../commands/join' ;
4- import { exitWithError , writeToFileByExtension } from '../../utils/miscellaneous' ;
4+ import {
5+ exitWithError ,
6+ getFallbackApisOrExit ,
7+ writeToFileByExtension ,
8+ } from '../../utils/miscellaneous' ;
59import { loadConfig } from '../../__mocks__/@redocly/openapi-core' ;
610import { ConfigFixture } from '../fixtures/config' ;
711
@@ -15,7 +19,35 @@ describe('handleJoin', () => {
1519
1620 it ( 'should call exitWithError because only one entrypoint' , async ( ) => {
1721 await handleJoin ( { argv : { apis : [ 'first.yaml' ] } , config : { } as any , version : 'cli-version' } ) ;
18- expect ( exitWithError ) . toHaveBeenCalledWith ( `At least 2 apis should be provided.` ) ;
22+ expect ( exitWithError ) . toHaveBeenCalledWith ( `At least 2 APIs should be provided.` ) ;
23+ } ) ;
24+
25+ it ( 'should call exitWithError if glob expands to less than 2 APIs' , async ( ) => {
26+ ( getFallbackApisOrExit as jest . Mock ) . mockResolvedValueOnce ( [ { path : 'first.yaml' } ] ) ;
27+
28+ await handleJoin ( {
29+ argv : { apis : [ '*.yaml' ] } ,
30+ config : { } as any ,
31+ version : 'cli-version' ,
32+ } ) ;
33+
34+ expect ( exitWithError ) . toHaveBeenCalledWith ( `At least 2 APIs should be provided.` ) ;
35+ } ) ;
36+
37+ it ( 'should proceed if glob expands to 2 or more APIs' , async ( ) => {
38+ ( detectSpec as jest . Mock ) . mockReturnValue ( 'oas3_1' ) ;
39+ ( getFallbackApisOrExit as jest . Mock ) . mockResolvedValueOnce ( [
40+ { path : 'first.yaml' } ,
41+ { path : 'second.yaml' } ,
42+ ] ) ;
43+
44+ await handleJoin ( {
45+ argv : { apis : [ '*.yaml' ] } ,
46+ config : ConfigFixture as any ,
47+ version : 'cli-version' ,
48+ } ) ;
49+
50+ expect ( exitWithError ) . not . toHaveBeenCalled ( ) ;
1951 } ) ;
2052
2153 it ( 'should call exitWithError because passed all 3 options for tags' , async ( ) => {
@@ -52,6 +84,7 @@ describe('handleJoin', () => {
5284 } ) ;
5385
5486 it ( 'should call exitWithError because Only OpenAPI 3.0 and OpenAPI 3.1 are supported' , async ( ) => {
87+ ( detectSpec as jest . Mock ) . mockReturnValueOnce ( 'oas2_0' ) ;
5588 await handleJoin ( {
5689 argv : {
5790 apis : [ 'first.yaml' , 'second.yaml' ] ,
0 commit comments