@@ -63,7 +63,7 @@ def test_batch_email_send_with_options(self) -> None:
6363 },
6464 ]
6565
66- options : resend .Emails .SendOptions = {
66+ options : resend .Batch .SendOptions = {
6767 "idempotency_key" : "af477dc78aa9fa91fff3b8c0d4a2e1a5" ,
6868 }
6969
@@ -90,3 +90,80 @@ def test_should_send_batch_email_raise_exception_when_no_content(self) -> None:
9090 ]
9191 with self .assertRaises (NoContentError ):
9292 _ = resend .Batch .send (params )
93+
94+ def test_batch_email_send_with_strict_validation_mode (self ) -> None :
95+ self .set_mock_json (
96+ {
97+ "data" : [
98+ {"id" : "ae2014de-c168-4c61-8267-70d2662a1ce1" },
99+ {"id" : "faccb7a5-8a28-4e9a-ac64-8da1cc3bc1cb" },
100+ ]
101+ }
102+ )
103+
104+ params : List [resend .Emails .SendParams ] = [
105+ {
106+ "from" : "from@resend.dev" ,
107+ "to" : ["to@resend.dev" ],
108+ "subject" : "hey" ,
109+ "html" : "<strong>hello, world!</strong>" ,
110+ },
111+ {
112+ "from" : "from@resend.dev" ,
113+ "to" : ["to@resend.dev" ],
114+ "subject" : "hello" ,
115+ "html" : "<strong>hello, world!</strong>" ,
116+ },
117+ ]
118+
119+ options : resend .Batch .SendOptions = {
120+ "batch_validation" : "strict" ,
121+ }
122+
123+ emails : resend .Batch .SendResponse = resend .Batch .send (params , options = options )
124+ assert len (emails ["data" ]) == 2
125+ assert emails ["data" ][0 ]["id" ] == "ae2014de-c168-4c61-8267-70d2662a1ce1"
126+ assert emails ["data" ][1 ]["id" ] == "faccb7a5-8a28-4e9a-ac64-8da1cc3bc1cb"
127+ assert "errors" not in emails
128+
129+ def test_batch_email_send_with_permissive_validation_mode (self ) -> None :
130+ self .set_mock_json (
131+ {
132+ "data" : [
133+ {"id" : "ae2014de-c168-4c61-8267-70d2662a1ce1" },
134+ ],
135+ "errors" : [
136+ {
137+ "index" : 1 ,
138+ "message" : "The `to` field is missing." ,
139+ }
140+ ],
141+ }
142+ )
143+
144+ params : List [resend .Emails .SendParams ] = [
145+ {
146+ "from" : "from@resend.dev" ,
147+ "to" : ["to@resend.dev" ],
148+ "subject" : "hey" ,
149+ "html" : "<strong>hello, world!</strong>" ,
150+ },
151+ {
152+ "from" : "from@resend.dev" ,
153+ "to" : [],
154+ "subject" : "hello" ,
155+ "html" : "<strong>hello, world!</strong>" ,
156+ },
157+ ]
158+
159+ options : resend .Batch .SendOptions = {
160+ "batch_validation" : "permissive" ,
161+ }
162+
163+ emails : resend .Batch .SendResponse = resend .Batch .send (params , options = options )
164+ assert len (emails ["data" ]) == 1
165+ assert emails ["data" ][0 ]["id" ] == "ae2014de-c168-4c61-8267-70d2662a1ce1"
166+ assert "errors" in emails
167+ assert len (emails ["errors" ]) == 1
168+ assert emails ["errors" ][0 ]["index" ] == 1
169+ assert emails ["errors" ][0 ]["message" ] == "The `to` field is missing."
0 commit comments