1- const { listFiles, buildParams } = require ( '@asyncapi/generator-helpers' ) ;
1+ const { listFiles, buildParams, hasNestedConfig } = require ( '@asyncapi/generator-helpers' ) ;
22const fs = require ( 'fs/promises' ) ;
33
4- jest . mock ( 'fs/promises' ) ;
4+ jest . mock ( 'fs/promises' , ( ) => ( {
5+ rm : jest . fn ( ) ,
6+ readdir : jest . fn ( ) ,
7+ } ) ) ;
58
69describe ( 'listFiles' , ( ) => {
710 afterEach ( ( ) => {
@@ -33,6 +36,57 @@ describe('listFiles', () => {
3336 } ) ;
3437} ) ;
3538
39+ describe ( 'hasNestedConfig' , ( ) => {
40+ it ( 'should return false for an empty object' , ( ) => {
41+ expect ( hasNestedConfig ( { } ) ) . toBe ( false ) ;
42+ } ) ;
43+
44+ it ( 'should return false when all values are primitives' , ( ) => {
45+ const config = { host : 'localhost' , port : 8080 , secure : false } ;
46+ expect ( hasNestedConfig ( config ) ) . toBe ( false ) ;
47+ } ) ;
48+
49+ it ( 'should return true when there is a nested object' , ( ) => {
50+ const config = { db : { user : 'admin' , pass : 'secret' } } ;
51+ expect ( hasNestedConfig ( config ) ) . toBe ( true ) ;
52+ } ) ;
53+
54+ it ( 'should return true when there are multiple nested objects' , ( ) => {
55+ const config = {
56+ db : { user : 'admin' } ,
57+ cache : { enabled : true }
58+ } ;
59+ expect ( hasNestedConfig ( config ) ) . toBe ( true ) ;
60+ } ) ;
61+
62+ it ( 'should return true when a value is an array' , ( ) => {
63+ const config = { servers : [ 's1' , 's2' ] } ;
64+ expect ( hasNestedConfig ( config ) ) . toBe ( true ) ;
65+ } ) ;
66+
67+ it ( 'should return false when a value is null' , ( ) => {
68+ const config = { host : null , port : 3000 } ;
69+ expect ( hasNestedConfig ( config ) ) . toBe ( false ) ;
70+ } ) ;
71+
72+ it ( 'should returns true when config contains both nested objects and primitive values' , ( ) => {
73+ const config = {
74+ host : 'localhost' ,
75+ db : { name : 'testdb' } ,
76+ retries : 3
77+ } ;
78+ expect ( hasNestedConfig ( config ) ) . toBe ( true ) ;
79+ } ) ;
80+
81+ it ( 'should handle nested arrays inside objects' , ( ) => {
82+ const config = {
83+ metadata : {
84+ tags : [ 'tag1' , 'tag2' ]
85+ }
86+ } ;
87+ expect ( hasNestedConfig ( config ) ) . toBe ( true ) ;
88+ } ) ;
89+ } ) ;
3690describe ( 'buildParams' , ( ) => {
3791 it ( 'should include clientFileName when language is not java' , ( ) => {
3892 const config = { clientFileName : 'myClient.js' } ;
@@ -85,4 +139,4 @@ describe('buildParams', () => {
85139 clientFileName : 'client.js' ,
86140 } ) ;
87141 } ) ;
88- } ) ;
142+ } ) ;
0 commit comments