@@ -612,6 +612,95 @@ describe("validatePayload", () => {
612612 } ;
613613 expect ( ( ) => validatePayload ( payload ) ) . not . toThrow ( ) ;
614614 } ) ;
615+
616+ it ( "should throw error for string attachments" , ( ) => {
617+ const payload = {
618+ 619+ message : {
620+ subject : "Test Subject" ,
621+ text : "Test message" ,
622+ attachments : "invalid-string" ,
623+ } ,
624+ } ;
625+ expect ( ( ) => validatePayload ( payload ) ) . toThrow ( ValidationError ) ;
626+ expect ( ( ) => validatePayload ( payload ) ) . toThrow (
627+ "Invalid message configuration: Field 'message.attachments' must be an array"
628+ ) ;
629+ } ) ;
630+
631+ it ( "should throw error for number attachments" , ( ) => {
632+ const payload = {
633+ 634+ message : {
635+ subject : "Test Subject" ,
636+ text : "Test message" ,
637+ attachments : 123 ,
638+ } ,
639+ } ;
640+ expect ( ( ) => validatePayload ( payload ) ) . toThrow ( ValidationError ) ;
641+ expect ( ( ) => validatePayload ( payload ) ) . toThrow (
642+ "Invalid message configuration: Field 'message.attachments' must be an array"
643+ ) ;
644+ } ) ;
645+ } ) ;
646+ } ) ;
647+
648+ describe ( "error messages" , ( ) => {
649+ it ( "should provide clear error for empty template name" , ( ) => {
650+ const payload = {
651+ 652+ template : {
653+ name : "" ,
654+ } ,
655+ } ;
656+ expect ( ( ) => validatePayload ( payload ) ) . toThrow ( ValidationError ) ;
657+ expect ( ( ) => validatePayload ( payload ) ) . toThrow (
658+ "Invalid template configuration: Field 'template.name' cannot be empty"
659+ ) ;
660+ } ) ;
661+
662+ it ( "should provide clear error for empty UID in array" , ( ) => {
663+ const payload = {
664+ toUids : [ "valid-uid" , "" ] ,
665+ message : {
666+ subject : "Test" ,
667+ text : "Test" ,
668+ } ,
669+ } ;
670+ expect ( ( ) => validatePayload ( payload ) ) . toThrow ( ValidationError ) ;
671+ expect ( ( ) => validatePayload ( payload ) ) . toThrow (
672+ "Invalid email configuration: Field 'toUids.1' cannot be empty"
673+ ) ;
674+ } ) ;
675+
676+ it ( "should provide clear error for cc as number" , ( ) => {
677+ const payload = {
678+ 679+ cc : 123 ,
680+ message : {
681+ subject : "Test" ,
682+ text : "Test" ,
683+ } ,
684+ } ;
685+ expect ( ( ) => validatePayload ( payload ) ) . toThrow ( ValidationError ) ;
686+ expect ( ( ) => validatePayload ( payload ) ) . toThrow (
687+ "Invalid email configuration: Field 'cc' must be either a string or an array of strings"
688+ ) ;
689+ } ) ;
690+
691+ it ( "should provide clear error for bcc as boolean" , ( ) => {
692+ const payload = {
693+ 694+ bcc : true ,
695+ message : {
696+ subject : "Test" ,
697+ text : "Test" ,
698+ } ,
699+ } ;
700+ expect ( ( ) => validatePayload ( payload ) ) . toThrow ( ValidationError ) ;
701+ expect ( ( ) => validatePayload ( payload ) ) . toThrow (
702+ "Invalid email configuration: Field 'bcc' must be either a string or an array of strings"
703+ ) ;
615704 } ) ;
616705 } ) ;
617706} ) ;
0 commit comments