mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
New tests
This commit is contained in:
@@ -1163,6 +1163,207 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$this->assertEquals('Please verify your email {{url}}', $response['body']['message']);
|
||||
}
|
||||
|
||||
#[Group('smtpAndTemplates')]
|
||||
public function testSessionAlertLocaleFallback(): void
|
||||
{
|
||||
$smtpHost = 'maildev';
|
||||
$smtpPort = 1025;
|
||||
$smtpUsername = 'user';
|
||||
$smtpPassword = 'password';
|
||||
|
||||
/** Create team */
|
||||
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'teamId' => ID::unique(),
|
||||
'name' => 'Session Alert Locale Fallback Test Team',
|
||||
]);
|
||||
$this->assertEquals(201, $team['headers']['status-code']);
|
||||
|
||||
/** Create project */
|
||||
$project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'projectId' => ID::unique(),
|
||||
'name' => 'Session Alert Locale Fallback Test',
|
||||
'teamId' => $team['body']['$id'],
|
||||
'region' => System::getEnv('_APP_REGION', 'default'),
|
||||
]);
|
||||
$this->assertEquals(201, $project['headers']['status-code']);
|
||||
$projectId = $project['body']['$id'];
|
||||
|
||||
/** Configure custom SMTP pointing to maildev */
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/smtp', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'enabled' => true,
|
||||
'senderEmail' => 'mailer@appwrite.io',
|
||||
'senderName' => 'Mailer',
|
||||
'host' => $smtpHost,
|
||||
'port' => $smtpPort,
|
||||
'username' => $smtpUsername,
|
||||
'password' => $smtpPassword,
|
||||
]);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
/**
|
||||
* Set custom sessionAlert template with no explicit locale.
|
||||
* When locale is omitted, the server stores it under the request's
|
||||
* default locale (en), which is the same slot used as the system-wide
|
||||
* fallback when a session's locale has no dedicated template.
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/templates/email', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'type' => 'sessionAlert',
|
||||
// Intentionally no locale
|
||||
'subject' => 'Fallback sign-in alert',
|
||||
'message' => 'Fallback sign-in alert body',
|
||||
'senderName' => 'Fallback Mailer',
|
||||
'senderEmail' => 'fallback@appwrite.io',
|
||||
]);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('Fallback sign-in alert', $response['body']['subject']);
|
||||
$this->assertEquals('Fallback sign-in alert body', $response['body']['message']);
|
||||
$this->assertEquals('Fallback Mailer', $response['body']['senderName']);
|
||||
$this->assertEquals('fallback@appwrite.io', $response['body']['senderEmail']);
|
||||
|
||||
/** Set custom sessionAlert template for Slovak locale */
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/templates/email', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'type' => 'sessionAlert',
|
||||
'locale' => 'sk',
|
||||
'subject' => 'Slovak sign-in alert',
|
||||
'message' => 'Slovak sign-in alert body',
|
||||
'senderName' => 'Slovak Mailer',
|
||||
'senderEmail' => 'sk@appwrite.io',
|
||||
]);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('Slovak sign-in alert', $response['body']['subject']);
|
||||
$this->assertEquals('Slovak sign-in alert body', $response['body']['message']);
|
||||
$this->assertEquals('Slovak Mailer', $response['body']['senderName']);
|
||||
$this->assertEquals('sk@appwrite.io', $response['body']['senderEmail']);
|
||||
|
||||
/** Enable session alerts */
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/auth/session-alerts', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'alerts' => true,
|
||||
]);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
/** Verify alerts are enabled */
|
||||
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, 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']['authSessionAlerts']);
|
||||
|
||||
/** Create user (email + password) in the project */
|
||||
$userEmail = 'session-alert-' . uniqid() . '@appwrite.io';
|
||||
$password = 'password';
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], [
|
||||
'userId' => ID::unique(),
|
||||
'email' => $userEmail,
|
||||
'password' => $password,
|
||||
'name' => 'Session Alert User',
|
||||
]);
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
/**
|
||||
* Prime first session — the listener suppresses the alert on the very
|
||||
* first session of a user, so this session is setup only.
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], [
|
||||
'email' => $userEmail,
|
||||
'password' => $password,
|
||||
]);
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
/** Create a new session with no locale — expect fallback (en) template */
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], [
|
||||
'email' => $userEmail,
|
||||
'password' => $password,
|
||||
]);
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
$lastEmail = $this->getLastEmailByAddress($userEmail);
|
||||
$this->assertEquals('Fallback sign-in alert', $lastEmail['subject']);
|
||||
$this->assertEquals('fallback@appwrite.io', $lastEmail['from'][0]['address']);
|
||||
$this->assertEquals('Fallback Mailer', $lastEmail['from'][0]['name']);
|
||||
$this->assertStringContainsString('Fallback sign-in alert body', $lastEmail['html']);
|
||||
|
||||
/** Create a new session with German locale — expect fallback (en) template */
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-locale' => 'de',
|
||||
], [
|
||||
'email' => $userEmail,
|
||||
'password' => $password,
|
||||
]);
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
$lastEmail = $this->getLastEmailByAddress($userEmail);
|
||||
$this->assertEquals('Fallback sign-in alert', $lastEmail['subject']);
|
||||
$this->assertEquals('fallback@appwrite.io', $lastEmail['from'][0]['address']);
|
||||
$this->assertEquals('Fallback Mailer', $lastEmail['from'][0]['name']);
|
||||
$this->assertStringContainsString('Fallback sign-in alert body', $lastEmail['html']);
|
||||
|
||||
/** Create a new session with Slovak locale — expect Slovak template */
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-locale' => 'sk',
|
||||
], [
|
||||
'email' => $userEmail,
|
||||
'password' => $password,
|
||||
]);
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
$lastEmail = $this->getLastEmailByAddress($userEmail);
|
||||
$this->assertEquals('Slovak sign-in alert', $lastEmail['subject']);
|
||||
$this->assertEquals('sk@appwrite.io', $lastEmail['from'][0]['address']);
|
||||
$this->assertEquals('Slovak Mailer', $lastEmail['from'][0]['name']);
|
||||
$this->assertStringContainsString('Slovak sign-in alert body', $lastEmail['html']);
|
||||
|
||||
/** Cleanup — delete the project */
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
$this->assertEquals(204, $response['headers']['status-code']);
|
||||
|
||||
/** Cleanup — delete the team */
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
$this->assertEquals(204, $response['headers']['status-code']);
|
||||
}
|
||||
|
||||
public function testUpdateProjectAuthDuration(): void
|
||||
{
|
||||
$data = $this->setupProjectData();
|
||||
|
||||
Reference in New Issue
Block a user