tests and fixes
This commit is contained in:
parent
16c708cd74
commit
ae549a1e9a
6 changed files with 87 additions and 8 deletions
|
@ -1800,9 +1800,10 @@ App::get('/v1/projects/:projectId/templates/email/:type/:locale')
|
|||
$template = $templates['email.' . $type . '-' . $locale] ?? null;
|
||||
|
||||
if (is_null($template)) {
|
||||
$localeFormated = substr($locale, 0, 2);
|
||||
$template = [
|
||||
'message' => Template::fromFile(__DIR__ . '/../../config/locale/templates/email-base.tpl'),
|
||||
'subject' => (new Locale($locale))->getText('emails.' . $type . '.subject'),
|
||||
'message' => Template::fromFile(__DIR__ . '/../../config/locale/templates/email-base.tpl')->render(),
|
||||
'subject' => (new Locale($localeFormated))->getText('emails.' . $type . '.subject'),
|
||||
'senderEmail' => App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', ''),
|
||||
'senderName' => App::getEnv('_APP_SYSTEM_EMAIL_NAME', '')
|
||||
];
|
||||
|
|
|
@ -74,7 +74,7 @@ use Appwrite\Utopia\Response\Model\HealthVersion;
|
|||
use Appwrite\Utopia\Response\Model\Mock; // Keep last
|
||||
use Appwrite\Utopia\Response\Model\Provider;
|
||||
use Appwrite\Utopia\Response\Model\Runtime;
|
||||
use Appwrite\Utopia\Response\Model\Template;
|
||||
use Appwrite\Utopia\Response\Model\SmsTemplate;
|
||||
use Appwrite\Utopia\Response\Model\UsageBuckets;
|
||||
use Appwrite\Utopia\Response\Model\UsageCollection;
|
||||
use Appwrite\Utopia\Response\Model\UsageDatabase;
|
||||
|
@ -345,7 +345,7 @@ class Response extends SwooleResponse
|
|||
->setModel(new UsageFunctions())
|
||||
->setModel(new UsageFunction())
|
||||
->setModel(new UsageProject())
|
||||
->setModel(new Template())
|
||||
->setModel(new SmsTemplate())
|
||||
->setModel(new EmailTemplate())
|
||||
// Verification
|
||||
// Recovery
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class EmailTemplate extends Template
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this
|
||||
->addRule('senderName', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class SmsTemplate extends Model
|
||||
class SmsTemplate extends Template
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
abstract class Template extends Model
|
||||
|
|
|
@ -18,6 +18,9 @@ class ProjectsConsoleClientTest extends Scope
|
|||
use ProjectConsole;
|
||||
use SideClient;
|
||||
|
||||
/**
|
||||
* @group smtpAndTemplates
|
||||
*/
|
||||
public function testCreateProject(): array
|
||||
{
|
||||
/**
|
||||
|
@ -430,6 +433,7 @@ class ProjectsConsoleClientTest extends Scope
|
|||
}
|
||||
|
||||
/**
|
||||
* @group smtpAndTemplates
|
||||
* @depends testCreateProject
|
||||
*/
|
||||
public function testUpdateProjectSMTP($data): array
|
||||
|
@ -455,6 +459,78 @@ class ProjectsConsoleClientTest extends Scope
|
|||
$this->assertEquals('emailuser', $response['body']['smtpUsername']);
|
||||
$this->assertEquals('securepassword', $response['body']['smtpPassword']);
|
||||
$this->assertEquals('', $response['body']['smtpSecure']);
|
||||
|
||||
/** Test Reading Project */
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertTrue($response['body']['smtpEnabled']);
|
||||
$this->assertEquals('mailer@appwrite.io', $response['body']['smtpSender']);
|
||||
$this->assertEquals('mail.appwrite.io', $response['body']['smtpHost']);
|
||||
$this->assertEquals(25, $response['body']['smtpPort']);
|
||||
$this->assertEquals('emailuser', $response['body']['smtpUsername']);
|
||||
$this->assertEquals('securepassword', $response['body']['smtpPassword']);
|
||||
$this->assertEquals('', $response['body']['smtpSecure']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group smtpAndTemplates
|
||||
* @depends testCreateProject */
|
||||
public function testUpdateTemplates($data): array
|
||||
{
|
||||
$id = $data['projectId'];
|
||||
|
||||
/** Get Default Template */
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/email/verification/en_us', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('Account Verification', $response['body']['subject']);
|
||||
$this->assertEquals('Appwrite', $response['body']['senderName']);
|
||||
$this->assertEquals('team@appwrite.io', $response['body']['senderEmail']);
|
||||
$this->assertEquals('verification', $response['body']['type']);
|
||||
$this->assertEquals('en_us', $response['body']['locale']);
|
||||
$this->assertMatchesRegularExpression('/<!doctype html>/', $response['body']['message']);
|
||||
|
||||
/** Update template */
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/templates/email/verification/en_us', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'subject' => 'Please verify your email',
|
||||
'message' => 'Please verify your email {{url}}',
|
||||
'senderName' => 'Appwrite Custom',
|
||||
'senderEmail' => 'custom@appwrite.io',
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('Please verify your email', $response['body']['subject']);
|
||||
$this->assertEquals('Appwrite Custom', $response['body']['senderName']);
|
||||
$this->assertEquals('custom@appwrite.io', $response['body']['senderEmail']);
|
||||
$this->assertEquals('verification', $response['body']['type']);
|
||||
$this->assertEquals('en_us', $response['body']['locale']);
|
||||
$this->assertEquals('Please verify your email {{url}}', $response['body']['message']);
|
||||
|
||||
/** Get Updated Template */
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/email/verification/en_us', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('Please verify your email', $response['body']['subject']);
|
||||
$this->assertEquals('Appwrite Custom', $response['body']['senderName']);
|
||||
$this->assertEquals('custom@appwrite.io', $response['body']['senderEmail']);
|
||||
$this->assertEquals('verification', $response['body']['type']);
|
||||
$this->assertEquals('en_us', $response['body']['locale']);
|
||||
$this->assertEquals('Please verify your email {{url}}', $response['body']['message']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue