2023-12-26 20:06:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Form;
|
|
|
|
|
2024-07-14 20:20:56 +02:00
|
|
|
use App\Form\Models\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;
|
2024-07-14 20:20:56 +02:00
|
|
|
use Tests\RequestFactories\EditorRequestFactory;
|
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
|
|
|
}
|
|
|
|
|
2024-07-14 20:20:56 +02:00
|
|
|
public function testItUpdatesTexts(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$formtemplate = Formtemplate::factory()->create();
|
|
|
|
$payload = FormtemplateRequest::new()
|
|
|
|
->mailTop(EditorRequestFactory::new()->text(10, 'lala'))
|
|
|
|
->mailBottom(EditorRequestFactory::new()->text(10, 'lalb'))
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$this->patchJson(route('formtemplate.update', ['formtemplate' => $formtemplate]), $payload)
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
$this->assertEquals('lala', Formtemplate::first()->mail_top->blocks[0]['data']['text']);
|
|
|
|
$this->assertEquals('lalb', Formtemplate::first()->mail_bottom->blocks[0]['data']['text']);
|
|
|
|
}
|
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
}
|