1
0

fix(helpdesk): inject appTitle/appUrl into HandoverNotificationService to avoid DB calls in tests

This commit is contained in:
aminovfariz
2026-06-05 14:10:13 +02:00
parent b8fc55bcc2
commit 3f08f6189e
4 changed files with 31 additions and 8 deletions

View File

@@ -145,7 +145,9 @@ final class HelpdeskContainerRegistrar implements ContainerRegistrar
));
$container->set(HandoverNotificationService::class, static fn (AppContainer $c): HandoverNotificationService => new HandoverNotificationService(
$c->get(MailService::class)
$c->get(MailService::class),
appTitle(),
appUrl(),
));
$container->set(HandoverService::class, static fn (AppContainer $c): HandoverService => new HandoverService(

View File

@@ -8,9 +8,24 @@ class HandoverNotificationService
{
public function __construct(
private readonly MailService $mailService,
private readonly string $appTitle = '',
private readonly string $appUrl = '',
) {
}
private function resolveAppTitle(): string
{
return $this->appTitle !== '' ? $this->appTitle : appTitle();
}
private function resolveAppUrl(string $path = ''): string
{
if ($this->appUrl !== '') {
return rtrim($this->appUrl, '/') . ($path !== '' ? '/' . ltrim($path, '/') : '');
}
return appUrl($path);
}
/**
* Notify the assignee that a handover was assigned to them.
*
@@ -29,7 +44,7 @@ class HandoverNotificationService
$domainUrl = trim((string) ($handover['domain_url'] ?? ''));
$dueDate = trim((string) ($handover['due_date'] ?? ''));
$handoverId = (int) ($handover['id'] ?? 0);
$handoverUrl = appUrl('helpdesk/handovers/edit/' . $handoverId);
$handoverUrl = $this->resolveAppUrl('helpdesk/handovers/edit/' . $handoverId);
$vars = [
'assignee_name' => $assigneeName,
@@ -38,10 +53,10 @@ class HandoverNotificationService
'domain_url' => $domainUrl !== '' ? $domainUrl : '—',
'due_date' => $dueDate !== '' ? $dueDate : '—',
'handover_url' => $handoverUrl,
'app_name' => appTitle(),
'app_name' => $this->resolveAppTitle(),
];
$subject = sprintf('[%s] Ihnen wurde eine Übergabe zugewiesen', appTitle());
$subject = sprintf('[%s] Ihnen wurde eine Übergabe zugewiesen', $this->resolveAppTitle());
$this->mailService->sendTemplate('handover_assigned', $vars, $toEmail, $subject);
}
@@ -69,7 +84,7 @@ class HandoverNotificationService
$debitorName = trim((string) ($handover['debitor_name'] ?? ''));
$domainUrl = trim((string) ($handover['domain_url'] ?? ''));
$handoverId = (int) ($handover['id'] ?? 0);
$handoverUrl = appUrl('helpdesk/handovers/edit/' . $handoverId);
$handoverUrl = $this->resolveAppUrl('helpdesk/handovers/edit/' . $handoverId);
$vars = [
'manager_name' => $managerName,
@@ -77,10 +92,10 @@ class HandoverNotificationService
'debitor_name' => $debitorName !== '' ? $debitorName : '—',
'domain_url' => $domainUrl !== '' ? $domainUrl : '—',
'handover_url' => $handoverUrl,
'app_name' => appTitle(),
'app_name' => $this->resolveAppTitle(),
];
$subject = sprintf('[%s] Übergabe wurde zur Prüfung eingereicht', appTitle());
$subject = sprintf('[%s] Übergabe wurde zur Prüfung eingereicht', $this->resolveAppTitle());
$this->mailService->sendTemplate('handover_review_requested', $vars, $toEmail, $subject);
}

View File

@@ -24,6 +24,10 @@ return gridFilterSchema([
'search' => true,
'query' => ['type' => 'string'],
],
[
'key' => 'view',
'type' => 'hidden',
],
[
'key' => 'status',
'type' => 'select',

View File

@@ -11,7 +11,9 @@ class HandoverNotificationServiceTest extends TestCase
private function createNotificationService(?MailService $mailService = null): HandoverNotificationService
{
return new HandoverNotificationService(
$mailService ?? $this->createMock(MailService::class)
$mailService ?? $this->createMock(MailService::class),
'TestApp',
'http://localhost',
);
}