Fix tests

This commit is contained in:
Matej Bačo
2026-04-20 22:47:47 +02:00
parent 8c31e9f206
commit c3e411fcaa
5 changed files with 25 additions and 18 deletions
@@ -32,7 +32,7 @@ class Update extends Action
->desc('Update project labels')
->groups(['api', 'project'])
->label('scope', 'project.write')
->label('event', 'project.labels.update')
// ->label('event', 'project.labels.update')
->label('audits.event', 'project.labels.update')
->label('audits.resource', 'project.labels/{response.$id}')
->label('sdk', new Method(
@@ -40,7 +40,7 @@ class Update extends Action
->desc('Update project SMTP configuration')
->groups(['api', 'project'])
->label('scope', 'project.write')
->label('event', 'project.smtp.update')
// ->label('event', 'project.smtp.update')
->label('audits.event', 'project.smtp.update')
->label('audits.resource', 'project.smtp/{response.$id}')
->label('sdk', new Method(
@@ -106,11 +106,13 @@ class Update extends Action
// Backwards compatibility
$smtp['replyToEmail'] = $smtp['replyToEmail'] ?? $smtp['replyTo'] ?? '';
// Ensure required fields are set
$requiredKeys = ['host', 'port', 'senderEmail'];
foreach ($requiredKeys as $key) {
if (empty($smtp[$key])) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, '"' . $key . '" is required. Please provide a value.');
if (($smtp['enabled'] ?? false) === true) {
// Ensure required fields are set
$requiredKeys = ['host', 'port', 'senderEmail'];
foreach ($requiredKeys as $key) {
if (empty($smtp[$key])) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Param "' . $key . '" is not optional.');
}
}
}
@@ -78,16 +78,16 @@ class Get extends Action
$defaultMessage = $this->getDefaultMessage($templateId, $localeObj);
// Apply defaults if needed
if (\is_null($template['message'])) {
if (\is_null($template['message'] ?? null)) {
$template['message'] = $defaultMessage;
}
if (\is_null($template['subject'])) {
if (\is_null($template['subject'] ?? null)) {
$template['subject'] = $defaultSubject;
}
// Backwards compatibility
if (!\is_null($template['replyTo'])) {
if (!\is_null($template['replyTo'] ?? null)) {
$template['replyToEmail'] = $template['replyToEmail'] ?? $template['replyTo'] ?? '';
}
@@ -58,12 +58,12 @@ class Update extends Action
))
->param('templateId', '', new WhiteList(Config::getParam('locale-templates')['email'] ?? [], true), 'Custom email template type. Can be one of: '.\implode(', ', Config::getParam('locale-templates')['email'] ?? []))
->param('locale', '', fn ($localeCodes) => new WhiteList($localeCodes), 'Custom email template locale. If left empty, the fallback locale (en) will be used.', optional: true, injections: ['localeCodes'])
->param('subject', null, new Nullable(new Text(255)), 'Subject of the email template. Can be up to 255 characters.')
->param('message', null, new Nullable(new Text(10485760)), 'Plain or HTML body of the email template message. Can be up to 10MB of content.')
->param('senderName', null, new Nullable(new Text(255, 0)), 'Name of the email sender.', true)
->param('senderEmail', null, new Nullable(new Email()), 'Email of the sender.', true)
->param('replyToEmail', null, new Nullable(new Email()), 'Reply to email.', true)
->param('replyToName', null, new Nullable(new Text(255, 0)), 'Reply to name.', true)
->param('subject', null, new Nullable(new Text(255)), 'Subject of the email template. Can be up to 255 characters.', optional: true)
->param('message', null, new Nullable(new Text(10485760)), 'Plain or HTML body of the email template message. Can be up to 10MB of content.', optional: true)
->param('senderName', null, new Nullable(new Text(255, 0)), 'Name of the email sender.', optional: true)
->param('senderEmail', null, new Nullable(new Email()), 'Email of the sender.', optional: true)
->param('replyToEmail', null, new Nullable(new Email()), 'Reply to email.', optional: true)
->param('replyToName', null, new Nullable(new Text(255, 0)), 'Reply to name.', optional: true)
->inject('response')
->inject('queueForEvents')
->inject('dbForPlatform')
@@ -108,7 +108,9 @@ class Update extends Action
}
// Backwards compatibility
$template['replyToEmail'] = $template['replyToEmail'] ?? $template['replyTo'] ?? '';
if (!\is_null($template['replyTo'] ?? null)) {
$template['replyToEmail'] = $template['replyToEmail'] ?? $template['replyTo'] ?? '';
}
// Ensure required fields are set
$requiredKeys = ['subject', 'message'];
+4 -1
View File
@@ -550,7 +550,7 @@ trait TemplatesBase
public function testUpdateEmailTemplateBlockedWhenSMTPDisabled(): void
{
// Custom templates only make sense alongside a custom SMTP configuration.
$this->client->call(
$response = $this->client->call(
Client::METHOD_PATCH,
'/project/smtp',
\array_merge([
@@ -560,6 +560,9 @@ trait TemplatesBase
['enabled' => false],
);
$this->assertSame(200, $response['headers']['status-code']);
$this->assertSame(false, $response['body']['smtpEnabled']);
try {
$response = $this->updateEmailTemplate(
templateId: 'verification',