2023-12-26 20:06:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Form;
|
|
|
|
|
2023-12-27 22:45:08 +01:00
|
|
|
use App\Form\Models\Formtemplate;
|
|
|
|
use App\Lib\Events\Succeeded;
|
2023-12-26 20:06:57 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2023-12-27 22:45:08 +01:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2023-12-26 20:06:57 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class FormtemplateUpdateActionTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2023-12-27 22:45:08 +01:00
|
|
|
public function testItUpdatesTemplates(): void
|
2023-12-26 20:06:57 +01:00
|
|
|
{
|
2023-12-27 22:45:08 +01:00
|
|
|
Event::fake([Succeeded::class]);
|
2023-12-26 20:06:57 +01:00
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
2023-12-27 22:45:08 +01:00
|
|
|
$formtemplate = Formtemplate::factory()->create();
|
|
|
|
FormtemplateRequest::new()->name('testname')->fake();
|
2023-12-26 20:06:57 +01:00
|
|
|
|
2023-12-27 22:45:08 +01:00
|
|
|
$this->patchJson(route('formtemplate.update', ['formtemplate' => $formtemplate]))
|
|
|
|
->assertOk();
|
2023-12-26 20:06:57 +01:00
|
|
|
|
|
|
|
$this->assertDatabaseHas('formtemplates', [
|
|
|
|
'name' => 'Testname',
|
|
|
|
]);
|
2023-12-27 22:45:08 +01:00
|
|
|
Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage aktualisiert.');
|
2023-12-26 20:06:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNameIsRequired(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami();
|
|
|
|
|
|
|
|
$this->postJson(route('formtemplate.store'), [
|
|
|
|
'name' => '',
|
|
|
|
'config' => [
|
|
|
|
'sections' => []
|
|
|
|
]
|
|
|
|
])->assertJsonValidationErrors(['name' => 'Name ist erforderlich']);
|
|
|
|
}
|
|
|
|
}
|