mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix(console): build worker console links from platform consoleUrl
The notifications and webhooks workers now take the console origin from the injected platform config instead of rebuilding it from _APP_CONSOLE_DOMAIN, so email links follow _APP_CONSOLE_URL and per-platform overrides. Rename the VCS comment QR variable since it points at the API host.
This commit is contained in:
1 parent
2423bb9c80
commit
7cc7063e40
6 files changed
+57
-50
No files matched your search
@@ -18,6 +18,7 @@ if (\str_contains($functionsDomain, ',')) {
|
||||
*/
|
||||
return [
|
||||
'apiHostname' => System::getEnv('_APP_DOMAIN', 'localhost'),
|
||||
// Also serves the API (VCS OAuth callbacks, avatars, images); never point it at the console web origin
|
||||
'consoleHostname' => System::getEnv('_APP_CONSOLE_DOMAIN', System::getEnv('_APP_DOMAIN', 'localhost')),
|
||||
// Console web app origin for links; it can live apart from the API host above
|
||||
'consoleUrl' => \rtrim(System::getEnv('_APP_CONSOLE_URL', (System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https') . '://' . System::getEnv('_APP_CONSOLE_DOMAIN', System::getEnv('_APP_DOMAIN', 'localhost'))), '/'),
|
||||
|
||||
@@ -52,10 +52,11 @@ class Notifications extends Action
|
||||
->inject('project')
|
||||
->inject('register')
|
||||
->inject('dbForPlatform')
|
||||
->inject('platform')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(Message $message, Document $project, Registry $register, Database $dbForPlatform): void
|
||||
public function action(Message $message, Document $project, Registry $register, Database $dbForPlatform, array $platform): void
|
||||
{
|
||||
$payload = $message->getPayload();
|
||||
|
||||
@@ -90,7 +91,7 @@ class Notifications extends Action
|
||||
}
|
||||
|
||||
try {
|
||||
$alertId = $this->dispatch($recipient, $messageId, $payload, $project, $register, $dbForPlatform);
|
||||
$alertId = $this->dispatch($recipient, $messageId, $payload, $project, $register, $dbForPlatform, $platform);
|
||||
if ($messageId !== '' && $channel === NOTIFICATION_TYPE_WEBHOOK && $alertId === null) {
|
||||
$this->persistAlert($dbForPlatform, $messageId, $recipient, $payload, $project);
|
||||
}
|
||||
@@ -173,11 +174,12 @@ class Notifications extends Action
|
||||
Document $project,
|
||||
Registry $register,
|
||||
Database $dbForPlatform,
|
||||
array $platform,
|
||||
): ?string {
|
||||
$channel = $recipient['channel'];
|
||||
|
||||
return match ($channel) {
|
||||
NOTIFICATION_TYPE_EMAIL => $this->dispatchEmail($recipient, $messageId, $payload, $project, $register, $dbForPlatform),
|
||||
NOTIFICATION_TYPE_EMAIL => $this->dispatchEmail($recipient, $messageId, $payload, $project, $register, $dbForPlatform, $platform),
|
||||
NOTIFICATION_TYPE_CONSOLE => $this->dispatchConsole($recipient, $messageId, $payload, $project, $dbForPlatform),
|
||||
NOTIFICATION_TYPE_WEBHOOK => $this->dispatchWebhook($recipient, $payload),
|
||||
default => throw new Exception('Unsupported notification channel: ' . $channel),
|
||||
@@ -194,6 +196,7 @@ class Notifications extends Action
|
||||
Document $project,
|
||||
Registry $register,
|
||||
Database $dbForPlatform,
|
||||
array $platform,
|
||||
): ?string {
|
||||
$address = $recipient['address'];
|
||||
$smtp = $this->resolveSmtpConfig($project, $payload);
|
||||
@@ -206,13 +209,10 @@ class Notifications extends Action
|
||||
$type = empty($smtp) ? 'cloud' : 'smtp';
|
||||
Span::add('type', $type);
|
||||
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'disabled' ? 'http' : 'https';
|
||||
$consoleHostname = System::getEnv('_APP_CONSOLE_DOMAIN', System::getEnv('_APP_DOMAIN', 'localhost'));
|
||||
|
||||
$subject = $payload['subject'] ?? '';
|
||||
$variables = $payload['variables'] ?? [];
|
||||
$variables = \array_merge($variables, $payload['templateParams'] ?? []);
|
||||
$variables['host'] = $protocol . '://' . $consoleHostname;
|
||||
$variables['host'] = $platform['consoleUrl'] ?? '';
|
||||
$name = $payload['name'] ?? '';
|
||||
$body = $payload['body'] ?? '';
|
||||
$preview = $payload['preview'] ?? '';
|
||||
|
||||
@@ -45,6 +45,7 @@ class Webhooks extends Action
|
||||
->inject('dbForPlatform')
|
||||
->inject('publisherForNotifications')
|
||||
->inject('publisherForUsage')
|
||||
->inject('platform')
|
||||
->inject('plan')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
@@ -55,11 +56,12 @@ class Webhooks extends Action
|
||||
* @param Database $dbForPlatform
|
||||
* @param NotificationPublisher $publisherForNotifications
|
||||
* @param UsagePublisher $publisherForUsage
|
||||
* @param array $platform
|
||||
* @param array $plan
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function action(Message $message, Document $project, Database $dbForPlatform, NotificationPublisher $publisherForNotifications, UsagePublisher $publisherForUsage, array $plan): void
|
||||
public function action(Message $message, Document $project, Database $dbForPlatform, NotificationPublisher $publisherForNotifications, UsagePublisher $publisherForUsage, array $platform, array $plan): void
|
||||
{
|
||||
$payload = $message->getPayload();
|
||||
|
||||
@@ -76,7 +78,7 @@ class Webhooks extends Action
|
||||
$errors = [];
|
||||
foreach ($project->getAttribute('webhooks', []) as $webhook) {
|
||||
if (array_intersect($webhook->getAttribute('events', []), $events)) {
|
||||
$error = $this->execute($events, $webhookPayload, $webhook, $user, $project, $dbForPlatform, $publisherForNotifications, $publisherForUsage, $plan);
|
||||
$error = $this->execute($events, $webhookPayload, $webhook, $user, $project, $dbForPlatform, $publisherForNotifications, $publisherForUsage, $platform, $plan);
|
||||
if ($error !== null) {
|
||||
$errors[] = $error;
|
||||
}
|
||||
@@ -97,10 +99,11 @@ class Webhooks extends Action
|
||||
* @param Database $dbForPlatform
|
||||
* @param NotificationPublisher $publisherForNotifications
|
||||
* @param UsagePublisher $publisherForUsage
|
||||
* @param array $platform
|
||||
* @param array $plan
|
||||
* @return string|null The error log if the delivery failed, otherwise null
|
||||
*/
|
||||
private function execute(array $events, string $payload, Document $webhook, Document $user, Document $project, Database $dbForPlatform, NotificationPublisher $publisherForNotifications, UsagePublisher $publisherForUsage, array $plan): ?string
|
||||
private function execute(array $events, string $payload, Document $webhook, Document $user, Document $project, Database $dbForPlatform, NotificationPublisher $publisherForNotifications, UsagePublisher $publisherForUsage, array $platform, array $plan): ?string
|
||||
{
|
||||
if ($webhook->getAttribute('enabled') !== true) {
|
||||
return null;
|
||||
@@ -196,7 +199,7 @@ class Webhooks extends Action
|
||||
if ($attempts >= \intval(System::getEnv('_APP_WEBHOOK_MAX_FAILED_ATTEMPTS', '10'))) {
|
||||
$webhook->setAttribute('enabled', false);
|
||||
$updatePayload['enabled'] = false;
|
||||
$this->sendAlert($attempts, $statusCode, $webhook, $project, $dbForPlatform, $publisherForNotifications, $plan);
|
||||
$this->sendAlert($attempts, $statusCode, $webhook, $project, $dbForPlatform, $publisherForNotifications, $platform, $plan);
|
||||
}
|
||||
|
||||
$dbForPlatform->updateDocument('webhooks', $webhook->getId(), new Document($updatePayload));
|
||||
@@ -237,10 +240,11 @@ class Webhooks extends Action
|
||||
* @param Document $project
|
||||
* @param Database $dbForPlatform
|
||||
* @param NotificationPublisher $publisherForNotifications
|
||||
* @param array $platform
|
||||
* @param array $plan
|
||||
* @return void
|
||||
*/
|
||||
public function sendAlert(int $attempts, mixed $statusCode, Document $webhook, Document $project, Database $dbForPlatform, NotificationPublisher $publisherForNotifications, array $plan): void
|
||||
public function sendAlert(int $attempts, mixed $statusCode, Document $webhook, Document $project, Database $dbForPlatform, NotificationPublisher $publisherForNotifications, array $platform, array $plan): void
|
||||
{
|
||||
$memberships = $dbForPlatform->find('memberships', [
|
||||
Query::equal('teamInternalId', [$project->getAttribute('teamInternalId')]),
|
||||
@@ -277,10 +281,6 @@ class Webhooks extends Action
|
||||
$projectId = $project->getId();
|
||||
$projectInternalId = $project->getSequence();
|
||||
|
||||
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'disabled' ? 'http' : 'https';
|
||||
$consoleHostname = System::getEnv('_APP_CONSOLE_DOMAIN', System::getEnv('_APP_DOMAIN', 'localhost'));
|
||||
$consoleUrl = \rtrim(System::getEnv('_APP_CONSOLE_URL', $protocol . '://' . $consoleHostname), '/');
|
||||
|
||||
$subject = 'Webhook deliveries have been paused';
|
||||
$preview = 'Webhook "' . $webhook->getAttribute('name') . '" has been paused after ' . $attempts . ' failed delivery attempts.';
|
||||
|
||||
@@ -319,7 +319,7 @@ class Webhooks extends Action
|
||||
$template->setParam('{{project}}', $project->getAttribute('name'));
|
||||
$template->setParam('{{url}}', $webhook->getAttribute('url'));
|
||||
$template->setParam('{{error}}', 'The server returned ' . $statusCode . ' status code');
|
||||
$template->setParam('{{host}}', $consoleUrl);
|
||||
$template->setParam('{{host}}', $platform['consoleUrl'] ?? '');
|
||||
$template->setParam('{{path}}', "/projects/{$projectId}/settings/webhooks");
|
||||
$template->setParam('{{attempts}}', $attempts);
|
||||
|
||||
|
||||
@@ -171,10 +171,10 @@ class Comment
|
||||
$qrImagePathLight = '/images/vcs/qr-light.svg';
|
||||
$qrImagePathDark = '/images/vcs/qr-dark.svg';
|
||||
|
||||
$consoleUrl = $protocol . '://' . $hostname . '/v1/avatars/qr?text=' . \urlencode($site['previewUrl']);
|
||||
$qrUrl = $protocol . '://' . $hostname . '/v1/avatars/qr?text=' . \urlencode($site['previewUrl']);
|
||||
$qr = $this->withImages
|
||||
? '[' . $this->generatImage($qrImagePathLight, $qrImagePathDark, 'QR Code', 28) . '](' . $consoleUrl . ')'
|
||||
: '[QR Code](' . $consoleUrl . ')';
|
||||
? '[' . $this->generatImage($qrImagePathLight, $qrImagePathDark, 'QR Code', 28) . '](' . $qrUrl . ')'
|
||||
: '[QR Code](' . $qrUrl . ')';
|
||||
|
||||
$preview = '[Preview URL](' . $site['previewUrl'] . ')';
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ final class SpyNotifications extends Notifications
|
||||
Document $project,
|
||||
Registry $register,
|
||||
Database $dbForPlatform,
|
||||
array $platform,
|
||||
): ?string {
|
||||
$channel = $recipient['channel'];
|
||||
$this->dispatched[] = [
|
||||
@@ -157,6 +158,7 @@ final class NotificationsTest extends TestCase
|
||||
private Authorization $authorization;
|
||||
private Registry $registry;
|
||||
private Document $project;
|
||||
private array $platform = ['consoleUrl' => 'https://console.example.test'];
|
||||
private Span $span;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -291,7 +293,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'event-1',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$this->assertCount(3, $worker->dispatched);
|
||||
$channels = \array_map(static fn ($d) => $d['channel'], $worker->dispatched);
|
||||
@@ -313,7 +315,7 @@ final class NotificationsTest extends TestCase
|
||||
'permissions' => [Permission::read(Role::any())],
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$rows = $this->database->find('notifications');
|
||||
$this->assertCount(2, $rows);
|
||||
@@ -345,11 +347,11 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'dup-key',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
$this->assertCount(1, $worker->dispatched);
|
||||
|
||||
$worker->dispatched = [];
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
$this->assertCount(0, $worker->dispatched, 'second invocation must short-circuit on dedup hit');
|
||||
}
|
||||
|
||||
@@ -363,7 +365,8 @@ final class NotificationsTest extends TestCase
|
||||
$this->buildMessage(['project' => ['$id' => 'project-x'], 'subject' => '', 'body' => '']),
|
||||
$this->project,
|
||||
$this->registry,
|
||||
$this->database
|
||||
$this->database,
|
||||
$this->platform
|
||||
);
|
||||
}
|
||||
|
||||
@@ -377,7 +380,7 @@ final class NotificationsTest extends TestCase
|
||||
'body' => 'Y',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$this->assertCount(1, $worker->dispatched);
|
||||
$this->assertSame('legacy@example.test', $worker->dispatched[0]['address']);
|
||||
@@ -409,7 +412,7 @@ final class NotificationsTest extends TestCase
|
||||
],
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} finally {
|
||||
\putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost);
|
||||
}
|
||||
@@ -443,7 +446,7 @@ final class NotificationsTest extends TestCase
|
||||
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Skipped mail processing. No SMTP configuration has been set.');
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} finally {
|
||||
\putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost);
|
||||
}
|
||||
@@ -469,7 +472,7 @@ final class NotificationsTest extends TestCase
|
||||
'body' => 'b',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$this->assertCount(2, $worker->dispatched);
|
||||
$this->assertSame('tenant-secret', $worker->dispatched[0]['signatureKey']);
|
||||
@@ -490,7 +493,7 @@ final class NotificationsTest extends TestCase
|
||||
];
|
||||
|
||||
try {
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
$this->fail('expected exception to propagate');
|
||||
} catch (\Throwable $error) {
|
||||
$this->assertSame('boom', $error->getMessage());
|
||||
@@ -521,7 +524,7 @@ final class NotificationsTest extends TestCase
|
||||
];
|
||||
|
||||
try {
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
$this->fail('expected webhook failure to propagate');
|
||||
} catch (\RuntimeException $error) {
|
||||
$this->assertSame('webhook down', $error->getMessage());
|
||||
@@ -534,7 +537,7 @@ final class NotificationsTest extends TestCase
|
||||
$this->assertSame(NOTIFICATION_TYPE_CONSOLE, $rows[0]->getAttribute('channel'));
|
||||
|
||||
$retry = new SpyNotifications();
|
||||
$retry->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$retry->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$this->assertCount(1, $retry->dispatched, 'retry should dispatch only the previously undelivered webhook');
|
||||
$this->assertSame(NOTIFICATION_TYPE_WEBHOOK, $retry->dispatched[0]['channel']);
|
||||
@@ -559,7 +562,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'console-skip',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
// The Console adapter wrote exactly one alert; the action loop
|
||||
// must NOT have called persistAlert (otherwise we'd see 2 rows or
|
||||
@@ -586,7 +589,7 @@ final class NotificationsTest extends TestCase
|
||||
];
|
||||
|
||||
try {
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
$this->fail('expected console zero-delivery to throw');
|
||||
} catch (\Throwable $error) {
|
||||
$this->assertStringContainsString('Console alert delivery failed', $error->getMessage());
|
||||
@@ -610,7 +613,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'fanout',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$rows = $this->database->find('notifications');
|
||||
$this->assertCount(2, $rows, 'two recipients must produce two distinct alert rows');
|
||||
@@ -647,7 +650,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'roundtrip',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$rows = $this->database->find('notifications');
|
||||
$this->assertCount(1, $rows);
|
||||
@@ -688,7 +691,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'logo-key',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} finally {
|
||||
\putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost);
|
||||
\putenv($previousTrackingSecret === false ? '_APP_NOTIFICATIONS_TRACKING_SECRET' : '_APP_NOTIFICATIONS_TRACKING_SECRET=' . $previousTrackingSecret);
|
||||
@@ -760,7 +763,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'logo-key-no-tracking-secret',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} finally {
|
||||
\putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost);
|
||||
\putenv($previousTrackingSecret === false ? '_APP_NOTIFICATIONS_TRACKING_SECRET' : '_APP_NOTIFICATIONS_TRACKING_SECRET=' . $previousTrackingSecret);
|
||||
@@ -792,7 +795,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'persist-email',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} finally {
|
||||
\putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost);
|
||||
}
|
||||
@@ -845,7 +848,7 @@ final class NotificationsTest extends TestCase
|
||||
|
||||
$threw = false;
|
||||
try {
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} catch (\Throwable $error) {
|
||||
$threw = true;
|
||||
$this->assertStringContainsString('SMTP unavailable', $error->getMessage());
|
||||
@@ -866,7 +869,7 @@ final class NotificationsTest extends TestCase
|
||||
$this->registry->set('smtp', static fn () => $working);
|
||||
|
||||
$retryWorker = new Notifications();
|
||||
$retryWorker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$retryWorker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$this->assertSame(1, $working->sendCount, 'retry must invoke the working adapter');
|
||||
|
||||
@@ -908,7 +911,7 @@ final class NotificationsTest extends TestCase
|
||||
|
||||
$threw = false;
|
||||
try {
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} catch (\Throwable $error) {
|
||||
$threw = true;
|
||||
$this->assertStringContainsString('SMTP unavailable', $error->getMessage());
|
||||
@@ -933,7 +936,7 @@ final class NotificationsTest extends TestCase
|
||||
$this->registry->set('smtp', static fn () => $working);
|
||||
|
||||
$retryWorker = new Notifications();
|
||||
$retryWorker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$retryWorker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$this->assertSame(1, $working->sendCount, 'retry must still deliver the email recipient');
|
||||
$rows = $this->database->find('notifications', [
|
||||
@@ -976,7 +979,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'happy-email',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} finally {
|
||||
\putenv($previousSmtpHost === false ? '_APP_SMTP_HOST' : '_APP_SMTP_HOST=' . $previousSmtpHost);
|
||||
\putenv($previousTrackingSecret === false ? '_APP_NOTIFICATIONS_TRACKING_SECRET' : '_APP_NOTIFICATIONS_TRACKING_SECRET=' . $previousTrackingSecret);
|
||||
@@ -1045,7 +1048,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'happy-console',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$rows = $this->database->find('notifications', [
|
||||
Query::equal('channel', ['console']),
|
||||
@@ -1088,7 +1091,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'console-preview',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$rows = $this->database->find('notifications');
|
||||
$this->assertCount(1, $rows);
|
||||
@@ -1116,7 +1119,7 @@ final class NotificationsTest extends TestCase
|
||||
];
|
||||
|
||||
try {
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
} catch (\Exception $error) {
|
||||
$this->assertStringContainsString('No SMTP configuration has been set', $error->getMessage());
|
||||
$threw = true;
|
||||
@@ -1148,7 +1151,7 @@ final class NotificationsTest extends TestCase
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Invalid console alert resourceId');
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1220,7 +1223,7 @@ final class NotificationsTest extends TestCase
|
||||
'deduplicationKey' => 'happy-webhook',
|
||||
];
|
||||
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database);
|
||||
$worker->action($this->buildMessage($payload), $this->project, $this->registry, $this->database, $this->platform);
|
||||
|
||||
$this->assertCount(1, $worker->captured, 'adapter must POST exactly once');
|
||||
$request = $worker->captured[0];
|
||||
|
||||
@@ -49,6 +49,7 @@ final class WebhooksTest extends TestCase
|
||||
]),
|
||||
dbForPlatform: $database,
|
||||
publisherForNotifications: $publisherForNotifications,
|
||||
platform: ['consoleUrl' => 'https://console.example.test'],
|
||||
plan: []
|
||||
);
|
||||
|
||||
@@ -68,7 +69,7 @@ final class WebhooksTest extends TestCase
|
||||
);
|
||||
$this->assertStringContainsString('Payments', (string) $payload['body']);
|
||||
$this->assertStringContainsString('Ada Lovelace', (string) $payload['body']);
|
||||
$this->assertStringContainsString('/projects/project-1/settings/webhooks', (string) $payload['body']);
|
||||
$this->assertStringContainsString('https://console.example.test/projects/project-1/settings/webhooks', (string) $payload['body']);
|
||||
$this->assertStringNotContainsString('{{', (string) $payload['body']);
|
||||
$this->assertSame(APP_NAME, $payload['variables']['platform']);
|
||||
$this->assertSame(APP_EMAIL_LOGO_URL, $payload['variables']['logoUrl']);
|
||||
@@ -134,6 +135,7 @@ final class WebhooksTest extends TestCase
|
||||
]),
|
||||
dbForPlatform: $database,
|
||||
publisherForNotifications: $publisherForNotifications,
|
||||
platform: ['consoleUrl' => 'https://console.example.test'],
|
||||
plan: []
|
||||
);
|
||||
|
||||
@@ -186,6 +188,7 @@ final class WebhooksTest extends TestCase
|
||||
project: $project,
|
||||
dbForPlatform: $database,
|
||||
publisherForNotifications: $publisherForNotifications,
|
||||
platform: ['consoleUrl' => 'https://console.example.test'],
|
||||
plan: []
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user