Add FormtemplateUpdateActionTest

This commit is contained in:
philipp lang 2023-12-27 22:45:08 +01:00
parent f55c174019
commit 5b2a290b49
2 changed files with 13 additions and 10 deletions

View File

@ -3,6 +3,7 @@
namespace App\Form\Actions;
use App\Form\Models\Formtemplate;
use App\Lib\Events\Succeeded;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
@ -35,6 +36,8 @@ class FormtemplateUpdateAction
{
$this->handle($formtemplate, $request->validated());
Succeeded::message('Vorlage aktualisiert.')->dispatch();
return response()->json([]);
}
}

View File

@ -2,7 +2,10 @@
namespace Tests\Feature\Form;
use App\Form\Models\Formtemplate;
use App\Lib\Events\Succeeded;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class FormtemplateUpdateActionTest extends TestCase
@ -10,23 +13,20 @@ class FormtemplateUpdateActionTest extends TestCase
use DatabaseTransactions;
public function testItStoresTemplates(): void
public function testItUpdatesTemplates(): void
{
Event::fake([Succeeded::class]);
$this->login()->loginNami()->withoutExceptionHandling();
$formtemplate = Formtemplate::factory()->create();
FormtemplateRequest::new()->name('testname')->fake();
$this->postJson(route('formtemplate.store'), [
'name' => 'Testname',
'config' => [
'sections' => [
['name' => 'Persönliches', 'fields' => []]
]
]
])->assertOk();
$this->patchJson(route('formtemplate.update', ['formtemplate' => $formtemplate]))
->assertOk();
$this->assertDatabaseHas('formtemplates', [
'name' => 'Testname',
'config' => json_encode(['sections' => [['name' => 'Persönliches', 'fields' => []]]]),
]);
Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage aktualisiert.');
}
public function testNameIsRequired(): void