Improve test smtp mail E2E test
This commit is contained in:
parent
d5be48a846
commit
e6c8eadc8c
2 changed files with 34 additions and 10 deletions
|
@ -25,14 +25,19 @@ abstract class Scope extends TestCase
|
||||||
$this->client = null;
|
$this->client = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getLastEmail(): array
|
protected function getLastEmail(int $limit = 1): array
|
||||||
{
|
{
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
$emails = json_decode(file_get_contents('http://maildev:1080/email'), true);
|
$emails = json_decode(file_get_contents('http://maildev:1080/email'), true);
|
||||||
|
|
||||||
if ($emails && is_array($emails)) {
|
if ($emails && is_array($emails)) {
|
||||||
return end($emails);
|
if($limit === 1) {
|
||||||
|
return end($emails);
|
||||||
|
} else {
|
||||||
|
$lastEmails = array_slice($emails, -1 * $limit);
|
||||||
|
return $lastEmails;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -579,25 +579,45 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group smtpAndTemplates
|
* @group smtpAndTemplates
|
||||||
* @depends testUpdateProjectSMTP
|
* @depends testCreateProject
|
||||||
*/
|
*/
|
||||||
public function testCreateProjectSMTPTests($data): array
|
public function testCreateProjectSMTPTests($data): array
|
||||||
{
|
{
|
||||||
$id = $data['projectId'];
|
$id = $data['projectId'];
|
||||||
$email = 'mailer@appwrite.io';
|
|
||||||
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
'email' => $email,
|
'emails' => [ 'testuser@appwrite.io', 'testusertwo@appwrite.io' ],
|
||||||
|
'senderEmail' => 'custommailer@appwrite.io',
|
||||||
|
'senderName' => 'Custom Mailer',
|
||||||
|
'replyTo' => 'reply@appwrite.io',
|
||||||
|
'host' => 'maildev',
|
||||||
|
'port' => 1025,
|
||||||
|
'username' => '',
|
||||||
|
'password' => '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(204, $response['headers']['status-code']);
|
$this->assertEquals(204, $response['headers']['status-code']);
|
||||||
|
|
||||||
$lastEmail = $this->getLastEmail();
|
$emails = $this->getLastEmail(2);
|
||||||
var_dump($lastEmail);
|
$this->assertCount(2, $emails);
|
||||||
$this->assertEquals($email, $lastEmail['to'][0]['address']);
|
$this->assertEquals('custommailer@appwrite.io', $emails[0]['from'][0]['address']);
|
||||||
$this->assertEquals('SMTP test email from Appwrite', $lastEmail['subject']);
|
$this->assertEquals('Custom Mailer', $emails[0]['from'][0]['name']);
|
||||||
|
$this->assertEquals('reply@appwrite.io', $emails[0]['replyTo'][0]['address']);
|
||||||
|
$this->assertEquals('Custom Mailer', $emails[0]['replyTo'][0]['name']);
|
||||||
|
$this->assertEquals('Custom SMTP email from Appwrite', $emails[0]['subject']);
|
||||||
|
$this->assertStringContainsStringIgnoringCase('good to go', $emails[0]['text']);
|
||||||
|
$this->assertStringContainsStringIgnoringCase('good to go', $emails[0]['html']);
|
||||||
|
|
||||||
|
$to = [
|
||||||
|
$emails[0]['to'][0]['address'],
|
||||||
|
$emails[1]['to'][0]['address']
|
||||||
|
];
|
||||||
|
\sort($to);
|
||||||
|
|
||||||
|
$this->assertEquals('testuser@appwrite.io', $to[0]);
|
||||||
|
$this->assertEquals('testusertwo@appwrite.io', $to[1]);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -1686,7 +1706,6 @@ var_dump($lastEmail);
|
||||||
|
|
||||||
foreach ($response['body'] as $key => $value) {
|
foreach ($response['body'] as $key => $value) {
|
||||||
if (\preg_match($pattern, $key)) {
|
if (\preg_match($pattern, $key)) {
|
||||||
\var_dump('Matched key: ' . $key);
|
|
||||||
$matches[$key] = $value;
|
$matches[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue