Fix tests
This commit is contained in:
parent
10b71f7a36
commit
c8e268d91b
|
@ -64,6 +64,9 @@ class FormCompileRequest extends Data implements HasContributionData {
|
||||||
$member = [];
|
$member = [];
|
||||||
foreach ($fields as [$type, $name]) {
|
foreach ($fields as [$type, $name]) {
|
||||||
$f = $this->form->getFields()->findBySpecialType($type);
|
$f = $this->form->getFields()->findBySpecialType($type);
|
||||||
|
if (!$f) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$member[$name] = $participant->getFields()->find($f)->value;
|
$member[$name] = $participant->getFields()->find($f)->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,7 @@ it('doesnt create document when no special fields given', function (array $field
|
||||||
->has(Participant::factory())
|
->has(Participant::factory())
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
generate($type, $form, true)->assertJsonValidationErrors([$field => $message]);
|
||||||
'type' => $type,
|
|
||||||
'form' => $form,
|
|
||||||
'validate' => '1',
|
|
||||||
]))->assertJsonValidationErrors([$field => $message]);
|
|
||||||
})
|
})
|
||||||
->with([
|
->with([
|
||||||
[fn() => [], 'FIRSTNAME', 'Kein Feld für Vorname vorhanden.'],
|
[fn() => [], 'FIRSTNAME', 'Kein Feld für Vorname vorhanden.'],
|
||||||
|
@ -61,11 +57,7 @@ it('validates special types of each document', function (string $type, array $fi
|
||||||
->has(Participant::factory())
|
->has(Participant::factory())
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
generate($type, $form, true)->assertJsonValidationErrors([$field => $message]);
|
||||||
'type' => $type,
|
|
||||||
'form' => $form,
|
|
||||||
'validate' => '1',
|
|
||||||
]))->assertJsonValidationErrors([$field => $message]);
|
|
||||||
})
|
})
|
||||||
->with([
|
->with([
|
||||||
[CitySolingenDocument::class, [], 'ADDRESS', 'Kein Feld für Adresse vorhanden.'],
|
[CitySolingenDocument::class, [], 'ADDRESS', 'Kein Feld für Adresse vorhanden.'],
|
||||||
|
@ -79,10 +71,7 @@ it('throws error when not validating but fields are not present', function () {
|
||||||
->has(Participant::factory())
|
->has(Participant::factory())
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
generate(CitySolingenDocument::class, $form, false)->assertStatus(422);
|
||||||
'type' => CitySolingenDocument::class,
|
|
||||||
'form' => $form,
|
|
||||||
]))->assertStatus(422);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('throws error when form doesnt have meta', function () {
|
it('throws error when form doesnt have meta', function () {
|
||||||
|
@ -94,10 +83,7 @@ it('throws error when form doesnt have meta', function () {
|
||||||
->location('')
|
->location('')
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
generate(CitySolingenDocument::class, $form, false)->assertStatus(422)->assertJsonValidationErrors([
|
||||||
'type' => CitySolingenDocument::class,
|
|
||||||
'form' => $form,
|
|
||||||
]))->assertStatus(422)->assertJsonValidationErrors([
|
|
||||||
'zip' => 'PLZ ist erforderlich.',
|
'zip' => 'PLZ ist erforderlich.',
|
||||||
'location' => 'Ort ist erforderlich.'
|
'location' => 'Ort ist erforderlich.'
|
||||||
]);
|
]);
|
||||||
|
@ -108,11 +94,7 @@ it('throws error when form doesnt have participants', function () {
|
||||||
|
|
||||||
$form = Form::factory()->fields([])->create();
|
$form = Form::factory()->fields([])->create();
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
generate(CitySolingenDocument::class, $form, true)->assertJsonValidationErrors(['participants' => 'Veranstaltung besitzt noch keine Teilnehmer*innen.']);
|
||||||
'type' => CitySolingenDocument::class,
|
|
||||||
'form' => $form,
|
|
||||||
'validate' => '1',
|
|
||||||
]))->assertJsonValidationErrors(['participants' => 'Veranstaltung besitzt noch keine Teilnehmer*innen.']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates document when fields are present', function () {
|
it('creates document when fields are present', function () {
|
||||||
|
@ -130,10 +112,7 @@ it('creates document when fields are present', function () {
|
||||||
->has(Participant::factory()->data(['fn' => 'Baum', 'ln' => 'Muster', 'bd' => '1991-05-06', 'zip' => '33333', 'loc' => 'Musterstadt', 'add' => 'Laastr 4']))
|
->has(Participant::factory()->data(['fn' => 'Baum', 'ln' => 'Muster', 'bd' => '1991-05-06', 'zip' => '33333', 'loc' => 'Musterstadt', 'add' => 'Laastr 4']))
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
generate(CitySolingenDocument::class, $form, false)->assertOk();
|
||||||
'type' => CitySolingenDocument::class,
|
|
||||||
'form' => $form,
|
|
||||||
]))->assertOk();
|
|
||||||
Tex::assertCompiled(CitySolingenDocument::class, fn($document) => $document->hasAllContent(['Baum', 'Muster', '1991', 'Musterstadt', 'Laastr 4', '33333']));
|
Tex::assertCompiled(CitySolingenDocument::class, fn($document) => $document->hasAllContent(['Baum', 'Muster', '1991', 'Musterstadt', 'Laastr 4', '33333']));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -159,9 +138,14 @@ it('creates document with form meta', function () {
|
||||||
->location('Frankfurt')
|
->location('Frankfurt')
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->json('GET', route('form.contribution', [
|
generate(RdpNrwDocument::class, $form, false)->assertOk();
|
||||||
'type' => RdpNrwDocument::class,
|
|
||||||
'form' => $form,
|
|
||||||
]))->assertOk();
|
|
||||||
Tex::assertCompiled(RdpNrwDocument::class, fn($document) => $document->hasAllContent(['20.06.2008', '22.06.2008', '12345 Frankfurt']));
|
Tex::assertCompiled(RdpNrwDocument::class, fn($document) => $document->hasAllContent(['20.06.2008', '22.06.2008', '12345 Frankfurt']));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function generate(string $document, Form $form, bool $validate) {
|
||||||
|
return test()->json('GET', route('form.contribution', [
|
||||||
|
'payload' => test()->filterString(['type' => $document]),
|
||||||
|
'form' => $form,
|
||||||
|
'validate' => $validate ? '1' : '0'
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue