Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiragAgg5k committed Feb 17, 2025
1 parent cec2956 commit c42b0d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/Utopia/Messaging/Adapter/Email/SMTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ protected function process(EmailMessage $message): array

if ($sent) {
$response->setDeliveredTo(\count($message->getTo()));

if (empty($message->getTo())) {
$response->setDeliveredTo(\count($message->getBCC()));
}
}

foreach ($message->getTo() as $to) {
Expand All @@ -132,6 +136,12 @@ protected function process(EmailMessage $message): array
$response->addResult($to, $sent ? '' : $error);
}

if (empty($message->getTo())) {
foreach ($message->getBCC() as $bcc) {
$response->addResult($bcc['email'], $sent ? '' : 'Unknown error');
}
}

return $response->toArray();
}
}
20 changes: 14 additions & 6 deletions tests/Messaging/Adapter/Email/SMTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public function testSendEmail(): void
content: $content,
fromName: $fromName,
fromEmail: $fromEmail,
bcc: [
[
'email' => 'tester2@localhost.test',
'name' => 'Test Recipient 2',
],
],
);

$response = $sender->send($message);
Expand All @@ -54,7 +60,6 @@ public function testSendEmailWithAttachment(): void
$fromName = 'Test Sender';
$fromEmail = 'sender@localhost.test';


$message = new Email(
to: [$to],
subject: $subject,
Expand Down Expand Up @@ -94,8 +99,8 @@ public function testSendEmailOnlyBCC(): void
$fromEmail = 'sender@localhost.test';
$bcc = [
[
'email' => 'tester@localhost.test',
'name' => 'Test Recipient',
'email' => 'tester2@localhost.test',
'name' => 'Test Recipient 2',
],
];

Expand All @@ -110,8 +115,11 @@ public function testSendEmailOnlyBCC(): void

$response = $sender->send($message);

$this->assertEquals(0, $response['deliveredTo'], \var_export($response, true));
$this->assertEquals('email', $response['type'], \var_export($response, true));
$this->assertEquals('', $response['results'][0]['error'], \var_export($response, true));
$lastEmail = $this->getLastEmail();

$this->assertResponse($response);
$this->assertEquals($fromEmail, $lastEmail['from'][0]['address']);
$this->assertEquals($subject, $lastEmail['subject']);
$this->assertEquals($content, \trim($lastEmail['text']));
}
}

0 comments on commit c42b0d3

Please sign in to comment.