mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge remote-tracking branch 'origin/main' into feat/vcs-factory
# Conflicts: # composer.lock
This commit is contained in:
commit
a802d8ee29
17 files changed
+501
-320
No files matched your search
@@ -103,7 +103,7 @@ jobs:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
|
||||
with:
|
||||
php-version: '8.3'
|
||||
php-version: '8.5'
|
||||
extensions: swoole
|
||||
tools: composer:v2
|
||||
coverage: none
|
||||
|
||||
@@ -3827,6 +3827,14 @@ Http::post('/v1/account/recovery')
|
||||
$customTemplate =
|
||||
$project->getAttribute('templates', [])['email.recovery-' . $locale->default] ??
|
||||
$project->getAttribute('templates', [])['email.recovery-' . $locale->fallback] ?? [];
|
||||
$smtpBaseTemplate = $project->getAttribute('smtpBaseTemplate', 'email-base');
|
||||
|
||||
$validator = new FileName();
|
||||
if (!$validator->isValid($smtpBaseTemplate)) {
|
||||
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Invalid template path');
|
||||
}
|
||||
|
||||
$bodyTemplate = __DIR__ . '/../../config/locale/templates/' . $smtpBaseTemplate . '.tpl';
|
||||
|
||||
$message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-inner-base.tpl');
|
||||
$message
|
||||
@@ -3906,12 +3914,27 @@ Http::post('/v1/account/recovery')
|
||||
'team' => ''
|
||||
];
|
||||
|
||||
if ($smtpBaseTemplate === APP_BRANDED_EMAIL_BASE_TEMPLATE) {
|
||||
$emailVariables = [
|
||||
...$emailVariables,
|
||||
'accentColor' => $platform['accentColor'],
|
||||
'logoUrl' => $platform['logoUrl'],
|
||||
'twitter' => $platform['twitterUrl'],
|
||||
'discord' => $platform['discordUrl'],
|
||||
'github' => $platform['githubUrl'],
|
||||
'terms' => $platform['termsUrl'],
|
||||
'privacy' => $platform['privacyUrl'],
|
||||
'platform' => $platform['platformName'],
|
||||
];
|
||||
}
|
||||
|
||||
$publisherForMails->enqueue(new MailMessage(
|
||||
project: $project,
|
||||
recipient: $profile->getAttribute('email', ''),
|
||||
name: $profile->getAttribute('name', ''),
|
||||
subject: $subject,
|
||||
template: MAIL_TEMPLATE_RECOVERY,
|
||||
bodyTemplate: $bodyTemplate,
|
||||
body: $body,
|
||||
preview: $preview,
|
||||
smtp: $smtpConfig,
|
||||
|
||||
@@ -1313,7 +1313,7 @@ Http::error()
|
||||
$log->setMessage($error->getMessage());
|
||||
|
||||
$log->addTag('database', $dsn->getHost());
|
||||
$log->addTag('method', $route?->getMethod() ?? $request->getMethod());
|
||||
$log->addTag('method', \implode(',', $route?->getMethods() ?? [$request->getMethod()]));
|
||||
$log->addTag('url', $request->getURI());
|
||||
$log->addTag('verboseType', get_class($error));
|
||||
$log->addTag('code', $error->getCode());
|
||||
|
||||
@@ -304,12 +304,15 @@ Http::shutdown()
|
||||
$result = [];
|
||||
$path = APP_STORAGE_CACHE . '/tests.json';
|
||||
$tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : [];
|
||||
$methods = $route->getMethods();
|
||||
|
||||
if (!\is_array($tests)) {
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Failed to read results', 500);
|
||||
}
|
||||
|
||||
$result[$route->getMethod() . ':' . $route->getPath()] = true;
|
||||
foreach ($methods as $method) {
|
||||
$result[$method . ':' . $route->getPath()] = true;
|
||||
}
|
||||
|
||||
$tests = \array_merge($tests, $result);
|
||||
|
||||
@@ -317,5 +320,5 @@ Http::shutdown()
|
||||
throw new Exception(Exception::GENERAL_MOCK, 'Failed to save results', 500);
|
||||
}
|
||||
|
||||
$response->dynamic(new Document(['result' => $route->getMethod() . ':' . $route->getPath() . ':passed']), Response::MODEL_MOCK);
|
||||
$response->dynamic(new Document(['result' => \implode(',', $methods) . ':' . $route->getPath() . ':passed']), Response::MODEL_MOCK);
|
||||
});
|
||||
+1
-1
@@ -557,7 +557,7 @@ $swoole->onRequest(function ($utopiaRequest, $utopiaResponse) use ($files, $swoo
|
||||
$log->setType(Log::TYPE_ERROR);
|
||||
$log->setMessage($th->getMessage());
|
||||
|
||||
$log->addTag('method', $route?->getMethod() ?? $request->getMethod());
|
||||
$log->addTag('method', \implode(',', $route?->getMethods() ?? [$request->getMethod()]));
|
||||
$log->addTag('url', $route?->getPath() ?? $request->getURI());
|
||||
$log->addTag('verboseType', get_class($th));
|
||||
$log->addTag('code', $th->getCode());
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.4.0",
|
||||
"php": ">=8.5.0",
|
||||
"ext-curl": "*",
|
||||
"ext-imagick": "*",
|
||||
"ext-mbstring": "*",
|
||||
@@ -77,7 +77,7 @@
|
||||
"utopia-php/dsn": "0.2.1",
|
||||
"utopia-php/http": "^2.0@RC",
|
||||
"utopia-php/fetch": "^1.1",
|
||||
"utopia-php/validators": "0.2.*",
|
||||
"utopia-php/validators": "0.3.*",
|
||||
"utopia-php/image": "0.8.*",
|
||||
"utopia-php/locale": "0.8.*",
|
||||
"utopia-php/lock": "0.2.*",
|
||||
@@ -88,7 +88,7 @@
|
||||
"utopia-php/pools": "1.*",
|
||||
"utopia-php/span": "3.0.*",
|
||||
"utopia-php/preloader": "0.2.*",
|
||||
"utopia-php/queue": "^0.21",
|
||||
"utopia-php/queue": "^0.22",
|
||||
"utopia-php/servers": "0.4.*",
|
||||
"utopia-php/registry": "0.5.*",
|
||||
"utopia-php/storage": "2.*",
|
||||
|
||||
Generated
+206
-215
File diff suppressed because it is too large.
Load diff
@@ -72,13 +72,15 @@ class Resolvers
|
||||
*
|
||||
* @param Http $utopia
|
||||
* @param ?Route $route
|
||||
* @param string $method
|
||||
* @return callable
|
||||
*/
|
||||
public static function api(
|
||||
Http $utopia,
|
||||
?Route $route,
|
||||
string $method,
|
||||
): callable {
|
||||
return static fn ($type, $args, $context, $info) => new Swoole(function (callable $resolve, callable $reject) use ($utopia, $route, $args) {
|
||||
return static fn ($type, $args, $context, $info) => new Swoole(function (callable $resolve, callable $reject) use ($utopia, $route, $method, $args) {
|
||||
$utopia = $utopia->context()->get('utopia:graphql');
|
||||
$request = $utopia->context()->get('request');
|
||||
$response = $utopia->context()->get('response');
|
||||
@@ -89,7 +91,7 @@ class Resolvers
|
||||
$response,
|
||||
$resolve,
|
||||
$reject,
|
||||
prepareRequest: static function (Request $request) use ($route, $args): void {
|
||||
prepareRequest: static function (Request $request) use ($route, $method, $args): void {
|
||||
$path = $route->getPath();
|
||||
foreach ($args as $key => $value) {
|
||||
if (\str_contains($path, '/:' . $key)) {
|
||||
@@ -97,10 +99,10 @@ class Resolvers
|
||||
}
|
||||
}
|
||||
|
||||
$request->setMethod($route->getMethod());
|
||||
$request->setMethod($method);
|
||||
$request->setURI($path);
|
||||
|
||||
switch ($route->getMethod()) {
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
$request->setQueryString($args);
|
||||
break;
|
||||
|
||||
@@ -90,7 +90,7 @@ class Schema
|
||||
$queries = [];
|
||||
$mutations = [];
|
||||
|
||||
foreach ($utopia->getRoutes() as $routes) {
|
||||
foreach ($utopia->getRoutes() as $httpMethod => $routes) {
|
||||
foreach ($routes as $route) {
|
||||
/** @var Route $route */
|
||||
|
||||
@@ -109,8 +109,8 @@ class Schema
|
||||
$methodName = $method->getMethodName();
|
||||
$name = $namespace . \ucfirst($methodName);
|
||||
|
||||
foreach (Mapper::route($utopia, $route, $method, $complexity) as $field) {
|
||||
switch ($route->getMethod()) {
|
||||
foreach (Mapper::route($utopia, $route, $method, $httpMethod, $complexity) as $field) {
|
||||
switch ($httpMethod) {
|
||||
case 'GET':
|
||||
$queries[$name] = $field;
|
||||
break;
|
||||
@@ -121,7 +121,7 @@ class Schema
|
||||
$mutations[$name] = $field;
|
||||
break;
|
||||
default:
|
||||
throw new \Exception("Unsupported method: {$route->getMethod()}");
|
||||
throw new \Exception("Unsupported method: {$httpMethod}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ class Mapper
|
||||
Http $utopia,
|
||||
Route $route,
|
||||
Method $method,
|
||||
string $httpMethod,
|
||||
callable $complexity
|
||||
): iterable {
|
||||
foreach (self::$blacklist as $blacklist) {
|
||||
@@ -151,7 +152,7 @@ class Mapper
|
||||
'type' => $type,
|
||||
'description' => $description,
|
||||
'args' => $params,
|
||||
'resolve' => Resolvers::api($utopia, $route)
|
||||
'resolve' => Resolvers::api($utopia, $route, $httpMethod)
|
||||
];
|
||||
|
||||
if ($list) {
|
||||
|
||||
@@ -216,7 +216,12 @@ class Mails extends Action
|
||||
$emailMessage->setOrigin(MESSAGE_SEND_TYPE_INTERNAL);
|
||||
|
||||
try {
|
||||
$adapter->send($emailMessage);
|
||||
$result = $adapter->send($emailMessage);
|
||||
|
||||
if (($result['deliveredTo'] ?? 0) === 0) {
|
||||
$error = $result['results'][0]['error'] ?? ($result['error'] ?? 'Unknown error');
|
||||
throw new Exception($error);
|
||||
}
|
||||
} catch (\Throwable $error) {
|
||||
Span::add('mail.status', 'failure');
|
||||
|
||||
|
||||
@@ -419,18 +419,7 @@ class OpenAPI3 extends Format
|
||||
$temp['security'][] = $securities;
|
||||
}
|
||||
|
||||
$body = [
|
||||
'content' => [
|
||||
$consumes[0] => [
|
||||
'schema' => [
|
||||
'type' => 'object',
|
||||
'properties' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$bodyRequired = [];
|
||||
$parameterNodes = [];
|
||||
|
||||
$parameters = \array_merge(
|
||||
$route->getParams(),
|
||||
@@ -826,55 +815,12 @@ class OpenAPI3 extends Format
|
||||
}
|
||||
}
|
||||
|
||||
if ($isPathParam) { // Param is in URL path (directly or through alias)
|
||||
$node['in'] = 'path';
|
||||
$temp['parameters'][] = $node;
|
||||
} elseif (\in_array($route->getMethod(), ['GET', 'DELETE'], true)) { // Param is in query
|
||||
$node['in'] = 'query';
|
||||
$temp['parameters'][] = $node;
|
||||
} else { // Param is in payload
|
||||
if ($node['required']) {
|
||||
$bodyRequired[] = $name;
|
||||
}
|
||||
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name] = [
|
||||
'type' => $node['schema']['type'],
|
||||
'description' => $node['description'],
|
||||
];
|
||||
|
||||
if (\array_key_exists('default', $node['schema'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['default'] = $node['schema']['default'];
|
||||
}
|
||||
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-example'] = $node['schema']['x-example'] ?? null;
|
||||
|
||||
if (isset($node['schema']['format'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['format'] = $node['schema']['format'];
|
||||
}
|
||||
|
||||
if (isset($node['schema']['enum'])) {
|
||||
/// If the enum flag is Set, add the enum values to the body
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['enum'] = $node['schema']['enum'];
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-enum-name'] = $node['schema']['x-enum-name'] ?? null;
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-enum-keys'] = $node['schema']['x-enum-keys'];
|
||||
}
|
||||
|
||||
if ($node['schema']['x-upload-id'] ?? false) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-upload-id'] = $node['schema']['x-upload-id'];
|
||||
}
|
||||
|
||||
if (isset($node['schema']['x-appwrite'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-appwrite'] = $node['schema']['x-appwrite'];
|
||||
}
|
||||
|
||||
if (\array_key_exists('items', $node['schema'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['items'] = $node['schema']['items'];
|
||||
}
|
||||
|
||||
if ($parameter['nullable']) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-nullable'] = true;
|
||||
}
|
||||
}
|
||||
$parameterNodes[] = [
|
||||
'name' => $name,
|
||||
'config' => $parameter,
|
||||
'node' => $node,
|
||||
'path' => $isPathParam,
|
||||
];
|
||||
|
||||
$segments = \explode('/', $url);
|
||||
foreach ($segments as &$segment) {
|
||||
@@ -886,15 +832,90 @@ class OpenAPI3 extends Format
|
||||
$url = \implode('/', $segments);
|
||||
}
|
||||
|
||||
if (!empty($bodyRequired)) {
|
||||
$body['content'][$consumes[0]]['schema']['required'] = $bodyRequired;
|
||||
}
|
||||
$methods = $route->getMethods();
|
||||
foreach ($methods as $method) {
|
||||
$methodTemp = $temp;
|
||||
if (\count($methods) > 1) {
|
||||
$methodTemp['operationId'] .= \ucfirst(\strtolower($method));
|
||||
}
|
||||
$body = [
|
||||
'content' => [
|
||||
$consumes[0] => [
|
||||
'schema' => [
|
||||
'type' => 'object',
|
||||
'properties' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$bodyRequired = [];
|
||||
|
||||
if (!empty($body['content'][$consumes[0]]['schema']['properties'])) {
|
||||
$temp['requestBody'] = $body;
|
||||
}
|
||||
foreach ($parameterNodes as $parameterNode) {
|
||||
$name = $parameterNode['name'];
|
||||
$parameter = $parameterNode['config'];
|
||||
$node = $parameterNode['node'];
|
||||
|
||||
$output['paths'][$url][\strtolower($route->getMethod())] = $temp;
|
||||
if ($parameterNode['path']) { // Param is in URL path (directly or through alias)
|
||||
$node['in'] = 'path';
|
||||
$methodTemp['parameters'][] = $node;
|
||||
} elseif (\in_array($method, ['GET', 'DELETE'], true)) { // Param is in query
|
||||
$node['in'] = 'query';
|
||||
$methodTemp['parameters'][] = $node;
|
||||
} else { // Param is in payload
|
||||
if ($node['required']) {
|
||||
$bodyRequired[] = $name;
|
||||
}
|
||||
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name] = [
|
||||
'type' => $node['schema']['type'],
|
||||
'description' => $node['description'],
|
||||
];
|
||||
|
||||
if (\array_key_exists('default', $node['schema'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['default'] = $node['schema']['default'];
|
||||
}
|
||||
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-example'] = $node['schema']['x-example'] ?? null;
|
||||
|
||||
if (isset($node['schema']['format'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['format'] = $node['schema']['format'];
|
||||
}
|
||||
|
||||
if (isset($node['schema']['enum'])) {
|
||||
/// If the enum flag is Set, add the enum values to the body
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['enum'] = $node['schema']['enum'];
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-enum-name'] = $node['schema']['x-enum-name'] ?? null;
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-enum-keys'] = $node['schema']['x-enum-keys'];
|
||||
}
|
||||
|
||||
if ($node['schema']['x-upload-id'] ?? false) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-upload-id'] = $node['schema']['x-upload-id'];
|
||||
}
|
||||
|
||||
if (isset($node['schema']['x-appwrite'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-appwrite'] = $node['schema']['x-appwrite'];
|
||||
}
|
||||
|
||||
if (\array_key_exists('items', $node['schema'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['items'] = $node['schema']['items'];
|
||||
}
|
||||
|
||||
if ($parameter['nullable']) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['x-nullable'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($bodyRequired)) {
|
||||
$body['content'][$consumes[0]]['schema']['required'] = $bodyRequired;
|
||||
}
|
||||
|
||||
if (!empty($body['content'][$consumes[0]]['schema']['properties'])) {
|
||||
$methodTemp['requestBody'] = $body;
|
||||
}
|
||||
|
||||
$output['paths'][$url][\strtolower($method)] = $methodTemp;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->models as $model) {
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
use Utopia\Database\Document;
|
||||
|
||||
class Database extends Model
|
||||
{
|
||||
@@ -59,21 +58,6 @@ class Database extends Model
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A null status is treated as ready.
|
||||
*
|
||||
* @param Document $document
|
||||
* @return Document
|
||||
*/
|
||||
public function filter(Document $document): Document
|
||||
{
|
||||
if (empty($document->getAttribute('status'))) {
|
||||
$document->setAttribute('status', 'ready');
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
|
||||
@@ -16,6 +16,40 @@ final class AccountConsoleClientTest extends Scope
|
||||
use ProjectConsole;
|
||||
use SideClient;
|
||||
|
||||
public function testCreateRecoveryEmailBranding(): void
|
||||
{
|
||||
$email = ID::unique() . '@appwrite.io';
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => ID::unique(),
|
||||
'email' => $email,
|
||||
'password' => 'password',
|
||||
'name' => 'Recovery User',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'email' => $email,
|
||||
'url' => 'http://localhost/recovery',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
$lastEmail = $this->getLastEmailByAddress($email);
|
||||
|
||||
$this->assertNotEmpty($lastEmail, 'Email not found for address: ' . $email);
|
||||
$this->assertStringContainsStringIgnoringCase('Appwrite logo', $lastEmail['html']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that account deletion succeeds even with active team memberships.
|
||||
* When the user is the sole owner and only member of a team, the team
|
||||
|
||||
@@ -1804,6 +1804,7 @@ final class AccountCustomClientTest extends Scope
|
||||
$this->assertEquals($name, $lastEmail['to'][0]['name']);
|
||||
$this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']);
|
||||
$this->assertStringContainsStringIgnoringCase('Reset your ' . $this->getProject()['name'] . ' password using the link.', $lastEmail['text']);
|
||||
$this->assertStringNotContainsStringIgnoringCase('Appwrite logo', $lastEmail['html']);
|
||||
|
||||
|
||||
$tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html']);
|
||||
|
||||
@@ -17,6 +17,9 @@ use Utopia\Telemetry\Adapter\None;
|
||||
final class SpyMailAdapter extends EmailAdapter
|
||||
{
|
||||
public ?EmailMessage $captured = null;
|
||||
public int $deliveredTo = 1;
|
||||
public ?string $error = null;
|
||||
public bool $emptyResults = false;
|
||||
public int $sendCount = 0;
|
||||
|
||||
public function getName(): string
|
||||
@@ -34,11 +37,32 @@ final class SpyMailAdapter extends EmailAdapter
|
||||
$this->sendCount++;
|
||||
$this->captured = $message;
|
||||
|
||||
return [
|
||||
'deliveredTo' => 1,
|
||||
$response = [
|
||||
'deliveredTo' => $this->deliveredTo,
|
||||
'type' => $this->getType(),
|
||||
'results' => [['recipient' => $message->getTo()[0]['email'] ?? '', 'status' => 'sent']],
|
||||
'results' => [],
|
||||
];
|
||||
|
||||
if ($this->emptyResults) {
|
||||
if ($this->error !== null) {
|
||||
$response['error'] = $this->error;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
$result = [
|
||||
'recipient' => $message->getTo()[0]['email'] ?? '',
|
||||
'status' => $this->deliveredTo === 0 ? 'failure' : 'success',
|
||||
];
|
||||
|
||||
if ($this->error !== null) {
|
||||
$result['error'] = $this->error;
|
||||
}
|
||||
|
||||
$response['results'] = [$result];
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,10 +85,12 @@ final class MailsTest extends TestCase
|
||||
'queue' => 'v1-mails',
|
||||
'timestamp' => \time(),
|
||||
'payload' => [
|
||||
'smtp' => [],
|
||||
'recipient' => 'legacy@example.test',
|
||||
'name' => 'Legacy User',
|
||||
'subject' => 'Hello {{name}}',
|
||||
'body' => 'Body {{name}}',
|
||||
'bodyTemplate' => '',
|
||||
'variables' => ['name' => 'Legacy'],
|
||||
'customMailOptions' => [
|
||||
'senderEmail' => 'sender@example.test',
|
||||
@@ -95,4 +121,61 @@ final class MailsTest extends TestCase
|
||||
$this->assertSame('reply@example.test', $message->getReplyToEmail());
|
||||
$this->assertSame('Custom Reply', $message->getReplyToName());
|
||||
}
|
||||
|
||||
public function testMailDeliveryFailureIsThrownByMailsWorker(): void
|
||||
{
|
||||
$adapter = new SpyMailAdapter();
|
||||
$adapter->deliveredTo = 0;
|
||||
$adapter->error = 'Domain not verified';
|
||||
|
||||
$this->assertMailWorkerThrows($adapter, 'Error sending mail: Domain not verified');
|
||||
}
|
||||
|
||||
public function testMailDeliveryFailureUsesTopLevelErrorWhenResultsEmpty(): void
|
||||
{
|
||||
$adapter = new SpyMailAdapter();
|
||||
$adapter->deliveredTo = 0;
|
||||
$adapter->emptyResults = true;
|
||||
$adapter->error = 'Provider rejected request';
|
||||
|
||||
$this->assertMailWorkerThrows($adapter, 'Error sending mail: Provider rejected request');
|
||||
}
|
||||
|
||||
private function assertMailWorkerThrows(SpyMailAdapter $adapter, string $expectedMessage): void
|
||||
{
|
||||
$registry = new Registry();
|
||||
$registry->set('smtp', static fn () => $adapter);
|
||||
|
||||
$previousSmtpHost = \getenv('_APP_SMTP_HOST');
|
||||
\putenv('_APP_SMTP_HOST=spy.smtp.test');
|
||||
|
||||
try {
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage($expectedMessage);
|
||||
|
||||
$worker = new Mails();
|
||||
$worker->action(
|
||||
new Message([
|
||||
'pid' => 'pid',
|
||||
'queue' => 'v1-mails',
|
||||
'timestamp' => \time(),
|
||||
'payload' => [
|
||||
'smtp' => [],
|
||||
'recipient' => 'legacy@example.test',
|
||||
'name' => 'Legacy User',
|
||||
'subject' => 'Hello',
|
||||
'body' => 'Body',
|
||||
'bodyTemplate' => '',
|
||||
'variables' => [],
|
||||
],
|
||||
]),
|
||||
new Document(['$id' => 'project-x']),
|
||||
$registry,
|
||||
new Log(),
|
||||
new None(),
|
||||
);
|
||||
} finally {
|
||||
\putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,6 +163,39 @@ final class FormatTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function testMultiMethodRouteEmitsEveryOperation(): void
|
||||
{
|
||||
Method::$processed = [];
|
||||
Method::$errors = [];
|
||||
|
||||
$route = (new Route(['GET', 'POST'], '/v1/tests/:testId'))
|
||||
->desc('Get or update test')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'test',
|
||||
group: null,
|
||||
name: 'getOrUpdateTest',
|
||||
description: 'Get or update test.',
|
||||
auth: [],
|
||||
responses: [],
|
||||
))
|
||||
->param('testId', '', new Text(256), 'Test ID.')
|
||||
->param('name', null, new Nullable(new Text(256)), 'Test name.', true);
|
||||
|
||||
$openApi = (new OpenAPI3(new Container(), [], [$route], [], [], 0, 'console'))->parse();
|
||||
|
||||
$get = $openApi['paths']['/tests/{testId}']['get'];
|
||||
$post = $openApi['paths']['/tests/{testId}']['post'];
|
||||
|
||||
$this->assertSame('testGetOrUpdateTestGet', $get['operationId']);
|
||||
$this->assertSame('testGetOrUpdateTestPost', $post['operationId']);
|
||||
$this->assertSame('path', $get['parameters'][0]['in']);
|
||||
$this->assertSame('query', $get['parameters'][1]['in']);
|
||||
$this->assertArrayNotHasKey('requestBody', $get);
|
||||
$this->assertSame('path', $post['parameters'][0]['in']);
|
||||
$this->assertCount(1, $post['parameters']);
|
||||
$this->assertArrayHasKey('name', $post['requestBody']['content']['application/json']['schema']['properties']);
|
||||
}
|
||||
|
||||
public function testModelReferencesDoNotEmitItemsOnObjectProperties(): void
|
||||
{
|
||||
Method::$processed = [];
|
||||
|
||||
Reference in new issue
Block a user