Add mail_top and mail_bottom for formtemplates
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
885eaa5df5
commit
46740b14a2
|
@ -28,8 +28,6 @@ class FormStoreAction
|
|||
'to' => 'required|date',
|
||||
'registration_from' => 'present|nullable|date',
|
||||
'registration_until' => 'present|nullable|date',
|
||||
'mail_top' => 'array',
|
||||
'mail_bottom' => 'array',
|
||||
'header_image' => 'required|exclude',
|
||||
'mailattachments' => 'present|array|exclude',
|
||||
'is_active' => 'boolean',
|
||||
|
|
|
@ -30,8 +30,6 @@ class FormUpdateAction
|
|||
'to' => 'required|date',
|
||||
'registration_from' => 'present|nullable|date',
|
||||
'registration_until' => 'present|nullable|date',
|
||||
'mail_top' => 'array',
|
||||
'mail_bottom' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'is_private' => 'boolean',
|
||||
'export' => 'nullable|array',
|
||||
|
|
|
@ -28,6 +28,8 @@ trait HasValidation
|
|||
'config.sections.*.fields.*.columns.mobile' => 'required|numeric|gt:0|lte:2',
|
||||
'config.sections.*.fields.*.columns.tablet' => 'required|numeric|gt:0|lte:4',
|
||||
'config.sections.*.fields.*.columns.desktop' => 'required|numeric|gt:0|lte:6',
|
||||
'mail_top' => 'array',
|
||||
'mail_bottom' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Form\Models;
|
||||
|
||||
use App\Form\Data\FormConfigData;
|
||||
use App\Lib\Editor\EditorData;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
@ -17,5 +18,7 @@ class Formtemplate extends Model
|
|||
|
||||
public $casts = [
|
||||
'config' => FormConfigData::class,
|
||||
'mail_top' => EditorData::class,
|
||||
'mail_bottom' => EditorData::class,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Form\Enums\SpecialType;
|
|||
use App\Form\Fields\Field;
|
||||
use App\Form\Models\Formtemplate;
|
||||
use App\Group;
|
||||
use App\Lib\Editor\EditorData;
|
||||
use App\Lib\HasMeta;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
|
@ -52,6 +53,8 @@ class FormtemplateResource extends JsonResource
|
|||
],
|
||||
'default' => [
|
||||
'name' => '',
|
||||
'mail_top' => EditorData::default(),
|
||||
'mail_bottom' => EditorData::default(),
|
||||
'config' => [
|
||||
'sections' => [],
|
||||
]
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Database\Factories\Form\Models;
|
|||
use App\Form\Models\Formtemplate;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Tests\Feature\Form\FormtemplateSectionRequest;
|
||||
use Tests\RequestFactories\EditorRequestFactory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Formtemplate>
|
||||
|
@ -24,6 +25,8 @@ class FormtemplateFactory extends Factory
|
|||
{
|
||||
return [
|
||||
'name' => $this->faker->words(4, true),
|
||||
'mail_top' => EditorRequestFactory::new()->toData(),
|
||||
'mail_bottom' => EditorRequestFactory::new()->toData(),
|
||||
'config' => [
|
||||
'sections' => [],
|
||||
],
|
||||
|
@ -45,4 +48,14 @@ class FormtemplateFactory extends Factory
|
|||
{
|
||||
return $this->state([str($method)->snake()->toString() => $parameters[0]]);
|
||||
}
|
||||
|
||||
public function mailTop(EditorRequestFactory $factory): self
|
||||
{
|
||||
return $this->state(['mail_top' => $factory->toData()]);
|
||||
}
|
||||
|
||||
public function mailBottom(EditorRequestFactory $factory): self
|
||||
{
|
||||
return $this->state(['mail_bottom' => $factory->toData()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('formtemplates', function (Blueprint $table) {
|
||||
$table->json('mail_top')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']));
|
||||
$table->json('mail_bottom')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('formtemplates', function (Blueprint $table) {
|
||||
$table->dropColumn('mail_top');
|
||||
$table->dropColumn('mail_bottom');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -83,6 +83,16 @@ class FormtemplateIndexActionTest extends TestCase
|
|||
])
|
||||
->assertInertiaPath('data.meta.default', [
|
||||
'name' => '',
|
||||
'mail_top' => [
|
||||
'version' => '1.0',
|
||||
'blocks' => [],
|
||||
'time' => 0,
|
||||
],
|
||||
'mail_bottom' => [
|
||||
'version' => '1.0',
|
||||
'blocks' => [],
|
||||
'time' => 0,
|
||||
],
|
||||
'config' => [
|
||||
'sections' => [],
|
||||
]
|
||||
|
|
|
@ -6,6 +6,8 @@ use Worksome\RequestFactories\RequestFactory;
|
|||
|
||||
/**
|
||||
* @method self name(string $name)
|
||||
* @method self mailTop(?EditorRequestFactory $content)
|
||||
* @method self mailBottom(?EditorRequestFactory $content)
|
||||
*/
|
||||
class FormtemplateRequest extends RequestFactory
|
||||
{
|
||||
|
@ -33,6 +35,6 @@ class FormtemplateRequest extends RequestFactory
|
|||
*/
|
||||
public function __call(string $method, $args): self
|
||||
{
|
||||
return $this->state([$method => $args[0]]);
|
||||
return $this->state([str($method)->snake()->toString() => $args[0]]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use App\Lib\Events\Succeeded;
|
|||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Generator;
|
||||
use Tests\RequestFactories\EditorRequestFactory;
|
||||
|
||||
class FormtemplateStoreActionTest extends FormTestCase
|
||||
{
|
||||
|
@ -20,14 +21,17 @@ class FormtemplateStoreActionTest extends FormTestCase
|
|||
{
|
||||
Event::fake([Succeeded::class]);
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
FormtemplateRequest::new()->name('testname')->sections([
|
||||
$payload = FormtemplateRequest::new()->name('testname')->sections([
|
||||
FormtemplateSectionRequest::new()->name('Persönliches')->fields([
|
||||
$this->textField('a')->name('lala1')->columns(['mobile' => 2, 'tablet' => 2, 'desktop' => 1])->required(false)->hint('hhh')->intro('intro'),
|
||||
$this->textareaField('b')->name('lala2')->required(false)->specialType(SpecialType::FIRSTNAME)->rows(10),
|
||||
]),
|
||||
])->fake();
|
||||
])
|
||||
->mailTop(EditorRequestFactory::new()->text(10, 'lala'))
|
||||
->mailBottom(EditorRequestFactory::new()->text(10, 'lblb'))
|
||||
->create();
|
||||
|
||||
$this->postJson(route('formtemplate.store'))->assertOk();
|
||||
$this->postJson(route('formtemplate.store'), $payload)->assertOk();
|
||||
|
||||
$formtemplate = Formtemplate::latest()->first();
|
||||
$this->assertEquals('Persönliches', $formtemplate->config->sections->get(0)->name);
|
||||
|
@ -41,6 +45,8 @@ class FormtemplateStoreActionTest extends FormTestCase
|
|||
$this->assertEquals(SpecialType::FIRSTNAME, $formtemplate->config->sections->get(0)->fields->get(1)->specialType);
|
||||
$this->assertEquals(['mobile' => 2, 'tablet' => 2, 'desktop' => 1], $formtemplate->config->sections->get(0)->fields->get(0)->columns->toArray());
|
||||
$this->assertEquals(10, $formtemplate->config->sections->get(0)->fields->get(1)->rows);
|
||||
$this->assertEquals('lala', $formtemplate->mail_top->blocks[0]['data']['text']);
|
||||
$this->assertEquals('lblb', $formtemplate->mail_bottom->blocks[0]['data']['text']);
|
||||
$this->assertFalse($formtemplate->config->sections->get(0)->fields->get(0)->required);
|
||||
Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage gespeichert.');
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Formtemplate;
|
||||
use App\Lib\Events\Succeeded;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Tests\RequestFactories\EditorRequestFactory;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FormtemplateUpdateActionTest extends TestCase
|
||||
|
@ -29,6 +31,22 @@ class FormtemplateUpdateActionTest extends TestCase
|
|||
Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage aktualisiert.');
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
public function testNameIsRequired(): void
|
||||
{
|
||||
$this->login()->loginNami();
|
||||
|
|
Loading…
Reference in New Issue