@@ -340,14 +340,63 @@ describe("content", () => {
340340 err . message ,
341341 "Invalid input! Failed to parse contents of the provided payload file" ,
342342 ) ;
343+ assert . isDefined ( err . cause ?. values ) ;
344+ assert . equal ( err . cause . values . length , 1 ) ;
343345 assert . include (
344- err . cause . message ,
346+ err . cause . values [ 0 ] . message ,
345347 "Invalid input! Failed to parse file extension unknown.md" ,
346348 ) ;
347349 } else {
348350 assert . fail ( "Failed to throw a SlackError" , err ) ;
349351 }
350352 }
351353 } ) ;
354+
355+ it ( "fails if invalid JSON exists in the input payload" , async ( ) => {
356+ mocks . core . getInput . withArgs ( "payload-file-path" ) . returns ( "example.json" ) ;
357+ mocks . fs . readFileSync
358+ . withArgs ( path . resolve ( "example.json" ) , "utf-8" )
359+ . returns ( `{
360+ "message": "a truncated file without an end` ) ;
361+ try {
362+ await send ( mocks . core ) ;
363+ assert . fail ( "Failed to throw for invalid JSON" ) ;
364+ } catch ( err ) {
365+ if ( err instanceof SlackError ) {
366+ assert . include (
367+ err . message ,
368+ "Invalid input! Failed to parse contents of the provided payload file" ,
369+ ) ;
370+ assert . isDefined ( err . cause ?. values ) ;
371+ assert . equal ( err . cause . values . length , 1 ) ;
372+ assert . isTrue ( err . cause . values [ 0 ] instanceof SyntaxError ) ;
373+ } else {
374+ assert . fail ( "Failed to throw a SlackError" , err ) ;
375+ }
376+ }
377+ } ) ;
378+
379+ it ( "fails if invalid YAML exists in the input payload" , async ( ) => {
380+ mocks . core . getInput . withArgs ( "payload-file-path" ) . returns ( "example.yaml" ) ;
381+ mocks . fs . readFileSync
382+ . withArgs ( path . resolve ( "example.yaml" ) , "utf-8" )
383+ . returns ( `- "message": "assigned": "values"` ) ;
384+ try {
385+ await send ( mocks . core ) ;
386+ assert . fail ( "Failed to throw for invalid YAML" ) ;
387+ } catch ( err ) {
388+ if ( err instanceof SlackError ) {
389+ assert . include (
390+ err . message ,
391+ "Invalid input! Failed to parse contents of the provided payload file" ,
392+ ) ;
393+ assert . isDefined ( err . cause ?. values ) ;
394+ assert . equal ( err . cause . values . length , 1 ) ;
395+ assert . isTrue ( err . cause . values [ 0 ] instanceof YAMLException ) ;
396+ } else {
397+ assert . fail ( "Failed to throw a SlackError" , err ) ;
398+ }
399+ }
400+ } ) ;
352401 } ) ;
353402} ) ;
0 commit comments