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
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Repository;
|
||||
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\TeamerMailingRecipient;
|
||||
use App\Repository\TeamerRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* Who an assignment mailing reaches. Run against db_test with real rows, because the question is
|
||||
* which teamers come back: confirmed ones only, each once however many of the assignments they
|
||||
* are on, and none from an assignment that was not picked.
|
||||
*
|
||||
* Every test runs inside a transaction that is rolled back, so db_test - shared between
|
||||
* branches - keeps nothing.
|
||||
*/
|
||||
class TeamerRepositoryAssignmentMailingTest extends KernelTestCase
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private TeamerRepository $repository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
|
||||
$this->repository = $this->entityManager->getRepository(Teamer::class);
|
||||
$this->entityManager->getConnection()->beginTransaction();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->entityManager->getConnection()->rollBack();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testATeamerConfirmedOnTwoPickedAssignmentsIsWrittenToOnce(): void
|
||||
{
|
||||
$first = $this->assignment();
|
||||
$second = $this->assignment();
|
||||
$teamer = $this->teamer('Anna');
|
||||
$this->place($teamer, $first, Disposition::STATUS_CONFIRMED);
|
||||
$this->place($teamer, $second, Disposition::STATUS_CONFIRMED);
|
||||
|
||||
$this->assertSame(['Anna'], $this->recipientNames([$first, $second]));
|
||||
}
|
||||
|
||||
public function testOnlyConfirmedDispositionsCount(): void
|
||||
{
|
||||
$assignment = $this->assignment();
|
||||
$this->place($this->teamer('Anna'), $assignment, Disposition::STATUS_CONFIRMED);
|
||||
$this->place($this->teamer('Bea'), $assignment, Disposition::STATUS_NEW);
|
||||
$this->place($this->teamer('Cem'), $assignment, Disposition::STATUS_CHECKING_CONTRACT);
|
||||
$this->place($this->teamer('Dana'), $assignment, Disposition::STATUS_CALLED_OFF);
|
||||
$this->place($this->teamer('Emil'), $assignment, Disposition::STATUS_ENDED);
|
||||
|
||||
$this->assertSame(['Anna'], $this->recipientNames([$assignment]));
|
||||
}
|
||||
|
||||
public function testAnAssignmentThatWasNotPickedIsLeftOut(): void
|
||||
{
|
||||
$picked = $this->assignment();
|
||||
$other = $this->assignment();
|
||||
$this->place($this->teamer('Anna'), $picked, Disposition::STATUS_CONFIRMED);
|
||||
$this->place($this->teamer('Bea'), $other, Disposition::STATUS_CONFIRMED);
|
||||
|
||||
$this->assertSame(['Anna'], $this->recipientNames([$picked]));
|
||||
}
|
||||
|
||||
public function testNoAssignmentsMeansNoRecipients(): void
|
||||
{
|
||||
$this->place($this->teamer('Anna'), $this->assignment(), Disposition::STATUS_CONFIRMED);
|
||||
|
||||
$this->assertSame([], $this->repository->getAssignmentMailingRecipients([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Assignment[] $assignments
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function recipientNames(array $assignments): array
|
||||
{
|
||||
$this->entityManager->flush();
|
||||
|
||||
$names = array_map(
|
||||
fn (TeamerMailingRecipient $recipient) => $recipient->getFirstName(),
|
||||
$this->repository->getAssignmentMailingRecipients($assignments)
|
||||
);
|
||||
sort($names);
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
private function assignment(): Assignment
|
||||
{
|
||||
$destination = (new Destination())
|
||||
->setProduct('Davos Klosters - Schwendi')
|
||||
->setHotel('Schwendi')
|
||||
->setHotelCode('DKI')
|
||||
->setHotelBusProId(1)
|
||||
->setDateFrom(new \DateTimeImmutable('+7 days'))
|
||||
->setDateTo(new \DateTimeImmutable('+14 days'))
|
||||
->setPickups([])
|
||||
;
|
||||
$assignment = (new Assignment())
|
||||
->setDestination($destination)
|
||||
->setStatus(Assignment::STATUS_STAFFED)
|
||||
;
|
||||
|
||||
$this->entityManager->persist($destination);
|
||||
$this->entityManager->persist($assignment);
|
||||
|
||||
return $assignment;
|
||||
}
|
||||
|
||||
private function teamer(string $firstName): Teamer
|
||||
{
|
||||
$teamer = (new Teamer())->setFirstName($firstName)->setLastName('Muster')->setGender('d');
|
||||
$this->entityManager->persist($teamer);
|
||||
|
||||
return $teamer;
|
||||
}
|
||||
|
||||
private function place(Teamer $teamer, Assignment $assignment, string $status): void
|
||||
{
|
||||
$disposition = (new Disposition(new Application($assignment, $teamer)))->setStatus($status);
|
||||
|
||||
$this->entityManager->persist($disposition);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user