-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathResendTest.php
More file actions
182 lines (151 loc) · 5.32 KB
/
ResendTest.php
File metadata and controls
182 lines (151 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
namespace Utopia\Tests\Adapter\Email;
use Utopia\Messaging\Adapter\Email\Resend;
use Utopia\Messaging\Messages\Email;
use Utopia\Messaging\Messages\Email\Attachment;
use Utopia\Tests\Adapter\Base;
class ResendTest extends Base
{
private Resend $sender;
private string $testEmail;
protected function setUp(): void
{
parent::setUp();
$key = \getenv('RESEND_API_KEY');
$this->sender = new Resend($key);
$this->testEmail = \getenv('RESEND_TEST_EMAIL');
sleep(2);
}
public function testSendEmail(): void
{
$to = $this->testEmail;
$subject = 'Test Subject';
$content = 'Test Content';
$fromEmail = $this->testEmail;
$cc = [['email' => $this->testEmail]];
$bcc = [['name' => 'Test BCC', 'email' => $this->testEmail]];
$message = new Email(
to: [$to],
subject: $subject,
content: $content,
fromName: 'Test Sender',
fromEmail: $fromEmail,
cc: $cc,
bcc: $bcc,
);
$response = $this->sender->send($message);
$this->assertResponse($response);
}
public function testSendEmailWithHtml(): void
{
$to = $this->testEmail;
$subject = 'Test HTML Subject';
$content = '<h1>Test HTML Content</h1><p>This is a test email with HTML content.</p>';
$fromEmail = $this->testEmail;
$message = new Email(
to: [$to],
subject: $subject,
content: $content,
fromName: 'Test Sender',
fromEmail: $fromEmail,
html: true,
);
$response = $this->sender->send($message);
$this->assertResponse($response);
}
public function testSendEmailWithReplyTo(): void
{
$to = $this->testEmail;
$subject = 'Test Reply-To Subject';
$content = 'Test Content with Reply-To';
$fromEmail = $this->testEmail;
$replyToEmail = $this->testEmail;
$message = new Email(
to: [$to],
subject: $subject,
content: $content,
fromName: 'Test Sender',
fromEmail: $fromEmail,
replyToName: 'Reply To Name',
replyToEmail: $replyToEmail,
);
$response = $this->sender->send($message);
$this->assertResponse($response);
}
public function testSendMultipleEmails(): void
{
$to1 = $this->testEmail;
$to2 = $this->testEmail;
$subject = 'Test Batch Subject';
$content = 'Test Batch Content';
$fromEmail = $this->testEmail;
$message = new Email(
to: [$to1, $to2],
subject: $subject,
content: $content,
fromName: 'Test Sender',
fromEmail: $fromEmail,
);
$response = $this->sender->send($message);
$this->assertEquals(2, $response['deliveredTo'], \var_export($response, true));
$this->assertEquals('', $response['results'][0]['error'], \var_export($response, true));
$this->assertEquals('success', $response['results'][0]['status'], \var_export($response, true));
$this->assertEquals('', $response['results'][1]['error'], \var_export($response, true));
$this->assertEquals('success', $response['results'][1]['status'], \var_export($response, true));
}
public function testSendEmailWithFileAttachment(): void
{
$message = new Email(
to: [$this->testEmail],
subject: 'Test File Attachment',
content: 'Test Content with file attachment',
fromName: 'Test Sender',
fromEmail: $this->testEmail,
attachments: [new Attachment(
name: 'image.png',
path: __DIR__.'/../../../assets/image.png',
type: 'image/png'
)],
);
$response = $this->sender->send($message);
$this->assertResponse($response);
}
public function testSendEmailWithStringAttachment(): void
{
$message = new Email(
to: [$this->testEmail],
subject: 'Test String Attachment',
content: 'Test Content with string attachment',
fromName: 'Test Sender',
fromEmail: $this->testEmail,
attachments: [new Attachment(
name: 'test.txt',
path: '',
type: 'text/plain',
content: 'Hello, this is a test attachment.',
)],
);
$response = $this->sender->send($message);
$this->assertResponse($response);
}
public function testSendEmailWithAttachmentExceedingMaxSize(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Total attachment size exceeds');
$largeContent = \str_repeat('x', 25 * 1024 * 1024 + 1);
$message = new Email(
to: [$this->testEmail],
subject: 'Test Oversized Attachment',
content: 'Test Content',
fromName: 'Test Sender',
fromEmail: $this->testEmail,
attachments: [new Attachment(
name: 'large.bin',
path: '',
type: 'application/octet-stream',
content: $largeContent,
)],
);
$this->sender->send($message);
}
}