adrema/tests/Feature/Contribution/StoreTest.php

204 lines
7.0 KiB
PHP
Raw Normal View History

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-09-07 12:04:13 +02:00
use App\Contribution\Documents\RdpNrwDocument;
use App\Contribution\Documents\CitySolingenDocument;
2024-12-13 19:03:40 +01:00
use App\Contribution\Documents\WuppertalDocument;
2022-11-07 16:18:11 +01:00
use App\Country;
2023-05-17 00:22:43 +02:00
use App\Gender;
2024-10-14 21:21:19 +02:00
use Modules\Invoice\InvoiceSettings;
2022-11-07 16:18:11 +01:00
use App\Member\Member;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2023-05-17 00:22:43 +02:00
use Laravel\Passport\Client;
use Laravel\Passport\Passport;
use Tests\RequestFactories\ContributionMemberApiRequestFactory;
use Tests\RequestFactories\ContributionRequestFactory;
2022-11-07 16:18:11 +01:00
use Zoomyboy\Tex\Tex;
2024-12-13 00:58:44 +01:00
uses(DatabaseTransactions::class);
dataset('validation', function () {
return [
[
['type' => 'aaa'],
2023-09-07 12:04:13 +02:00
CitySolingenDocument::class,
'type',
2024-12-13 00:58:44 +01:00
],
[
['type' => ''],
2023-09-07 12:04:13 +02:00
CitySolingenDocument::class,
'type',
2024-12-13 00:58:44 +01:00
],
[
['dateFrom' => ''],
2023-09-07 12:04:13 +02:00
CitySolingenDocument::class,
'dateFrom',
2024-12-13 00:58:44 +01:00
],
[
['dateFrom' => '2022-01'],
2023-09-07 12:04:13 +02:00
CitySolingenDocument::class,
'dateFrom',
2024-12-13 00:58:44 +01:00
],
[
['dateUntil' => ''],
2023-09-07 12:04:13 +02:00
CitySolingenDocument::class,
'dateUntil',
2024-12-13 00:58:44 +01:00
],
[
['dateUntil' => '2022-01'],
2023-09-07 12:04:13 +02:00
CitySolingenDocument::class,
'dateUntil',
2024-12-13 00:58:44 +01:00
],
[
['country' => -1],
2023-09-07 12:04:13 +02:00
RdpNrwDocument::class,
'country',
2024-12-13 00:58:44 +01:00
],
[
['country' => 'AAAA'],
2023-09-07 12:04:13 +02:00
RdpNrwDocument::class,
'country',
2024-12-13 00:58:44 +01:00
],
[
['members' => 'A'],
2023-09-07 12:04:13 +02:00
RdpNrwDocument::class,
'members',
2024-12-13 00:58:44 +01:00
],
[
['members' => [99999]],
2023-09-07 12:04:13 +02:00
RdpNrwDocument::class,
'members.0',
2024-12-13 00:58:44 +01:00
],
[
['members' => ['lalala']],
2023-09-07 12:04:13 +02:00
RdpNrwDocument::class,
'members.0',
2024-12-13 00:58:44 +01:00
],
[
['eventName' => ''],
2023-09-07 12:04:13 +02:00
CitySolingenDocument::class,
'eventName',
2024-12-13 00:58:44 +01:00
],
[
['zipLocation' => ''],
2023-09-07 12:04:13 +02:00
CitySolingenDocument::class,
'zipLocation',
2024-12-13 00:58:44 +01:00
],
2024-12-13 01:59:09 +01:00
[
['zipLocation' => ''],
2024-12-13 19:03:40 +01:00
WuppertalDocument::class,
2024-12-13 01:59:09 +01:00
'zipLocation',
],
[
['dateFrom' => ''],
2024-12-13 19:03:40 +01:00
WuppertalDocument::class,
2024-12-13 01:59:09 +01:00
'dateFrom',
],
[
['dateUntil' => ''],
2024-12-13 19:03:40 +01:00
WuppertalDocument::class,
2024-12-13 01:59:09 +01:00
'dateUntil',
],
2024-12-13 00:58:44 +01:00
];
});
it('compiles documents via api', function (string $type, array $bodyChecks) {
$this->withoutExceptionHandling();
Tex::spy();
$this->login()->loginNami();
2024-12-13 02:16:09 +01:00
$member1 = Member::factory()->defaults()->male()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Max', 'lastname' => 'Muster']);
$member2 = Member::factory()->defaults()->female()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']);
2024-12-13 00:58:44 +01:00
$response = $this->call('GET', '/contribution-generate', [
'payload' => ContributionRequestFactory::new()->type($type)->state([
'dateFrom' => '1991-06-15',
'dateUntil' => '1991-06-16',
'eventName' => 'Super tolles Lager',
'members' => [$member1->id, $member2->id],
'type' => $type,
'zipLocation' => '42777 SG',
])->toBase64(),
]);
$response->assertSessionDoesntHaveErrors();
$response->assertOk();
Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
})->with([
["App\\Contribution\\Documents\\CitySolingenDocument", ["Super tolles Lager", "Max Muster", "Jane Muster", "15.06.1991"]],
["App\\Contribution\\Documents\\RdpNrwDocument", ["Muster, Max", "Muster, Jane", "15.06.1991", "42777 SG"]],
["App\\Contribution\\Documents\\CityRemscheidDocument", ["Max", "Muster", "Jane"]],
["App\\Contribution\\Documents\\CityFrankfurtMainDocument", ["Max", "Muster", "Jane"]],
["App\\Contribution\\Documents\\BdkjHesse", ["Max", "Muster", "Jane"]],
2024-12-13 19:03:40 +01:00
["App\\Contribution\\Documents\\WuppertalDocument", ["Max", "Muster", "Jane", "42777 SG", "15.06.1991", "16.06.1991"]],
2024-12-13 00:58:44 +01:00
]);
it('testItCompilesGroupNameInSolingenDocument', function () {
$this->withoutExceptionHandling()->login()->loginNami();
Tex::spy();
InvoiceSettings::fake(['from_long' => 'Stamm BiPi']);
$this->call('GET', '/contribution-generate', [
'payload' => ContributionRequestFactory::new()->type(CitySolingenDocument::class)->toBase64(),
]);
Tex::assertCompiled(CitySolingenDocument::class, fn ($document) => $document->hasAllContent(['Stamm BiPi']));
});
it('testItCompilesContributionDocumentsViaApi', function () {
$this->withoutExceptionHandling();
Tex::spy();
Gender::factory()->female()->create();
Gender::factory()->male()->create();
Passport::actingAsClient(Client::factory()->create(), ['contribution-generate']);
$country = Country::factory()->create();
Member::factory()->defaults()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Max', 'lastname' => 'Muster']);
Member::factory()->defaults()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']);
$response = $this->postJson('/api/contribution-generate', [
'country' => $country->id,
'dateFrom' => '1991-06-15',
'dateUntil' => '1991-06-16',
'eventName' => 'Super tolles Lager',
'type' => CitySolingenDocument::class,
'zipLocation' => '42777 SG',
'member_data' => [
ContributionMemberApiRequestFactory::new()->create(),
ContributionMemberApiRequestFactory::new()->create(),
],
]);
$response->assertSessionDoesntHaveErrors();
$response->assertOk();
Tex::assertCompiled(CitySolingenDocument::class, fn ($document) => $document->hasAllContent(['Super']));
});
it('testInputShouldBeBase64EncodedJson', function (string $payload) {
$this->login()->loginNami();
$this->call('GET', '/contribution-generate', ['payload' => $payload])->assertSessionHasErrors('payload');
})->with([
[""],
["aaaa"],
["YWFhCg=="],
]);
it('testItValidatesInput', function (array $input, string $documentClass, string $errorField) {
$this->login()->loginNami();
Country::factory()->create();
Member::factory()->defaults()->create();
$this->postJson('/contribution-validate', ContributionRequestFactory::new()->type($documentClass)->state($input)->create())
->assertJsonValidationErrors($errorField);
})->with('validation');
it('testItValidatesInputBeforeGeneration', function (array $input, string $documentClass, string $errorField) {
$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);
})->with('validation');