@@ -156,3 +156,101 @@ def test_email_send_with_inline_attachment(self) -> None:
156156 }
157157 email : resend .Emails .SendResponse = resend .Emails .send (params )
158158 assert email ["id" ] == "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
159+
160+ def test_email_list (self ) -> None :
161+ self .set_mock_json (
162+ {
163+ "object" : "list" ,
164+ "data" : [
165+ {
166+ "id" : "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" ,
167+ "to" : ["james@bond.com" ],
168+ "from" : "onboarding@resend.dev" ,
169+ "created_at" : "2023-04-03T22:13:42.674981+00:00" ,
170+ "subject" : "Hello World" ,
171+ "html" : "Congrats on sending your <strong>first email</strong>!" ,
172+ "text" : None ,
173+ "bcc" : [None ],
174+ "cc" : [None ],
175+ "reply_to" : [None ],
176+ "last_event" : "delivered" ,
177+ },
178+ {
179+ "id" : "5ef9a417-02e9-4d39-ad75-9611e0fcc33d" ,
180+ "to" : ["test@example.com" ],
181+ "from" : "hello@resend.dev" ,
182+ "created_at" : "2023-04-04T10:15:42.674981+00:00" ,
183+ "subject" : "Test Email" ,
184+ "html" : "This is a test email" ,
185+ "text" : "This is a test email" ,
186+ "bcc" : [None ],
187+ "cc" : [None ],
188+ "reply_to" : [None ],
189+ "last_event" : "sent" ,
190+ },
191+ ],
192+ "has_more" : True ,
193+ }
194+ )
195+
196+ emails : resend .Emails .ListResponse = resend .Emails .list ()
197+ assert emails ["object" ] == "list"
198+ assert len (emails ["data" ]) == 2
199+ assert emails ["has_more" ] == True
200+ assert emails ["data" ][0 ]["id" ] == "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"
201+ assert emails ["data" ][1 ]["id" ] == "5ef9a417-02e9-4d39-ad75-9611e0fcc33d"
202+
203+ def test_email_list_with_params (self ) -> None :
204+ self .set_mock_json (
205+ {
206+ "object" : "list" ,
207+ "data" : [
208+ {
209+ "id" : "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" ,
210+ "to" : ["james@bond.com" ],
211+ "from" : "onboarding@resend.dev" ,
212+ "created_at" : "2023-04-03T22:13:42.674981+00:00" ,
213+ "subject" : "Hello World" ,
214+ "html" : "Congrats on sending your <strong>first email</strong>!" ,
215+ "text" : None ,
216+ "bcc" : [None ],
217+ "cc" : [None ],
218+ "reply_to" : [None ],
219+ "last_event" : "delivered" ,
220+ },
221+ ],
222+ "has_more" : False ,
223+ }
224+ )
225+
226+ list_params : resend .Emails .ListParams = {
227+ "limit" : 10 ,
228+ "after" : "cursor123" ,
229+ }
230+ emails : resend .Emails .ListResponse = resend .Emails .list (params = list_params )
231+ assert emails ["object" ] == "list"
232+ assert len (emails ["data" ]) == 1
233+ assert emails ["has_more" ] == False
234+
235+ def test_email_list_with_before_param (self ) -> None :
236+ self .set_mock_json (
237+ {
238+ "object" : "list" ,
239+ "data" : [],
240+ "has_more" : False ,
241+ }
242+ )
243+
244+ list_params : resend .Emails .ListParams = {
245+ "limit" : 5 ,
246+ "before" : "cursor456" ,
247+ }
248+ emails : resend .Emails .ListResponse = resend .Emails .list (params = list_params )
249+ assert emails ["object" ] == "list"
250+ assert len (emails ["data" ]) == 0
251+ assert emails ["has_more" ] == False
252+
253+ def test_should_list_email_raise_exception_when_no_content (self ) -> None :
254+ self .set_mock_json (None )
255+ with self .assertRaises (NoContentError ):
256+ _ = resend .Emails .list ()
0 commit comments