Add backend for zip and location form

This commit is contained in:
philipp lang 2025-07-05 04:19:14 +02:00
parent 6b7de1446f
commit f2090aa9d0
6 changed files with 57 additions and 3 deletions

View File

@ -36,6 +36,8 @@ class FormStoreAction
'needs_prevention' => 'present|boolean',
'prevention_text' => 'array',
'prevention_conditions' => 'array',
'zip' => 'present|nullable|string',
'location' => 'present|nullable|string',
];
}

View File

@ -3,7 +3,6 @@
namespace App\Form\Actions;
use App\Form\Models\Form;
use App\Lib\Editor\Condition;
use App\Lib\Events\Succeeded;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\Concerns\AsAction;
@ -36,6 +35,8 @@ class FormUpdateAction
'needs_prevention' => 'present|boolean',
'prevention_text' => 'array',
'prevention_conditions' => 'array',
'location' => 'present|nullable|string',
'zip' => 'present|nullable|string',
];
}

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('forms', function (Blueprint $table) {
$table->string('zip')->nullable()->after('name');
$table->string('location')->nullable()->after('name');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('forms', function (Blueprint $table) {
$table->dropColumn('zip');
$table->dropColumn('location');
});
}
};

View File

@ -53,6 +53,8 @@ class FormRequest extends RequestFactory
'export' => ExportData::from([])->toArray(),
'needs_prevention' => $this->faker->boolean(),
'prevention_text' => EditorRequestFactory::new()->create(),
'zip' => (string) $this->faker->numberBetween(10, 6666),
'location' => (string) $this->faker->city(),
'prevention_conditions' => Condition::defaults()->toArray(),
];
}

View File

@ -32,6 +32,8 @@ it('testItStoresForm', function () {
->mailTop(EditorRequestFactory::new()->text(11, 'lala'))
->mailBottom(EditorRequestFactory::new()->text(12, 'lalab'))
->headerImage('htzz.jpg')
->zip('12345')
->location('Solingen')
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([$this->textField()->namiType(NamiType::BIRTHDAY)->forMembers(false)->hint('hhh')])])
->fake();
@ -55,6 +57,8 @@ it('testItStoresForm', function () {
$this->assertFalse($form->config->sections->get(0)->fields->get(0)->forMembers);
$this->assertCount(1, $form->getMedia('headerImage'));
$this->assertEquals('formname.jpg', $form->getMedia('headerImage')->first()->file_name);
$this->assertEquals('Solingen', $form->location);
$this->assertEquals('12345', $form->zip);
Event::assertDispatched(Succeeded::class, fn(Succeeded $event) => $event->message === 'Veranstaltung gespeichert.');
$this->assertFrontendCacheCleared();
});
@ -71,14 +75,16 @@ it('testItStoresDefaultSorting', function () {
$this->assertFalse(false, $form->meta['sorting']['direction']);
});
it('testRegistrationDatesCanBeNull', function () {
it('testValuesCanBeNull', function () {
$this->login()->loginNami()->withoutExceptionHandling();
$this->postJson(route('form.store'), FormRequest::new()->registrationFrom(null)->registrationUntil(null)->create())->assertOk();
$this->postJson(route('form.store'), FormRequest::new()->registrationFrom(null)->registrationUntil(null)->location(null)->zip(null)->create())->assertOk();
$this->assertDatabaseHas('forms', [
'registration_until' => null,
'registration_from' => null,
'zip' => null,
'location' => null,
]);
});

View File

@ -118,6 +118,19 @@ it('testItUpdatesActiveState', function () {
$this->assertTrue($form->fresh()->is_active);
});
it('updates zip and location', function () {
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$request = FormRequest::new()->zip('12345')->location('Musterstadt')->create();
$this->patchJson(route('form.update', ['form' => $form]), $request)->assertOk();
test()->assertDatabaseHas('forms', [
'id' => $form->id,
'zip' => '12345',
'location' => 'Musterstadt',
]);
});
it('testItUpdatesPrivateState', function () {
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();