@@ -12,6 +12,7 @@ import {
1212 fixCapitalisedPlural ,
1313 toFieldName ,
1414 toQueryName ,
15+ inflektObject ,
1516} from '../src' ;
1617
1718describe ( 'singularize' , ( ) => {
@@ -198,3 +199,121 @@ describe('toQueryName', () => {
198199 expect ( toQueryName ( 'Category' ) ) . toBe ( 'categories' ) ;
199200 } ) ;
200201} ) ;
202+
203+ describe ( 'inflektObject' , ( ) => {
204+ it ( 'should convert kebab-case keys to camelCase' , ( ) => {
205+ const input = {
206+ 'schema-file' : 'test.graphql' ,
207+ 'dry-run' : true ,
208+ 'api-names' : [ 'api1' , 'api2' ] ,
209+ } ;
210+ const expected = {
211+ schemaFile : 'test.graphql' ,
212+ dryRun : true ,
213+ apiNames : [ 'api1' , 'api2' ] ,
214+ } ;
215+ expect ( inflektObject ( input ) ) . toEqual ( expected ) ;
216+ } ) ;
217+
218+ it ( 'should preserve camelCase keys' , ( ) => {
219+ const input = {
220+ endpoint : 'http://localhost:3000' ,
221+ output : './generated' ,
222+ verbose : false ,
223+ } ;
224+ expect ( inflektObject ( input ) ) . toEqual ( input ) ;
225+ } ) ;
226+
227+ it ( 'should handle mixed kebab-case and camelCase keys' , ( ) => {
228+ const input = {
229+ 'schema-file' : 'schema.graphql' ,
230+ endpoint : 'http://localhost:3000' ,
231+ 'react-query' : true ,
232+ output : './dist' ,
233+ 'browser-compatible' : false ,
234+ } ;
235+ const expected = {
236+ schemaFile : 'schema.graphql' ,
237+ endpoint : 'http://localhost:3000' ,
238+ reactQuery : true ,
239+ output : './dist' ,
240+ browserCompatible : false ,
241+ } ;
242+ expect ( inflektObject ( input ) ) . toEqual ( expected ) ;
243+ } ) ;
244+
245+ it ( 'should handle empty objects' , ( ) => {
246+ expect ( inflektObject ( { } ) ) . toEqual ( { } ) ;
247+ } ) ;
248+
249+ it ( 'should handle objects with various value types' , ( ) => {
250+ const input = {
251+ 'string-value' : 'test' ,
252+ 'number-value' : 42 ,
253+ 'boolean-value' : true ,
254+ 'null-value' : null as null ,
255+ 'undefined-value' : undefined as undefined ,
256+ 'array-value' : [ 1 , 2 , 3 ] ,
257+ 'object-value' : { nested : 'value' } ,
258+ } ;
259+ const expected = {
260+ stringValue : 'test' ,
261+ numberValue : 42 ,
262+ booleanValue : true ,
263+ nullValue : null as null ,
264+ undefinedValue : undefined as undefined ,
265+ arrayValue : [ 1 , 2 , 3 ] ,
266+ objectValue : { nested : 'value' } ,
267+ } ;
268+ expect ( inflektObject ( input ) ) . toEqual ( expected ) ;
269+ } ) ;
270+
271+ it ( 'should handle multiple consecutive hyphens' , ( ) => {
272+ const input = {
273+ 'multi-word-key-name' : 'value' ,
274+ } ;
275+ const expected = {
276+ multiWordKeyName : 'value' ,
277+ } ;
278+ expect ( inflektObject ( input ) ) . toEqual ( expected ) ;
279+ } ) ;
280+
281+ it ( 'should preserve single-word keys' , ( ) => {
282+ const input = {
283+ endpoint : 'url' ,
284+ schemas : [ 'public' ] ,
285+ orm : true ,
286+ } ;
287+ expect ( inflektObject ( input ) ) . toEqual ( input ) ;
288+ } ) ;
289+
290+ it ( 'should handle CLI argument conversion use case' , ( ) => {
291+ const argv = {
292+ endpoint : 'http://localhost:5000/graphql' ,
293+ 'schema-file' : undefined as string | undefined ,
294+ output : 'codegen' ,
295+ schemas : undefined as string [ ] | undefined ,
296+ 'api-names' : undefined as string [ ] | undefined ,
297+ 'react-query' : true ,
298+ orm : false ,
299+ 'browser-compatible' : true ,
300+ authorization : 'Bearer token123' ,
301+ 'dry-run' : false ,
302+ verbose : true ,
303+ } ;
304+ const expected = {
305+ endpoint : 'http://localhost:5000/graphql' ,
306+ schemaFile : undefined as string | undefined ,
307+ output : 'codegen' ,
308+ schemas : undefined as string [ ] | undefined ,
309+ apiNames : undefined as string [ ] | undefined ,
310+ reactQuery : true ,
311+ orm : false ,
312+ browserCompatible : true ,
313+ authorization : 'Bearer token123' ,
314+ dryRun : false ,
315+ verbose : true ,
316+ } ;
317+ expect ( inflektObject ( argv ) ) . toEqual ( expected ) ;
318+ } ) ;
319+ } ) ;
0 commit comments