fix(helpdesk): inject appTitle/appUrl into HandoverNotificationService to avoid DB calls in tests
This commit is contained in:
@@ -145,7 +145,9 @@ final class HelpdeskContainerRegistrar implements ContainerRegistrar
|
|||||||
));
|
));
|
||||||
|
|
||||||
$container->set(HandoverNotificationService::class, static fn (AppContainer $c): HandoverNotificationService => new HandoverNotificationService(
|
$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(
|
$container->set(HandoverService::class, static fn (AppContainer $c): HandoverService => new HandoverService(
|
||||||
|
|||||||
@@ -8,9 +8,24 @@ class HandoverNotificationService
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly MailService $mailService,
|
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.
|
* Notify the assignee that a handover was assigned to them.
|
||||||
*
|
*
|
||||||
@@ -29,7 +44,7 @@ class HandoverNotificationService
|
|||||||
$domainUrl = trim((string) ($handover['domain_url'] ?? ''));
|
$domainUrl = trim((string) ($handover['domain_url'] ?? ''));
|
||||||
$dueDate = trim((string) ($handover['due_date'] ?? ''));
|
$dueDate = trim((string) ($handover['due_date'] ?? ''));
|
||||||
$handoverId = (int) ($handover['id'] ?? 0);
|
$handoverId = (int) ($handover['id'] ?? 0);
|
||||||
$handoverUrl = appUrl('helpdesk/handovers/edit/' . $handoverId);
|
$handoverUrl = $this->resolveAppUrl('helpdesk/handovers/edit/' . $handoverId);
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
'assignee_name' => $assigneeName,
|
'assignee_name' => $assigneeName,
|
||||||
@@ -38,10 +53,10 @@ class HandoverNotificationService
|
|||||||
'domain_url' => $domainUrl !== '' ? $domainUrl : '—',
|
'domain_url' => $domainUrl !== '' ? $domainUrl : '—',
|
||||||
'due_date' => $dueDate !== '' ? $dueDate : '—',
|
'due_date' => $dueDate !== '' ? $dueDate : '—',
|
||||||
'handover_url' => $handoverUrl,
|
'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);
|
$this->mailService->sendTemplate('handover_assigned', $vars, $toEmail, $subject);
|
||||||
}
|
}
|
||||||
@@ -69,7 +84,7 @@ class HandoverNotificationService
|
|||||||
$debitorName = trim((string) ($handover['debitor_name'] ?? ''));
|
$debitorName = trim((string) ($handover['debitor_name'] ?? ''));
|
||||||
$domainUrl = trim((string) ($handover['domain_url'] ?? ''));
|
$domainUrl = trim((string) ($handover['domain_url'] ?? ''));
|
||||||
$handoverId = (int) ($handover['id'] ?? 0);
|
$handoverId = (int) ($handover['id'] ?? 0);
|
||||||
$handoverUrl = appUrl('helpdesk/handovers/edit/' . $handoverId);
|
$handoverUrl = $this->resolveAppUrl('helpdesk/handovers/edit/' . $handoverId);
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
'manager_name' => $managerName,
|
'manager_name' => $managerName,
|
||||||
@@ -77,10 +92,10 @@ class HandoverNotificationService
|
|||||||
'debitor_name' => $debitorName !== '' ? $debitorName : '—',
|
'debitor_name' => $debitorName !== '' ? $debitorName : '—',
|
||||||
'domain_url' => $domainUrl !== '' ? $domainUrl : '—',
|
'domain_url' => $domainUrl !== '' ? $domainUrl : '—',
|
||||||
'handover_url' => $handoverUrl,
|
'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);
|
$this->mailService->sendTemplate('handover_review_requested', $vars, $toEmail, $subject);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ return gridFilterSchema([
|
|||||||
'search' => true,
|
'search' => true,
|
||||||
'query' => ['type' => 'string'],
|
'query' => ['type' => 'string'],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'key' => 'view',
|
||||||
|
'type' => 'hidden',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'key' => 'status',
|
'key' => 'status',
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ class HandoverNotificationServiceTest extends TestCase
|
|||||||
private function createNotificationService(?MailService $mailService = null): HandoverNotificationService
|
private function createNotificationService(?MailService $mailService = null): HandoverNotificationService
|
||||||
{
|
{
|
||||||
return new HandoverNotificationService(
|
return new HandoverNotificationService(
|
||||||
$mailService ?? $this->createMock(MailService::class)
|
$mailService ?? $this->createMock(MailService::class),
|
||||||
|
'TestApp',
|
||||||
|
'http://localhost',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user