@@ -52,10 +52,10 @@ describe('idl', () => {
5252 expect (
5353 schemaToIdl ( {
5454 schema : Schema ,
55- value : { username : 'David ' , status : { type : 'active' , owner : 'abc' } }
55+ value : { username : 'Hello ' , status : { type : 'active' , owner : 'abc' } }
5656 } )
5757 ) . toEqual ( {
58- username : 'David ' ,
58+ username : 'Hello ' ,
5959 status : { active : { owner : 'abc' } }
6060 } ) ;
6161 } ) ;
@@ -132,13 +132,94 @@ describe('idl', () => {
132132 expect (
133133 schemaFromIdl ( {
134134 schema : Schema ,
135- value : { username : 'David ' , status : { active : { owner : 'abc' } } }
135+ value : { username : 'Hello ' , status : { active : { owner : 'abc' } } }
136136 } )
137137 ) . toEqual ( {
138- username : 'David ' ,
138+ username : 'Hello ' ,
139139 status : { type : 'active' , owner : 'abc' }
140140 } ) ;
141141 } ) ;
142142 } ) ;
143143 } ) ;
144+
145+ describe ( 'camel case' , ( ) => {
146+ describe ( 'object with camelCase fields' , ( ) => {
147+ const Schema = z . object ( { firstName : z . string ( ) , lastName : z . string ( ) } ) ;
148+
149+ it ( 'converts camelCase keys to snake_case' , ( ) => {
150+ expect (
151+ schemaToIdl ( { schema : Schema , value : { firstName : 'Hello' , lastName : 'World' } } )
152+ ) . toEqual ( {
153+ first_name : 'Hello' ,
154+ last_name : 'World'
155+ } ) ;
156+ } ) ;
157+ } ) ;
158+
159+ describe ( 'object with camelCase fields' , ( ) => {
160+ const Schema = z . object ( { firstName : z . string ( ) , lastName : z . string ( ) } ) ;
161+
162+ it ( 'converts snake_case keys back to camelCase' , ( ) => {
163+ expect (
164+ schemaFromIdl ( { schema : Schema , value : { first_name : 'Hello' , last_name : 'World' } } )
165+ ) . toEqual ( {
166+ firstName : 'Hello' ,
167+ lastName : 'World'
168+ } ) ;
169+ } ) ;
170+ } ) ;
171+
172+ describe ( 'nested object with camelCase fields' , ( ) => {
173+ const Schema = z . object ( {
174+ userId : z . string ( ) ,
175+ userProfile : z . object ( { displayName : z . string ( ) } )
176+ } ) ;
177+
178+ it ( 'converts nested camelCase keys to snake_case' , ( ) => {
179+ expect (
180+ schemaToIdl ( {
181+ schema : Schema ,
182+ value : { userId : 'abc' , userProfile : { displayName : 'Hello' } }
183+ } )
184+ ) . toEqual ( {
185+ user_id : 'abc' ,
186+ user_profile : { display_name : 'Hello' }
187+ } ) ;
188+ } ) ;
189+
190+ it ( 'converts nested snake_case keys back to camelCase' , ( ) => {
191+ expect (
192+ schemaFromIdl ( {
193+ schema : Schema ,
194+ value : { user_id : 'abc' , user_profile : { display_name : 'Hello' } }
195+ } )
196+ ) . toEqual ( {
197+ userId : 'abc' ,
198+ userProfile : { displayName : 'Hello' }
199+ } ) ;
200+ } ) ;
201+ } ) ;
202+ } ) ;
203+
204+ describe ( 'snake_case fields' , ( ) => {
205+ const Schema = z . object ( { first_name : z . string ( ) , last_name : z . string ( ) } ) ;
206+
207+ it ( 'keeps snake_case keys unchanged in schemaToIdl' , ( ) => {
208+ expect (
209+ schemaToIdl ( { schema : Schema , value : { first_name : 'Hello' , last_name : 'World' } } )
210+ ) . toEqual ( {
211+ first_name : 'Hello' ,
212+ last_name : 'World'
213+ } ) ;
214+ } ) ;
215+
216+ it ( 'keeps snake_case keys unchanged in schemaFromIdl' , ( ) => {
217+ expect (
218+ schemaFromIdl ( { schema : Schema , value : { first_name : 'Hello' , last_name : 'World' } } )
219+ ) . toEqual ( {
220+ first_name : 'Hello' ,
221+ last_name : 'World'
222+ } ) ;
223+ } ) ;
224+ } ) ;
144225} ) ;
0 commit comments