2022-11-07 16:18:11 +01:00
|
|
|
<?php
|
|
|
|
|
2022-11-17 21:47:45 +01:00
|
|
|
namespace Tests\Feature\Contribution;
|
2022-11-07 16:18:11 +01:00
|
|
|
|
2023-03-14 22:29:39 +01:00
|
|
|
use App\Contribution\Documents\ContributionDocument;
|
|
|
|
use App\Contribution\Documents\DvDocument;
|
2023-03-09 02:14:24 +01:00
|
|
|
use App\Contribution\Documents\SolingenDocument;
|
2022-11-07 16:18:11 +01:00
|
|
|
use App\Country;
|
|
|
|
use App\Member\Member;
|
2023-03-14 22:29:39 +01:00
|
|
|
use Generator;
|
2022-11-07 16:18:11 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2023-03-14 22:29:39 +01:00
|
|
|
use Tests\RequestFactories\ContributionRequestFactory;
|
2022-11-07 16:18:11 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
use Zoomyboy\Tex\Tex;
|
|
|
|
|
2022-11-17 21:47:45 +01:00
|
|
|
class StoreTest extends TestCase
|
2022-11-07 16:18:11 +01:00
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
/**
|
2022-11-17 21:47:45 +01:00
|
|
|
* @testWith ["App\\Contribution\\Documents\\SolingenDocument", ["Super tolles Lager", "Max Muster", "Jane Muster", "15.06.1991"]]
|
|
|
|
* ["App\\Contribution\\Documents\\DvDocument", ["Muster, Max", "Muster, Jane", "15.06.1991", "42777 SG"]]
|
2022-11-17 23:01:46 +01:00
|
|
|
* ["App\\Contribution\\Documents\\RemscheidDocument", ["Max", "Muster", "Jane"]]
|
2022-11-07 16:18:11 +01:00
|
|
|
*
|
|
|
|
* @param array<int, string> $bodyChecks
|
|
|
|
*/
|
|
|
|
public function testItCompilesContributionDocuments(string $type, array $bodyChecks): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
Tex::spy();
|
|
|
|
$this->login()->loginNami();
|
|
|
|
$country = Country::factory()->create();
|
2022-11-17 22:59:16 +01:00
|
|
|
$member1 = Member::factory()->defaults()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Max', 'lastname' => 'Muster']);
|
|
|
|
$member2 = Member::factory()->defaults()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']);
|
2022-11-07 16:18:11 +01:00
|
|
|
|
2023-03-14 22:29:39 +01:00
|
|
|
$response = $this->call('GET', '/contribution-generate', [
|
2023-03-09 02:14:24 +01:00
|
|
|
'payload' => base64_encode(json_encode([
|
|
|
|
'country' => $country->id,
|
|
|
|
'dateFrom' => '1991-06-15',
|
|
|
|
'dateUntil' => '1991-06-16',
|
|
|
|
'eventName' => 'Super tolles Lager',
|
|
|
|
'members' => [$member1->id, $member2->id],
|
|
|
|
'type' => $type,
|
|
|
|
'zipLocation' => '42777 SG',
|
|
|
|
])),
|
2022-11-07 16:18:11 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertSessionDoesntHaveErrors();
|
|
|
|
$response->assertOk();
|
|
|
|
Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
|
|
|
|
}
|
2023-03-09 02:14:24 +01:00
|
|
|
|
2023-03-14 22:29:39 +01:00
|
|
|
/**
|
|
|
|
* @testWith [""]
|
|
|
|
* ["aaaa"]
|
|
|
|
* ["YWFhCg=="]
|
|
|
|
*/
|
|
|
|
public function testInputShouldBeBase64EncodedJson(string $payload): void
|
2023-03-09 02:14:24 +01:00
|
|
|
{
|
|
|
|
$this->login()->loginNami();
|
|
|
|
|
2023-03-14 22:29:39 +01:00
|
|
|
$this->call('GET', '/contribution-generate', ['payload' => $payload])->assertSessionHasErrors('payload');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string, string> $input
|
|
|
|
* @param class-string<ContributionDocument> $documentClass
|
|
|
|
* @dataProvider validationDataProvider
|
|
|
|
*/
|
|
|
|
public function testItValidatesInput(array $input, string $documentClass, string $errorField): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami();
|
|
|
|
Country::factory()->create();
|
|
|
|
Member::factory()->defaults()->create();
|
2023-03-09 02:14:24 +01:00
|
|
|
|
2023-03-14 22:29:39 +01:00
|
|
|
$this->postJson('/contribution-validate', ContributionRequestFactory::new()->type($documentClass)->state($input)->create())
|
|
|
|
->assertJsonValidationErrors($errorField);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string, string> $input
|
|
|
|
* @param class-string<ContributionDocument> $documentClass
|
|
|
|
* @dataProvider validationDataProvider
|
|
|
|
*/
|
|
|
|
public function testItValidatesInputBeforeGeneration(array $input, string $documentClass, string $errorField): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami();
|
|
|
|
Country::factory()->create();
|
|
|
|
Member::factory()->defaults()->create();
|
|
|
|
|
|
|
|
$this->call('GET', '/contribution-generate', [
|
|
|
|
'payload' => ContributionRequestFactory::new()->type($documentClass)->state($input)->toBase64(),
|
|
|
|
])->assertSessionHasErrors($errorField);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function validationDataProvider(): Generator
|
|
|
|
{
|
|
|
|
yield [
|
|
|
|
['type' => 'aaa'],
|
|
|
|
SolingenDocument::class,
|
|
|
|
'type',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['type' => ''],
|
|
|
|
SolingenDocument::class,
|
|
|
|
'type',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['dateFrom' => ''],
|
|
|
|
SolingenDocument::class,
|
|
|
|
'dateFrom',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['dateFrom' => '2022-01'],
|
|
|
|
SolingenDocument::class,
|
|
|
|
'dateFrom',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['dateUntil' => ''],
|
|
|
|
SolingenDocument::class,
|
|
|
|
'dateUntil',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['dateUntil' => '2022-01'],
|
|
|
|
SolingenDocument::class,
|
|
|
|
'dateUntil',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['country' => -1],
|
|
|
|
DvDocument::class,
|
|
|
|
'country',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['country' => 'AAAA'],
|
|
|
|
DvDocument::class,
|
|
|
|
'country',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['members' => 'A'],
|
|
|
|
DvDocument::class,
|
|
|
|
'members',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['members' => [99999]],
|
|
|
|
DvDocument::class,
|
|
|
|
'members.0',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['members' => ['lalala']],
|
|
|
|
DvDocument::class,
|
|
|
|
'members.0',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['eventName' => ''],
|
|
|
|
SolingenDocument::class,
|
|
|
|
'eventName',
|
|
|
|
];
|
|
|
|
yield [
|
|
|
|
['zipLocation' => ''],
|
|
|
|
SolingenDocument::class,
|
|
|
|
'zipLocation',
|
|
|
|
];
|
2023-03-09 02:14:24 +01:00
|
|
|
}
|
2022-11-07 16:18:11 +01:00
|
|
|
}
|