feat: copy the house managers of the selected houses on assignment mailings

This commit is contained in:
fromme committed 2026-11-12 12:45:53 +01:00
1 parent 2c51ddf86f
commit f22d1f1199
17 files changed
+293 -24

No files matched your search

@@ -18,6 +18,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
/**
@@ -254,6 +255,69 @@ class AssignmentMailingControllerTest extends WebTestCase
$this->assertSame(['Anna Muster ([email protected])'], $this->colleaguesIn('[email protected]'));
}
/**
* Each house manager once per mailing, on the mail of the first recipient of their house -
* muted or not - and never one of another house or a blocked one.
*/
public function testHouseManagersAreInCcOnOneMailOfTheirHouse(): void
{
// codes of no real house: other tests leave house managers of real ones in db_test
$schwendi = $this->assignment('Schwendi', 'XQSWE');
$rotbach = $this->assignment('Rotbach', 'XQR');
$this->place($this->teamer('Anna'), $schwendi, Disposition::STATUS_CONFIRMED);
$this->place($this->teamer('Cem'), $schwendi, Disposition::STATUS_CONFIRMED);
$this->place($this->teamer('Dora'), $rotbach, Disposition::STATUS_CONFIRMED);
$this->houseManager('Greta', ['XQR']);
$this->houseManager('Hugo', ['XQS']);
$this->houseManager('Hanna', ['XQS'])->setMuteNotifications(true);
$this->houseManager('Paul', ['XQP']);
$this->houseManager('Dieter', ['XQS'])->setDisabledAt(new \DateTimeImmutable());
$this->login('ROLE_MANAGER');
$crawler = $this->startMailing($schwendi, $rotbach);
$this->assertStringContainsString(
'In Kopie (Hausleitung): Hugo Hausleitung, Hanna Hausleitung, Greta Hausleitung',
$crawler->filter('#mailing-assignments')->text()
);
$this->client->request('POST', self::COMPOSE_URL.'/send', [
'assignment_mailing' => $this->mailingFields($crawler, 'Treffpunkt', 'Hallo'),
]);
$this->assertEmailCount(3);
$this->assertSame(['[email protected]', '[email protected]'], $this->ccIn('[email protected]'));
$this->assertSame([], $this->ccIn('[email protected]'));
$this->assertSame(['[email protected]'], $this->ccIn('[email protected]'));
}
/**
* Placed on the travel as a teamer, or writing under the address of one, the house manager has
* the mail already.
*/
public function testAHouseManagerWhoIsARecipientIsNotInCc(): void
{
$assignment = $this->assignment('Schwendi', 'XQS');
$anna = $this->teamer('Anna');
$this->place($anna, $assignment, Disposition::STATUS_CONFIRMED);
$this->place($this->teamer('Cem'), $assignment, Disposition::STATUS_CONFIRMED);
$this->houseManager('Hugo', ['XQS'])->setTeamer($anna);
$this->houseManager('Hanna', ['XQS'])->setEmail('[email protected]');
$this->login('ROLE_MANAGER');
$crawler = $this->startMailing($assignment);
$this->assertStringNotContainsString('In Kopie', $crawler->filter('#mailing-assignments')->text());
$this->client->request('POST', self::COMPOSE_URL.'/send', [
'assignment_mailing' => $this->mailingFields($crawler, 'Treffpunkt', 'Hallo'),
]);
$this->assertEmailCount(2);
$this->assertSame([], $this->ccIn('[email protected]'));
$this->assertSame([], $this->ccIn('[email protected]'));
}
public function testColleagueNamesAreEscaped(): void
{
$assignment = $this->assignment('Schwendi');
@@ -354,6 +418,22 @@ class AssignmentMailingControllerTest extends WebTestCase
$this->fail(sprintf('No mail to %s', $to));
}
/**
* The CC addresses of the mail sent to the given address.
*
* @return string[]
*/
private function ccIn(string $to): array
{
foreach ($this->getMailerMessages() as $message) {
if ($message instanceof Email && $to === $message->getTo()[0]->getAddress()) {
return array_map(fn (Address $address) => $address->getAddress(), $message->getCc());
}
}
$this->fail(sprintf('No mail to %s', $to));
}
private function startMailing(Assignment ...$assignments): Crawler
{
$this->entityManager->flush();
@@ -399,12 +479,12 @@ class AssignmentMailingControllerTest extends WebTestCase
$this->client->loginUser($user);
}
private function assignment(string $hotel): Assignment
private function assignment(string $hotel, string $hotelCode = 'DKI'): Assignment
{
$destination = (new Destination())
->setProduct('Davos Klosters')
->setHotel($hotel)
->setHotelCode('DKI')
->setHotelCode($hotelCode)
->setHotelBusProId(1)
->setCountry('CH')
->setDateFrom(new \DateTimeImmutable('+7 days'))
@@ -424,6 +504,25 @@ class AssignmentMailingControllerTest extends WebTestCase
return $assignment;
}
/**
* @param string[] $hotelCodes
*/
private function houseManager(string $firstName, array $hotelCodes): User
{
$user = (new User())
->setFirstName($firstName)
->setLastName('Hausleitung')
->setEmail(strtolower($firstName).'[email protected]')
->setRoles(['ROLE_HOUSE_MANAGER'])
->setHotelCodes($hotelCodes)
->setBusProAddressId(1)
->setBusProPersonId(1)
;
$this->entityManager->persist($user);
return $user;
}
private function teamer(string $firstName): Teamer
{
$teamer = (new Teamer())
@@ -85,6 +85,7 @@ class EmailTextMailRenderingTest extends KernelTestCase
'transport' => null,
'bus_transport' => null,
'reply_to' => null,
'cc' => [],
]);
$html = $email->getHtmlBody();
+1
View File
@@ -50,6 +50,7 @@ class MailerTest extends KernelTestCase
'transport' => $transport,
'bus_transport' => null,
'reply_to' => null,
'cc' => [],
]);
}
}
@@ -73,7 +73,7 @@ class HouseManagerReminderQueryTest extends KernelTestCase
/** @var UserRepository $repository */
$repository = $this->entityManager->getRepository(User::class);
$reminded = $repository->findHouseManagersToRemind();
$reminded = $repository->findActiveHouseManagers();
$this->assertContains($active, $reminded);
$this->assertNotContains($blocked, $reminded);
@@ -53,7 +53,7 @@ class FeedbackReminderServiceTest extends TestCase
{
$houseManager = $this->houseManager('[email protected]', ['DKI']);
$this->userRepository->method('findHouseManagersToRemind')->willReturn([$houseManager]);
$this->userRepository->method('findActiveHouseManagers')->willReturn([$houseManager]);
$this->destinationRepository
->expects($this->once())
->method('findPendingForHouseManager')
@@ -66,7 +66,7 @@ class FeedbackReminderServiceTest extends TestCase
public function testMutedHouseManagersAndThoseWithoutHotelCodesAreSkipped(): void
{
$this->userRepository->method('findHouseManagersToRemind')->willReturn([
$this->userRepository->method('findActiveHouseManagers')->willReturn([
$this->houseManager('[email protected]', ['DKI'])->setMuteNotifications(true),
$this->houseManager('[email protected]', []),
]);
@@ -83,7 +83,7 @@ class FeedbackReminderServiceTest extends TestCase
*/
public function testNoMailOnANightNothingIsDue(): void
{
$this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
$this->userRepository->method('findActiveHouseManagers')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($this->travel(10))]);
$this->mailer->expects($this->never())->method('createAndSendEmail');
@@ -98,7 +98,7 @@ class FeedbackReminderServiceTest extends TestCase
$due = $this->travel(14);
$quiet = $this->travel(10);
$this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
$this->userRepository->method('findActiveHouseManagers')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([$this->row($quiet), $this->row($due)]);
$this->mailer
->expects($this->once())
@@ -124,7 +124,7 @@ class FeedbackReminderServiceTest extends TestCase
$untouched = $this->travel(3); // ended 2026-11-17
$submitted = $this->travel(1); // ended 2026-11-19
$this->userRepository->method('findHouseManagersToRemind')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
$this->userRepository->method('findActiveHouseManagers')->willReturn([$this->houseManager('[email protected]', ['DKI'])]);
$this->destinationRepository->method('findPendingForHouseManager')->willReturn([
$this->row($beforeGoLive, null, 2),
$this->row($draft, 'draft', 0),
@@ -338,6 +338,52 @@ class TeamerMailingServiceTest extends TestCase
$this->assertSame(['[email protected]', '[email protected]'], $replyTo);
}
public function testSendMailingPutsEachRecipientsCcOnTheirMailOnly(): void
{
$cc = [];
$this->mailer
->expects($this->exactly(2))
->method('createAndSendEmail')
->willReturnCallback(function (array $context, array $options) use (&$cc): void {
$cc[$options['to']] = $options['cc'];
})
;
$anna = $this->createRecipient('Anna', 'Berg', '[email protected]');
$recipients = (new TeamerMailingRecipientsDto())
->addEligible($anna)
->addEligible($this->createRecipient('Bea', 'Ohm', '[email protected]'))
;
$this->service->sendMailing(SendTeamerMailing::fromRecipients(
'Betreff',
'Nachricht',
$recipients,
cc: [$anna->getId() => ['[email protected]', '[email protected]']]
));
$this->assertSame([
'[email protected]' => ['[email protected]', '[email protected]'],
'[email protected]' => [],
], $cc);
}
public function testAMailingQueuedWithoutTheCcSendsNone(): void
{
$this->mailer
->expects($this->once())
->method('createAndSendEmail')
->willReturnCallback(function (array $context, array $options): void {
$this->assertSame([], $options['cc']);
})
;
// the snapshot as it was queued before the 'cc' key existed
$this->service->sendMailing(new SendTeamerMailing('Betreff', 'Nachricht', [
['email' => '[email protected]', 'firstName' => 'Anna', 'lastName' => 'Berg', 'fullName' => 'Anna Berg'],
]));
}
/**
* 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.