Fix participant update
This commit is contained in:
parent
5d48521875
commit
d9c45f5236
|
@ -17,15 +17,38 @@ class ParticipantUpdateAction
|
|||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'data' => 'required',
|
||||
];
|
||||
/** @var Participant */
|
||||
$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
|
||||
{
|
||||
$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();
|
||||
return response()->json([]);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use App\Form\Enums\SpecialType;
|
|||
/**
|
||||
* @method self name(string $name)
|
||||
* @method self key(string $key)
|
||||
* @method self required(string|bool $key)
|
||||
* @method self required(bool $isRequired)
|
||||
* @method self rows(int $rows)
|
||||
* @method self columns(array{mobile: int, tablet: int, desktop: int} $rows)
|
||||
* @method self default(mixed $default)
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Form\Actions\ExportSyncAction;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
|
||||
class ParticipantUpdateActionTest extends FormTestCase
|
||||
{
|
||||
|
@ -13,19 +15,31 @@ class ParticipantUpdateActionTest extends FormTestCase
|
|||
|
||||
public function testItUpdatesParticipant(): void
|
||||
{
|
||||
Queue::fake();
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$participant = Participant::factory()->data(['vorname' => 'Max', 'select' => ['A', 'B']])
|
||||
->for(Form::factory()->sections([
|
||||
FormtemplateSectionRequest::new()->name('Sektion')->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
$this->checkboxesField('select')->options(['A', 'B', 'C']),
|
||||
])
|
||||
$participant = Participant::factory()->data(['vorname' => 'Max'])
|
||||
->for(Form::factory()->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
]))
|
||||
->create();
|
||||
|
||||
$this->patchJson(route('participant.update', ['participant' => $participant->id]), ['data' => ['vorname' => 'Jane']])
|
||||
$this->patchJson(route('participant.update', ['participant' => $participant->id]), ['vorname' => 'Jane'])
|
||||
->assertOk();
|
||||
|
||||
$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