Decision now support auto mailing

This commit is contained in:
Simon Pocrnjič
2025-10-12 00:20:03 +02:00
parent 1b615163be
commit 3ab1c05fcc
33 changed files with 1862 additions and 548 deletions
+31 -2
View File
@@ -2,12 +2,40 @@
use App\Services\EmailTemplateRenderer;
it('renders activity placeholders', function () {
/** @var EmailTemplateRenderer $renderer */
$renderer = app(EmailTemplateRenderer::class);
$activity = (object) [
'note' => 'Call client about payment',
'due_date' => '2025-10-15',
'amount' => 123.45,
'action' => (object) ['name' => 'CALL - OUTBOUND'],
'decision' => (object) ['name' => 'Promise'],
];
$tpl = [
'subject' => 'Action: {{ activity.action.name }}',
'html' => '<p>{{ activity.note }}</p><p>{{ activity.decision.name }} {{ activity.due_date }} {{ activity.amount }}</p>',
'text' => 'Note: {{ activity.note }}',
];
$out = $renderer->render($tpl, [
'activity' => $activity,
]);
expect($out['subject'])->toBe('Action: CALL - OUTBOUND');
expect($out['html'])
->toContain('<p>Call client about payment</p>')
->toContain('<p>Promise 15.10.2025 123,45 €</p>');
expect($out['text'])->toBe('Note: Call client about payment');
});
it('renders placeholders in subject, html and text', function () {
$renderer = new EmailTemplateRenderer;
$template = [
'subject' => 'Hello {{ person.full_name }} - {{ contract.reference }}',
'html' => '<p>Case: {{ case.uuid }}</p><p>Meta: {{ contract.meta.foo }}</p>',
'html' => '<p>Case: {{ case.uuid }}</p><p>Meta: {{ contract.meta.foo }}</p><p>Amount: {{ contract.amount }}</p>',
'text' => 'Client: {{ client.uuid }} Extra: {{ extra.note }}',
];
@@ -15,7 +43,7 @@
'person' => (object) ['first_name' => 'Jane', 'last_name' => 'Doe', 'email' => 'jane@example.test'],
'client' => (object) ['uuid' => 'cl-123'],
'client_case' => (object) ['uuid' => 'cc-456', 'reference' => 'REF-1'],
'contract' => (object) ['uuid' => 'co-789', 'reference' => 'CON-42', 'meta' => ['foo' => 'bar']],
'contract' => (object) ['uuid' => 'co-789', 'reference' => 'CON-42', 'amount' => 1000, 'meta' => ['foo' => 'bar']],
'extra' => ['note' => 'hello'],
];
@@ -24,5 +52,6 @@
expect($result['subject'])->toBe('Hello Jane Doe - CON-42');
expect($result['html'])->toContain('Case: cc-456');
expect($result['html'])->toContain('Meta: bar');
expect($result['html'])->toContain('Amount: 1.000,00 €');
expect($result['text'])->toBe('Client: cl-123 Extra: hello');
});