@@ -144,6 +144,57 @@ describe("getStringArg", () => {
144144 "`name` argument is required and must not be empty or whitespace-only. (type string)" ,
145145 ) ;
146146 } ) ;
147+
148+ it ( "should convert parsed JSON object to string for contents parameter" , ( ) => {
149+ // This simulates the case where JSON.parse() has converted a JSON string into an object
150+ const args = { contents : { key : "value" , number : 123 } } ;
151+ const result = getStringArg ( args , "contents" ) ;
152+ expect ( result ) . toBe ( '{"key":"value","number":123}' ) ;
153+ } ) ;
154+
155+ it ( "should convert nested JSON object to string for contents parameter" , ( ) => {
156+ const args = {
157+ contents : {
158+ user : {
159+ name : "John" ,
160+ details : {
161+ age : 30 ,
162+ preferences : [ "coding" , "reading" ] ,
163+ } ,
164+ } ,
165+ } ,
166+ } ;
167+ const result = getStringArg ( args , "contents" ) ;
168+ const expected =
169+ '{"user":{"name":"John","details":{"age":30,"preferences":["coding","reading"]}}}' ;
170+ expect ( result ) . toBe ( expected ) ;
171+ } ) ;
172+
173+ it ( "should convert JSON array to string for contents parameter" , ( ) => {
174+ const args = { contents : [ "item1" , "item2" , { key : "value" } ] } ;
175+ const result = getStringArg ( args , "contents" ) ;
176+ expect ( result ) . toBe ( '["item1","item2",{"key":"value"}]' ) ;
177+ } ) ;
178+
179+ it ( "should throw error when non-contents parameter is an object" , ( ) => {
180+ const args = { filename : { invalid : "object" } } ;
181+ expect ( ( ) => getStringArg ( args , "filename" ) ) . toThrowError (
182+ "Argument `filename` must be a string, not an object" ,
183+ ) ;
184+ } ) ;
185+
186+ it ( "should handle contents parameter that is already a string" , ( ) => {
187+ const args = { contents : "already a string" } ;
188+ const result = getStringArg ( args , "contents" ) ;
189+ expect ( result ) . toBe ( "already a string" ) ;
190+ } ) ;
191+
192+ it ( "should handle contents parameter that is null" , ( ) => {
193+ const args = { contents : null } ;
194+ expect ( ( ) => getStringArg ( args , "contents" ) ) . toThrowError (
195+ "`contents` argument is required and must not be empty or whitespace-only. (type string)" ,
196+ ) ;
197+ } ) ;
147198} ) ;
148199
149200describe ( "getOptionalStringArg" , ( ) => {
0 commit comments