@@ -144,6 +144,50 @@ 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 handle contents parameter that is already a string" , ( ) => {
180+ const args = { contents : "already a string" } ;
181+ const result = getStringArg ( args , "contents" ) ;
182+ expect ( result ) . toBe ( "already a string" ) ;
183+ } ) ;
184+
185+ it ( "should handle contents parameter that is null" , ( ) => {
186+ const args = { contents : null } ;
187+ expect ( ( ) => getStringArg ( args , "contents" ) ) . toThrowError (
188+ "`contents` argument is required and must not be empty or whitespace-only. (type string)" ,
189+ ) ;
190+ } ) ;
147191} ) ;
148192
149193describe ( "getOptionalStringArg" , ( ) => {
0 commit comments