feat: accept form submissions from the websites over an API endpoint
This commit is contained in:
1 parent
f48e53fdd0
commit
30ad5e8488
17 files changed
+1350
-4
No files matched your search
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\ApplicationFormSubmissionDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* The normalization the json column relies on: no empty answers, numbers as strings, booleans
|
||||
* kept, and a multi-select as a flat list of what was picked.
|
||||
*/
|
||||
class ApplicationFormSubmissionDtoTest extends TestCase
|
||||
{
|
||||
public function testEmptyAnswersAreDropped(): void
|
||||
{
|
||||
$dto = $this->dto(['Nationalität' => 'deutsch', 'Führerschein' => '', 'Sprachen' => [], 'Sport' => null]);
|
||||
|
||||
$this->assertSame(['Nationalität' => 'deutsch'], $dto->getNormalizedDetails());
|
||||
}
|
||||
|
||||
public function testNumbersBecomeStringsAndBooleansStay(): void
|
||||
{
|
||||
$dto = $this->dto(['Skifahrer seit' => 2004, 'Datenschutz' => true]);
|
||||
|
||||
$this->assertSame(['Skifahrer seit' => '2004', 'Datenschutz' => true], $dto->getNormalizedDetails());
|
||||
}
|
||||
|
||||
public function testAMultiSelectStaysAFlatListOfLabels(): void
|
||||
{
|
||||
$dto = $this->dto(['Ich fahre' => ['Ski', 'Snowboard']]);
|
||||
|
||||
$this->assertSame(['Ich fahre' => ['Ski', 'Snowboard']], $dto->getNormalizedDetails());
|
||||
}
|
||||
|
||||
public function testARelativeSubmissionTimeIsNotADate(): void
|
||||
{
|
||||
$this->assertNull((new ApplicationFormSubmissionDto(submittedAt: 'now'))->getSubmittedAt());
|
||||
$this->assertNull((new ApplicationFormSubmissionDto(submittedAt: '2026-09-22'))->getSubmittedAt());
|
||||
$this->assertNotNull((new ApplicationFormSubmissionDto(submittedAt: '2026-09-22T12:30:00+02:00'))->getSubmittedAt());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $details
|
||||
*/
|
||||
private function dto(array $details): ApplicationFormSubmissionDto
|
||||
{
|
||||
return new ApplicationFormSubmissionDto(
|
||||
form: 'applicationform',
|
||||
formLabel: 'Bewerbungsformular',
|
||||
submittedAt: '2026-09-22T12:30:00+02:00',
|
||||
details: $details,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user