Fix participant update
This commit is contained in:
parent
5d48521875
commit
d9c45f5236
|
@ -17,15 +17,38 @@ class ParticipantUpdateAction
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
/** @var Participant */
|
||||||
'data' => 'required',
|
$participant = request()->route('participant');
|
||||||
];
|
|
||||||
|
return $participant->form->getRegistrationRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function getValidationAttributes(): array
|
||||||
|
{
|
||||||
|
/** @var Participant */
|
||||||
|
$participant = request()->route('participant');
|
||||||
|
|
||||||
|
return $participant->form->getRegistrationAttributes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function getValidationMessages(): array
|
||||||
|
{
|
||||||
|
/** @var Participant */
|
||||||
|
$participant = request()->route('participant');
|
||||||
|
|
||||||
|
return $participant->form->getRegistrationMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Participant $participant, ActionRequest $request): JsonResponse
|
public function handle(Participant $participant, ActionRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$participant->update(['data' => [...$participant->data, ...$request->validated('data')]]);
|
$participant->update(['data' => [...$participant->data, ...$request->validated()]]);
|
||||||
|
ExportSyncAction::dispatch($participant->form->id);
|
||||||
Succeeded::message('Teilnehmer*in bearbeitet.')->dispatch();
|
Succeeded::message('Teilnehmer*in bearbeitet.')->dispatch();
|
||||||
return response()->json([]);
|
return response()->json([]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use App\Form\Enums\SpecialType;
|
||||||
/**
|
/**
|
||||||
* @method self name(string $name)
|
* @method self name(string $name)
|
||||||
* @method self key(string $key)
|
* @method self key(string $key)
|
||||||
* @method self required(string|bool $key)
|
* @method self required(bool $isRequired)
|
||||||
* @method self rows(int $rows)
|
* @method self rows(int $rows)
|
||||||
* @method self columns(array{mobile: int, tablet: int, desktop: int} $rows)
|
* @method self columns(array{mobile: int, tablet: int, desktop: int} $rows)
|
||||||
* @method self default(mixed $default)
|
* @method self default(mixed $default)
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Form;
|
namespace Tests\Feature\Form;
|
||||||
|
|
||||||
|
use App\Form\Actions\ExportSyncAction;
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Support\Facades\Queue;
|
||||||
|
|
||||||
class ParticipantUpdateActionTest extends FormTestCase
|
class ParticipantUpdateActionTest extends FormTestCase
|
||||||
{
|
{
|
||||||
|
@ -13,19 +15,31 @@ class ParticipantUpdateActionTest extends FormTestCase
|
||||||
|
|
||||||
public function testItUpdatesParticipant(): void
|
public function testItUpdatesParticipant(): void
|
||||||
{
|
{
|
||||||
|
Queue::fake();
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
$participant = Participant::factory()->data(['vorname' => 'Max', 'select' => ['A', 'B']])
|
$participant = Participant::factory()->data(['vorname' => 'Max'])
|
||||||
->for(Form::factory()->sections([
|
->for(Form::factory()->fields([
|
||||||
FormtemplateSectionRequest::new()->name('Sektion')->fields([
|
$this->textField('vorname')->name('Vorname'),
|
||||||
$this->textField('vorname')->name('Vorname'),
|
|
||||||
$this->checkboxesField('select')->options(['A', 'B', 'C']),
|
|
||||||
])
|
|
||||||
]))
|
]))
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->patchJson(route('participant.update', ['participant' => $participant->id]), ['data' => ['vorname' => 'Jane']])
|
$this->patchJson(route('participant.update', ['participant' => $participant->id]), ['vorname' => 'Jane'])
|
||||||
->assertOk();
|
->assertOk();
|
||||||
|
|
||||||
$this->assertEquals('Jane', $participant->fresh()->data['vorname']);
|
$this->assertEquals('Jane', $participant->fresh()->data['vorname']);
|
||||||
|
ExportSyncAction::assertPushed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItHasValidation(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami();
|
||||||
|
$participant = Participant::factory()->data(['vorname' => 'Max', 'select' => ['A', 'B']])
|
||||||
|
->for(Form::factory()->fields([
|
||||||
|
$this->textField('vorname')->name('Vorname')->required(true),
|
||||||
|
]))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->patchJson(route('participant.update', ['participant' => $participant->id]), ['vorname' => ''])
|
||||||
|
->assertJsonValidationErrors(['vorname' => 'Vorname ist erforderlich.']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue