feat: add mailing templates and mail the confirmed teamers of selected assignments
This commit is contained in:
1 parent
6c89f1b8a9
commit
e285646bb2
57 files changed
+3525
-31
No files matched your search
@@ -6,9 +6,11 @@ namespace App\Tests\Service\Teamer;
|
||||
|
||||
use App\Email\MailBodyRenderer;
|
||||
use App\Email\Mailer;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\User;
|
||||
use App\Message\SendTeamerMailing;
|
||||
use App\Model\EmailPathAttachmentDto;
|
||||
use App\Model\TeamerFilterDto;
|
||||
use App\Model\TeamerMailingDto;
|
||||
use App\Model\TeamerMailingRecipient;
|
||||
@@ -168,6 +170,83 @@ class TeamerMailingServiceTest extends TestCase
|
||||
$this->service->sendMailing($this->createMailing('Betreff', 'Nachricht'));
|
||||
}
|
||||
|
||||
public function testResolveAssignmentRecipientsPartitionsTheConfirmedTeamers(): void
|
||||
{
|
||||
$eligible = $this->createRecipient('Anna', 'Berg', '[email protected]');
|
||||
$disabled = $this->createRecipient('Cem', 'Dal', '[email protected]', disabled: true);
|
||||
|
||||
$this->teamerRepository
|
||||
->method('getAssignmentMailingRecipients')
|
||||
->willReturn([$eligible, $disabled])
|
||||
;
|
||||
|
||||
$recipients = $this->service->resolveAssignmentRecipients([new Assignment()]);
|
||||
|
||||
$this->assertSame([$eligible], $recipients->getEligible());
|
||||
$this->assertSame(1, $recipients->getSkippedDisabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* By path and nothing else: the queued mail of every recipient has to stay small, the file is
|
||||
* read only when that mail is sent.
|
||||
*/
|
||||
public function testSendMailingAttachesTheFilesByPathToEveryMail(): void
|
||||
{
|
||||
$attached = [];
|
||||
$this->mailer
|
||||
->expects($this->exactly(2))
|
||||
->method('createAndSendEmail')
|
||||
->willReturnCallback(function (array $context, array $options) use (&$attached): void {
|
||||
$attached[] = array_map(
|
||||
fn (EmailPathAttachmentDto $attachment) => [$attachment->getPath(), $attachment->getName()],
|
||||
$options['attachments']
|
||||
);
|
||||
})
|
||||
;
|
||||
|
||||
$recipients = (new TeamerMailingRecipientsDto())
|
||||
->addEligible($this->createRecipient('Anna', 'Berg', '[email protected]'))
|
||||
->addEligible($this->createRecipient('Bea', 'Ohm', '[email protected]'))
|
||||
;
|
||||
|
||||
$this->service->sendMailing(SendTeamerMailing::fromRecipients('Betreff', 'Nachricht', $recipients, [
|
||||
['path' => '/uploads/mailing_template/a/a.pdf', 'name' => 'Packliste.pdf'],
|
||||
]));
|
||||
|
||||
$this->assertSame([
|
||||
[['/uploads/mailing_template/a/a.pdf', 'Packliste.pdf']],
|
||||
[['/uploads/mailing_template/a/a.pdf', 'Packliste.pdf']],
|
||||
], $attached);
|
||||
}
|
||||
|
||||
public function testSendMailingWithoutAttachmentsAttachesNothing(): void
|
||||
{
|
||||
$this->mailer
|
||||
->expects($this->once())
|
||||
->method('createAndSendEmail')
|
||||
->willReturnCallback(function (array $context, array $options): void {
|
||||
$this->assertSame([], $options['attachments']);
|
||||
})
|
||||
;
|
||||
|
||||
$this->service->sendMailing($this->createMailing(
|
||||
'Betreff',
|
||||
'Nachricht',
|
||||
$this->createRecipient('Anna', 'Berg', '[email protected]')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* A mailing queued before the attachments existed comes out of the queue without the
|
||||
* property; it has to send as it would have, not fail in the worker.
|
||||
*/
|
||||
public function testAMailingQueuedWithoutAttachmentsHasNone(): void
|
||||
{
|
||||
$mailing = (new \ReflectionClass(SendTeamerMailing::class))->newInstanceWithoutConstructor();
|
||||
|
||||
$this->assertSame([], $mailing->getAttachments());
|
||||
}
|
||||
|
||||
/**
|
||||
* A preview has to stay on the default relay and the default queue, or composing a
|
||||
* mailing would wait on the same worker the mailing itself is queued behind.
|
||||
|
||||
Reference in new issue
Block a user