feat: list and show submitted questionnaires to the office

This commit is contained in:
fromme committed 2026-10-27 17:02:51 +01:00
1 parent 890e04f8a6
commit a35f91ac63
15 files changed
+715 -46

No files matched your search

@@ -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();
}
}