@@ -261,6 +261,176 @@ describe("oasDiffChangelog", () => {
261261 expect ( execSyncStub . callCount ) . to . equal ( 2 ) ;
262262 } ) ;
263263
264+ it ( "should report deleted APIs when directories exist in base but not in new" , async ( ) => {
265+ const execSyncStub = sinon . stub ( ) ;
266+ execSyncStub . onCall ( 0 ) . returns ( "version 1.0.0" ) ;
267+
268+ const fsStub = {
269+ readdir : sinon . stub ( ) ,
270+ stat : sinon . stub ( ) ,
271+ writeFile : sinon . stub ( ) ,
272+ } ;
273+
274+ // Base has api-v1 and api-v2, new only has api-v1
275+ fsStub . readdir . onCall ( 0 ) . returns ( [ "api-v1" , "api-v2" ] ) ; // base directories
276+ fsStub . readdir . onCall ( 1 ) . returns ( [ "api-v2" ] ) ; // new directories
277+
278+ // All stat calls return isDirectory true
279+ fsStub . stat . returns ( { isDirectory : ( ) => true } ) ;
280+
281+ const oasDiff = pq ( "./oasDiff" , {
282+ child_process : {
283+ execSync : execSyncStub ,
284+ } ,
285+ "fs-extra" : fsStub ,
286+ } ) ;
287+
288+ const baseApi = "base" ;
289+ const newApi = "new" ;
290+ const flags = {
291+ "out-file" : "output.txt" ,
292+ dir : true ,
293+ } ;
294+
295+ await oasDiff . oasDiffChangelog ( baseApi , newApi , flags ) ;
296+
297+ expect ( fsStub . writeFile . called ) . to . be . true ;
298+ const writtenContent = fsStub . writeFile . args [ 0 ] [ 1 ] ;
299+ expect ( writtenContent ) . to . include ( "======api-v1 API is deleted======" ) ;
300+ } ) ;
301+
302+ it ( "should report added APIs when directories exist in new but not in base" , async ( ) => {
303+ const execSyncStub = sinon . stub ( ) ;
304+ execSyncStub . onCall ( 0 ) . returns ( "version 1.0.0" ) ;
305+
306+ const fsStub = {
307+ readdir : sinon . stub ( ) ,
308+ stat : sinon . stub ( ) ,
309+ writeFile : sinon . stub ( ) ,
310+ } ;
311+
312+ // Base has only api-v1, new has api-v1 and api-v2
313+ fsStub . readdir . onCall ( 0 ) . returns ( [ "api-v1" ] ) ; // base directories
314+ fsStub . readdir . onCall ( 1 ) . returns ( [ "api-v1" , "api-v2" ] ) ; // new directories
315+
316+ // All stat calls return isDirectory true
317+ fsStub . stat . returns ( { isDirectory : ( ) => true } ) ;
318+
319+ const oasDiff = pq ( "./oasDiff" , {
320+ child_process : {
321+ execSync : execSyncStub ,
322+ } ,
323+ "fs-extra" : fsStub ,
324+ } ) ;
325+
326+ const baseApi = "base" ;
327+ const newApi = "new" ;
328+ const flags = {
329+ "out-file" : "output.txt" ,
330+ dir : true ,
331+ } ;
332+
333+ await oasDiff . oasDiffChangelog ( baseApi , newApi , flags ) ;
334+
335+ expect ( fsStub . writeFile . called ) . to . be . true ;
336+ const writtenContent = fsStub . writeFile . args [ 0 ] [ 1 ] ;
337+ expect ( writtenContent ) . to . include ( "======api-v2 API is added======" ) ;
338+ } ) ;
339+
340+ it ( "should report both added and deleted APIs in the same comparison" , async ( ) => {
341+ const execSyncStub = sinon . stub ( ) ;
342+ execSyncStub . onCall ( 0 ) . returns ( "version 1.0.0" ) ;
343+ execSyncStub . onCall ( 1 ) . returns ( "changes in api-v1" ) ;
344+
345+ const fsStub = {
346+ readdir : sinon . stub ( ) ,
347+ stat : sinon . stub ( ) ,
348+ writeFile : sinon . stub ( ) ,
349+ } ;
350+
351+ // Base has api-v1 and api-v2, new has api-v1 and api-v3
352+ fsStub . readdir . onCall ( 0 ) . returns ( [ "api-v1" , "api-v2" ] ) ; // base directories
353+ fsStub . readdir . onCall ( 1 ) . returns ( [ "api-v2" , "api-v3" ] ) ; // new directories
354+
355+ // All stat calls return isDirectory true
356+ fsStub . stat . returns ( { isDirectory : ( ) => true } ) ;
357+
358+ const oasDiff = pq ( "./oasDiff" , {
359+ child_process : {
360+ execSync : execSyncStub ,
361+ } ,
362+ "fs-extra" : fsStub ,
363+ } ) ;
364+
365+ const baseApi = "base" ;
366+ const newApi = "new" ;
367+ const flags = {
368+ "out-file" : "output.txt" ,
369+ dir : true ,
370+ } ;
371+
372+ await oasDiff . oasDiffChangelog ( baseApi , newApi , flags ) ;
373+
374+ expect ( fsStub . writeFile . called ) . to . be . true ;
375+ const writtenContent = fsStub . writeFile . args [ 0 ] [ 1 ] ;
376+ expect ( writtenContent ) . to . include ( "======api-v1 API is deleted======" ) ;
377+ expect ( writtenContent ) . to . include ( "======api-v3 API is added======" ) ;
378+ expect ( writtenContent ) . to . include ( "=== Changes in api-v2 ===" ) ;
379+ } ) ;
380+
381+ it ( "should handle mixed scenarios with changes, additions, and deletions" , async ( ) => {
382+ const execSyncStub = sinon . stub ( ) ;
383+ execSyncStub . onCall ( 0 ) . returns ( "version 1.0.0" ) ;
384+ execSyncStub . onCall ( 1 ) . returns ( "changes in common-api" ) ;
385+ execSyncStub . onCall ( 2 ) . returns ( "" ) ; // no changes in stable-api
386+
387+ const fsStub = {
388+ readdir : sinon . stub ( ) ,
389+ stat : sinon . stub ( ) ,
390+ writeFile : sinon . stub ( ) ,
391+ } ;
392+
393+ // Base: common-api, stable-api, old-api
394+ // New: common-api, stable-api, new-api
395+ fsStub . readdir . onCall ( 0 ) . returns ( [ "common-api" , "stable-api" , "old-api" ] ) ; // base
396+ fsStub . readdir . onCall ( 1 ) . returns ( [ "common-api" , "stable-api" , "new-api" ] ) ; // new
397+
398+ // All stat calls return isDirectory true
399+ fsStub . stat . returns ( { isDirectory : ( ) => true } ) ;
400+
401+ const oasDiff = pq ( "./oasDiff" , {
402+ child_process : {
403+ execSync : execSyncStub ,
404+ } ,
405+ "fs-extra" : fsStub ,
406+ } ) ;
407+
408+ const baseApi = "base" ;
409+ const newApi = "new" ;
410+ const flags = {
411+ "out-file" : "output.txt" ,
412+ dir : true ,
413+ } ;
414+
415+ await oasDiff . oasDiffChangelog ( baseApi , newApi , flags ) ;
416+
417+ expect ( fsStub . writeFile . called ) . to . be . true ;
418+ const writtenContent = fsStub . writeFile . args [ 0 ] [ 1 ] ;
419+
420+ // Should show deleted API
421+ expect ( writtenContent ) . to . include ( "======old-api API is deleted======" ) ;
422+
423+ // Should show added API
424+ expect ( writtenContent ) . to . include ( "======new-api API is added======" ) ;
425+
426+ // Should show changes in common-api
427+ expect ( writtenContent ) . to . include ( "=== Changes in common-api ===" ) ;
428+ expect ( writtenContent ) . to . include ( "changes in common-api" ) ;
429+
430+ // Should NOT show stable-api since it has no changes
431+ expect ( writtenContent ) . to . not . include ( "=== Changes in stable-api ===" ) ;
432+ } ) ;
433+
264434 it ( "should throw an error if oasdiff is not installed" , ( ) => {
265435 const oasDiff = pq ( "./oasDiff" , {
266436 child_process : {
0 commit comments