Add setting for yearly prevention mail

This commit is contained in:
philipp lang 2025-05-27 19:33:35 +02:00
parent 010ad80793
commit a482e16739
4 changed files with 37 additions and 25 deletions

View File

@ -19,6 +19,7 @@ class SettingStoreAction
{ {
return [ return [
'formmail' => 'array', 'formmail' => 'array',
'yearlymail' => 'array',
]; ];
} }
@ -26,6 +27,7 @@ class SettingStoreAction
{ {
$settings = app(PreventionSettings::class); $settings = app(PreventionSettings::class);
$settings->formmail = EditorData::from($request->formmail); $settings->formmail = EditorData::from($request->formmail);
$settings->yearlymail = EditorData::from($request->yearlymail);
$settings->save(); $settings->save();
Succeeded::message('Einstellungen gespeichert.')->dispatch(); Succeeded::message('Einstellungen gespeichert.')->dispatch();

View File

@ -9,6 +9,7 @@ class PreventionSettings extends LocalSettings
{ {
public EditorData $formmail; public EditorData $formmail;
public EditorData $yearlymail;
public static function group(): string public static function group(): string
{ {

View File

@ -0,0 +1,11 @@
<?php
use Spatie\LaravelSettings\Migrations\SettingsMigration;
return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('prevention.yearlymail', ['time' => 1, 'blocks' => [], 'version' => '1.0']);
}
};

View File

@ -5,36 +5,34 @@ namespace Tests\Feature\Prevention;
use App\Prevention\PreventionSettings; use App\Prevention\PreventionSettings;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\RequestFactories\EditorRequestFactory; use Tests\RequestFactories\EditorRequestFactory;
use Tests\TestCase;
class SettingTest extends TestCase uses(DatabaseTransactions::class);
{
use DatabaseTransactions; it('testItOpensSettingsPage', function () {
test()->withoutExceptionHandling();
test()->login()->loginNami();
public function testItOpensSettingsPage(): void test()->get('/setting/prevention')->assertComponent('setting/Prevention')->assertOk();
{ });
$this->login()->loginNami();
$this->get('/setting/prevention')->assertComponent('setting/Prevention')->assertOk(); it('receives settings', function () {
} test()->login()->loginNami();
public function testItReceivesSettings(): void
{
$this->login()->loginNami();
$text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->toData(); $text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->toData();
app(PreventionSettings::class)->fill(['formmail' => $text])->save(); $yearlyMail = EditorRequestFactory::new()->text(50, 'lala dd')->toData();
app(PreventionSettings::class)->fill(['formmail' => $text, 'yearlymail' => $yearlyMail])->save();
$this->get('/api/prevention') test()->get('/api/prevention')
->assertJsonPath('data.formmail.blocks.0.data.text', 'lorem ipsum'); ->assertJsonPath('data.formmail.blocks.0.data.text', 'lorem ipsum')
} ->assertJsonPath('data.yearlymail.blocks.0.data.text', 'lala dd');
});
public function testItStoresSettings(): void it('testItStoresSettings', function () {
{ test()->login()->loginNami();
$this->login()->loginNami();
$this->post('/api/prevention', ['formmail' => EditorRequestFactory::new()->text(50, 'new lorem')->create()])->assertOk(); $formmail = EditorRequestFactory::new()->text(50, 'new lorem')->create();
$this->assertTrue(app(PreventionSettings::class)->formmail->hasAll(['new lorem'])); $yearlyMail = EditorRequestFactory::new()->text(50, 'lala dd')->create();
} test()->post('/api/prevention', ['formmail' => $formmail, 'yearlymail' => $yearlyMail])->assertOk();
} test()->assertTrue(app(PreventionSettings::class)->formmail->hasAll(['new lorem']));
test()->assertTrue(app(PreventionSettings::class)->yearlymail->hasAll(['lala dd']));
});