-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathResendTest.php
More file actions
143 lines (118 loc) · 4.11 KB
/
ResendTest.php
File metadata and controls
143 lines (118 loc) · 4.11 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
<?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->assertSame(2, $response['deliveredTo'], \var_export($response, true));
$this->assertSame('', $response['results'][0]['error'], \var_export($response, true));
$this->assertSame('success', $response['results'][0]['status'], \var_export($response, true));
$this->assertSame('', $response['results'][1]['error'], \var_export($response, true));
$this->assertSame('success', $response['results'][1]['status'], \var_export($response, true));
}
public function testSendEmailWithAttachmentsThrowsException(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Resend does not support attachments at this time');
$to = $this->testEmail;
$subject = 'Test Subject';
$content = 'Test Content';
$fromEmail = $this->testEmail;
$message = new Email(
to: [$to],
subject: $subject,
content: $content,
fromName: 'Test Sender',
fromEmail: $fromEmail,
attachments: [new Attachment(
name: 'image.png',
path: __DIR__.'/../../../assets/image.png',
type: 'image/png'
)],
);
$this->sender->send($message);
}
}