feat: list and show submitted questionnaires to the office
This commit is contained in:
1 parent
890e04f8a6
commit
a35f91ac63
15 files changed
+715
-46
No files matched your search
@@ -4,14 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\Questionnaire\Definition;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
@@ -27,6 +22,8 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
*/
|
||||
class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
{
|
||||
use QuestionnaireFixturesTrait;
|
||||
|
||||
private const string GO_LIVE = '2026-01-01';
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
@@ -138,45 +135,4 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
|
||||
|
||||
return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, new \DateTimeImmutable(self::GO_LIVE));
|
||||
}
|
||||
|
||||
private function escort(string $dateTo = 'yesterday', ?Teamer $teamer = null): Disposition
|
||||
{
|
||||
$destination = (new Destination())
|
||||
->setProduct('Davos Klosters - Schwendi')
|
||||
->setHotel('Schwendi')
|
||||
->setHotelCode('DKI')
|
||||
->setHotelBusProId(1)
|
||||
->setDateFrom(new \DateTimeImmutable($dateTo.' -7 days'))
|
||||
->setDateTo(new \DateTimeImmutable($dateTo))
|
||||
->setPickups([['busProId' => 4711, 'city' => 'Stuttgart', 'street' => 'Busbahnhof', 'time' => '21:30']])
|
||||
;
|
||||
$assignment = (new Assignment())
|
||||
->setDestination($destination)
|
||||
->setPickup(4711)
|
||||
->setStatus(Assignment::STATUS_STAFFED)
|
||||
;
|
||||
$disposition = (new Disposition(new Application($assignment, $teamer ?? $this->teamer)))
|
||||
->setStatus(Disposition::STATUS_ENDED)
|
||||
;
|
||||
|
||||
$this->entityManager->persist($destination);
|
||||
$this->entityManager->persist($assignment);
|
||||
$this->entityManager->persist($disposition);
|
||||
|
||||
return $disposition;
|
||||
}
|
||||
|
||||
private function respond(Disposition $disposition, bool $submit, string $questionnaire = QuestionnaireCatalog::TEAMER_ESCORT): void
|
||||
{
|
||||
$definition = new Definition($questionnaire, 1, 'Beispiel', null, []);
|
||||
$response = QuestionnaireResponse::forDisposition($definition, $disposition);
|
||||
|
||||
if ($submit) {
|
||||
$response->submit($definition, [], [], new \DateTimeImmutable());
|
||||
} else {
|
||||
$response->saveDraft([], []);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\Questionnaire\Definition;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* Escort placements and questionnaire responses for running the questionnaire queries against
|
||||
* db_test. The using test owns $entityManager and $teamer, and rolls its transaction back.
|
||||
*
|
||||
* @property EntityManagerInterface $entityManager
|
||||
* @property Teamer $teamer
|
||||
*/
|
||||
trait QuestionnaireFixturesTrait
|
||||
{
|
||||
private function escort(string $dateTo = 'yesterday', ?Teamer $teamer = null, string $hotel = 'Schwendi'): Disposition
|
||||
{
|
||||
$destination = (new Destination())
|
||||
->setProduct('Davos Klosters - Schwendi')
|
||||
->setHotel($hotel)
|
||||
->setHotelCode('DKI')
|
||||
->setHotelBusProId(1)
|
||||
->setDateFrom(new \DateTimeImmutable($dateTo.' -7 days'))
|
||||
->setDateTo(new \DateTimeImmutable($dateTo))
|
||||
->setPickups([['busProId' => 4711, 'city' => 'Stuttgart', 'street' => 'Busbahnhof', 'time' => '21:30']])
|
||||
;
|
||||
$assignment = (new Assignment())
|
||||
->setDestination($destination)
|
||||
->setPickup(4711)
|
||||
->setStatus(Assignment::STATUS_STAFFED)
|
||||
;
|
||||
$disposition = (new Disposition(new Application($assignment, $teamer ?? $this->teamer)))
|
||||
->setStatus(Disposition::STATUS_ENDED)
|
||||
;
|
||||
|
||||
$this->entityManager->persist($destination);
|
||||
$this->entityManager->persist($assignment);
|
||||
$this->entityManager->persist($disposition);
|
||||
|
||||
return $disposition;
|
||||
}
|
||||
|
||||
private function respond(Disposition $disposition, bool $submit, string $questionnaire = QuestionnaireCatalog::TEAMER_ESCORT): QuestionnaireResponse
|
||||
{
|
||||
$definition = new Definition($questionnaire, 1, 'Beispiel', null, []);
|
||||
$response = QuestionnaireResponse::forDisposition($definition, $disposition);
|
||||
|
||||
if ($submit) {
|
||||
$response->submit($definition, [], [], new \DateTimeImmutable());
|
||||
} else {
|
||||
$response->saveDraft([], []);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\QuestionnaireResponseFilterDto;
|
||||
use App\Repository\QuestionnaireResponseRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* The office's list of submitted questionnaires, run against db_test inside a rolled-back
|
||||
* transaction. A draft is still the teamer's and must never show up there.
|
||||
*/
|
||||
class QuestionnaireResponseRepositoryTest extends KernelTestCase
|
||||
{
|
||||
use QuestionnaireFixturesTrait;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private QuestionnaireResponseRepository $repository;
|
||||
|
||||
private Teamer $teamer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
|
||||
$this->repository = $this->entityManager->getRepository(QuestionnaireResponse::class);
|
||||
$this->entityManager->getConnection()->beginTransaction();
|
||||
|
||||
$this->teamer = (new Teamer())->setFirstName('Kim')->setLastName('Muster')->setGender('d');
|
||||
$this->entityManager->persist($this->teamer);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->entityManager->getConnection()->rollBack();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testOnlySubmittedResponsesToThisQuestionnaireAreListed(): void
|
||||
{
|
||||
$submitted = $this->respond($this->escort(), submit: true);
|
||||
$this->respond($this->escort(), submit: false);
|
||||
$this->respond($this->escort(), submit: true, questionnaire: 'other');
|
||||
|
||||
$this->assertSame([$submitted], $this->list(new QuestionnaireResponseFilterDto()));
|
||||
}
|
||||
|
||||
public function testFilterByTeamer(): void
|
||||
{
|
||||
$other = (new Teamer())->setFirstName('Alex')->setLastName('Beispiel')->setGender('d');
|
||||
$this->entityManager->persist($other);
|
||||
$this->respond($this->escort(teamer: $other), submit: true);
|
||||
$mine = $this->respond($this->escort(), submit: true);
|
||||
|
||||
$this->assertSame([$mine], $this->list((new QuestionnaireResponseFilterDto())->setTeamer($this->teamer)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Matched as a substring, and a % typed into the filter is a literal, not a wildcard.
|
||||
*/
|
||||
public function testFilterByHotel(): void
|
||||
{
|
||||
$ranalt = $this->respond($this->escort(hotel: 'Gasthof Ranalt'), submit: true);
|
||||
$this->respond($this->escort(hotel: 'Schwendi'), submit: true);
|
||||
|
||||
$this->assertSame([$ranalt], $this->list((new QuestionnaireResponseFilterDto())->setHotel('ranalt')));
|
||||
$this->assertSame([], $this->list((new QuestionnaireResponseFilterDto())->setHotel('%')));
|
||||
}
|
||||
|
||||
public function testFilterByEndOfAssignment(): void
|
||||
{
|
||||
$recent = $this->respond($this->escort(dateTo: '2026-03-14'), submit: true);
|
||||
$this->respond($this->escort(dateTo: '2026-01-10'), submit: true);
|
||||
|
||||
$filter = (new QuestionnaireResponseFilterDto())
|
||||
->setDateFrom(new \DateTimeImmutable('2026-03-01'))
|
||||
->setDateTo(new \DateTimeImmutable('2026-03-14'))
|
||||
;
|
||||
|
||||
$this->assertSame([$recent], $this->list($filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<QuestionnaireResponse>
|
||||
*/
|
||||
private function list(QuestionnaireResponseFilterDto $filter): array
|
||||
{
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->repository->getListQuery(QuestionnaireCatalog::TEAMER_ESCORT, $filter)->getResult();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user