Add data type cast for Mailgateway
This commit is contained in:
parent
bf0e9cb962
commit
201b99cacf
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Mailgateway\Casts;
|
|
||||||
|
|
||||||
use App\Mailgateway\Types\Type;
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @implements CastsAttributes<Type, Type>
|
|
||||||
*/
|
|
||||||
class TypeCast implements CastsAttributes
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Cast the given value.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
|
||||||
* @param mixed $value
|
|
||||||
* @param array<string, mixed> $attributes
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function get($model, string $key, $value, array $attributes)
|
|
||||||
{
|
|
||||||
$value = json_decode($value, true);
|
|
||||||
|
|
||||||
return app($value['cls'])->setParams($value['params']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prepare the given value for storage.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
|
||||||
* @param mixed $value
|
|
||||||
* @param array<string, mixed> $attributes
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function set($model, string $key, $value, array $attributes)
|
|
||||||
{
|
|
||||||
return json_encode($value);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Mailgateway\Models;
|
namespace App\Mailgateway\Models;
|
||||||
|
|
||||||
use App\Mailgateway\Casts\TypeCast;
|
use App\Mailgateway\Types\Type;
|
||||||
use Database\Factories\Mailgateway\Models\MailgatewayFactory;
|
use Database\Factories\Mailgateway\Models\MailgatewayFactory;
|
||||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
@ -14,6 +14,6 @@ class Mailgateway extends Model
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use HasUuids;
|
use HasUuids;
|
||||||
|
|
||||||
public $casts = ['type' => TypeCast::class];
|
public $casts = ['type' => Type::class];
|
||||||
public $guarded = [];
|
public $guarded = [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ class MailgatewayResource extends JsonResource
|
||||||
'domain' => $this->domain,
|
'domain' => $this->domain,
|
||||||
'type_human' => $this->type::name(),
|
'type_human' => $this->type::name(),
|
||||||
'works' => $this->type->works(),
|
'works' => $this->type->works(),
|
||||||
'type' => $this->type->toResource(),
|
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'links' => [
|
'links' => [
|
||||||
'update' => route('mailgateway.update', ['mailgateway' => $this->getModel()]),
|
'update' => route('mailgateway.update', ['mailgateway' => $this->getModel()]),
|
||||||
|
|
|
@ -4,9 +4,15 @@ namespace App\Mailgateway\Types;
|
||||||
|
|
||||||
use App\Maildispatcher\Data\MailEntry;
|
use App\Maildispatcher\Data\MailEntry;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Livewire\Wireable;
|
||||||
|
use Spatie\LaravelData\Concerns\WireableData;
|
||||||
|
use Spatie\LaravelData\Data;
|
||||||
|
|
||||||
abstract class Type
|
abstract class Type extends Data implements Wireable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use WireableData;
|
||||||
|
|
||||||
abstract public static function name(): string;
|
abstract public static function name(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,17 +73,6 @@ abstract class Type
|
||||||
])->toArray();
|
])->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<string, array<string, mixed>>
|
|
||||||
*/
|
|
||||||
public function toResource(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'cls' => get_class($this),
|
|
||||||
'params' => get_object_vars($this),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection<int, MailEntry> $results
|
* @param Collection<int, MailEntry> $results
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Database\Factories\Mailgateway\Models;
|
namespace Database\Factories\Mailgateway\Models;
|
||||||
|
|
||||||
use App\Mailgateway\Models\Mailgateway;
|
use App\Mailgateway\Models\Mailgateway;
|
||||||
|
use App\Mailgateway\Types\LocalType;
|
||||||
use App\Mailgateway\Types\Type;
|
use App\Mailgateway\Types\Type;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
@ -22,24 +23,14 @@ class MailgatewayFactory extends Factory
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => $this->faker->words(5, true),
|
'name' => $this->faker->words(5, true),
|
||||||
'type' => [
|
'type' => new LocalType(),
|
||||||
'cls' => app('mail-gateways')->random(),
|
|
||||||
'params' => [],
|
|
||||||
],
|
|
||||||
'domain' => $this->faker->safeEmailDomain(),
|
'domain' => $this->faker->safeEmailDomain(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function type(Type $type): self
|
||||||
* @param class-string<Type> $type
|
|
||||||
* @param array<string, mixed> $params
|
|
||||||
*/
|
|
||||||
public function type(string $type, array $params): self
|
|
||||||
{
|
{
|
||||||
return $this->state(['type' => [
|
return $this->state(['type' => $type]);
|
||||||
'cls' => $type,
|
|
||||||
'params' => $params,
|
|
||||||
]]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function name(string $name): self
|
public function name(string $name): self
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
namespace Modules\Mailgateway\Components;
|
namespace Modules\Mailgateway\Components;
|
||||||
|
|
||||||
use App\Mailgateway\Models\Mailgateway;
|
use App\Mailgateway\Models\Mailgateway;
|
||||||
|
use App\Mailgateway\Types\Type;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Livewire\Attributes\On;
|
use Livewire\Attributes\On;
|
||||||
use Livewire\Attributes\Validate;
|
use Livewire\Attributes\Validate;
|
||||||
|
@ -15,9 +15,9 @@ class Form extends Component
|
||||||
|
|
||||||
public string $name = '';
|
public string $name = '';
|
||||||
public string $domain = '';
|
public string $domain = '';
|
||||||
public array $params = [];
|
public ?Type $type = null;
|
||||||
#[Validate('required')]
|
#[Validate('required|string')]
|
||||||
public ?string $cls = null;
|
public ?string $typeClass = null;
|
||||||
public Collection $types;
|
public Collection $types;
|
||||||
public ?Mailgateway $model = null;
|
public ?Mailgateway $model = null;
|
||||||
|
|
||||||
|
@ -26,19 +26,17 @@ class Form extends Component
|
||||||
return [
|
return [
|
||||||
'name' => 'required|string|max:255',
|
'name' => 'required|string|max:255',
|
||||||
'domain' => 'required|string|max:255',
|
'domain' => 'required|string|max:255',
|
||||||
'cls' => ['required', 'string', 'max:255', Rule::in(app('mail-gateways'))],
|
...$this->type ? collect($this->type::rules())->mapWithKeys(fn ($rules, $key) => ["type.{$key}" => $rules]) : [],
|
||||||
'params' => 'present|array',
|
|
||||||
...$this->cls ? collect($this->cls::rules())->mapWithKeys(fn ($rules, $key) => ["params.{$key}" => $rules]) : [],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validationAttributes(): array
|
public function validationAttributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'cls' => 'Typ',
|
'type' => 'Typ',
|
||||||
'name' => 'Beschreibung',
|
'name' => 'Beschreibung',
|
||||||
'domain' => 'Domain',
|
'domain' => 'Domain',
|
||||||
...$this->cls ? collect($this->cls::fieldNames())->mapWithKeys(fn ($attribute, $key) => ["params.{$key}" => $attribute]) : [],
|
...$this->type ? collect($this->type::fieldNames())->mapWithKeys(fn ($attribute, $key) => ["params.{$key}" => $attribute]) : [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,19 +51,23 @@ class Form extends Component
|
||||||
$this->model = Mailgateway::find($id);
|
$this->model = Mailgateway::find($id);
|
||||||
$this->name = $this->model->name;
|
$this->name = $this->model->name;
|
||||||
$this->domain = $this->model->domain;
|
$this->domain = $this->model->domain;
|
||||||
$this->cls = get_class($this->model->type);
|
$this->type = $this->model->type;
|
||||||
$this->params = (array) $this->model->type;
|
$this->typeClass = get_class($this->model->type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updatedType(string $type): void
|
|
||||||
{
|
|
||||||
$this->params = $type::defaults();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fields(): array
|
public function fields(): array
|
||||||
{
|
{
|
||||||
return $this->cls ? $this->cls::fields() : [];
|
return $this->type ? $this->type::fields() : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatedTypeClass(?string $type): void
|
||||||
|
{
|
||||||
|
if (!$type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->type = $type::from([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[On('onStoreFromModal')]
|
#[On('onStoreFromModal')]
|
||||||
|
@ -73,14 +75,14 @@ class Form extends Component
|
||||||
{
|
{
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
||||||
if (!app($this->cls)->setParams($this->params)->works()) {
|
if (!$this->type->works()) {
|
||||||
throw ValidationException::withMessages(['connection' => 'Verbindung fehlgeschlagen.']);
|
throw ValidationException::withMessages(['connection' => 'Verbindung fehlgeschlagen.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'domain' => $this->domain,
|
'domain' => $this->domain,
|
||||||
'type' => ['cls' => $this->cls, 'params' => $this->params],
|
'type' => $this->type,
|
||||||
];
|
];
|
||||||
if ($this->model) {
|
if ($this->model) {
|
||||||
$this->model->update($payload);
|
$this->model->update($payload);
|
||||||
|
@ -99,11 +101,11 @@ class Form extends Component
|
||||||
<form class="grid grid-cols-2 gap-3">
|
<form class="grid grid-cols-2 gap-3">
|
||||||
<x-form::text name="name" wire:model="name" label="Beschreibung" required />
|
<x-form::text name="name" wire:model="name" label="Beschreibung" required />
|
||||||
<x-form::text name="domain" wire:model="domain" label="Domain" required />
|
<x-form::text name="domain" wire:model="domain" label="Domain" required />
|
||||||
<x-form::select name="cls" wire:model.live="cls" label="Typ" :options="$types" required />
|
<x-form::select name="typeClass" wire:model.live="typeClass" label="Typ" :options="$types" required />
|
||||||
@foreach($this->fields() as $index => $field)
|
@foreach($this->fields() as $index => $field)
|
||||||
<x-form::text
|
<x-form::text
|
||||||
wire:key="index"
|
wire:key="index"
|
||||||
wire:model="params.{{$field['name']}}"
|
wire:model="type.{{$field['name']}}"
|
||||||
:label="$field['label']"
|
:label="$field['label']"
|
||||||
:type="$field['type']"
|
:type="$field['type']"
|
||||||
:name="$field['name']"
|
:name="$field['name']"
|
||||||
|
|
|
@ -4,7 +4,6 @@ namespace Tests\Feature\Mailgateway;
|
||||||
|
|
||||||
use App\Mailgateway\Models\Mailgateway;
|
use App\Mailgateway\Models\Mailgateway;
|
||||||
use App\Mailgateway\Types\LocalType;
|
use App\Mailgateway\Types\LocalType;
|
||||||
use App\Mailgateway\Types\MailmanType;
|
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
use Modules\Mailgateway\Components\SettingView;
|
use Modules\Mailgateway\Components\SettingView;
|
||||||
|
@ -21,7 +20,7 @@ it('test it can view index page', function () {
|
||||||
|
|
||||||
it('test it displays local gateways', function () {
|
it('test it displays local gateways', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
Mailgateway::factory()->type(LocalType::class, [])->name('Lore')->domain('example.com')->create();
|
Mailgateway::factory()->type(LocalType::from([]))->name('Lore')->domain('example.com')->create();
|
||||||
|
|
||||||
Livewire::test(SettingView::class)
|
Livewire::test(SettingView::class)
|
||||||
->assertSeeHtml('example.com')
|
->assertSeeHtml('example.com')
|
||||||
|
@ -32,8 +31,8 @@ it('test it displays local gateways', function () {
|
||||||
|
|
||||||
it('displays mailman gateways', function () {
|
it('displays mailman gateways', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
$typeParams = MailmanTypeRequest::new()->succeeds()->create(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner']);
|
$typeParams = MailmanTypeRequest::new()->succeeds()->state(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner']);
|
||||||
Mailgateway::factory()->type(MailmanType::class, $typeParams)->create();
|
Mailgateway::factory()->type($typeParams->toData())->create();
|
||||||
|
|
||||||
Livewire::test(SettingView::class)->assertSeeHtml('Verbindung erfolgreich');
|
Livewire::test(SettingView::class)->assertSeeHtml('Verbindung erfolgreich');
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,39 +17,32 @@ it('test it saves a mail gateway', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
Livewire::test(Form::class)
|
Livewire::test(Form::class)
|
||||||
|
->set('typeClass', LocalType::class)
|
||||||
->set('name', 'lala')
|
->set('name', 'lala')
|
||||||
->set('domain', 'example.com')
|
->set('domain', 'example.com')
|
||||||
->set('cls', LocalType::class)
|
|
||||||
->call('onSave')
|
->call('onSave')
|
||||||
|
->assertHasNoErrors()
|
||||||
->assertDispatched('closeModal')
|
->assertDispatched('closeModal')
|
||||||
->assertDispatched('refresh-page')
|
->assertDispatched('refresh-page')
|
||||||
->assertDispatched('success');
|
->assertDispatched('success');
|
||||||
|
|
||||||
$this->assertDatabaseHas('mailgateways', [
|
test()->assertDatabaseHas('mailgateways', [
|
||||||
'domain' => 'example.com',
|
'domain' => 'example.com',
|
||||||
'name' => 'lala',
|
'name' => 'lala',
|
||||||
'type' => json_encode([
|
'type' => json_encode([
|
||||||
'cls' => LocalType::class,
|
'type' => LocalType::class,
|
||||||
'params' => [],
|
'data' => [],
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('validates type', function () {
|
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
|
||||||
|
|
||||||
Livewire::test(Form::class)
|
|
||||||
->set('cls', '')
|
|
||||||
->assertHasErrors(['cls' => 'required']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('test it validates mail gateway', function (array $attributes, array $errors) {
|
it('test it validates mail gateway', function (array $attributes, array $errors) {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
Livewire::test(Form::class)
|
Livewire::test(Form::class)
|
||||||
->set('name', 'lala')
|
->set('name', 'lala')
|
||||||
->set('domain', 'example.com')
|
->set('domain', 'example.com')
|
||||||
->set('cls', LocalType::class)
|
->set('typeClass', LocalType::class)
|
||||||
->setArray($attributes)
|
->setArray($attributes)
|
||||||
->call('onSave')
|
->call('onSave')
|
||||||
->assertHasErrors($errors)
|
->assertHasErrors($errors)
|
||||||
|
@ -59,6 +52,7 @@ it('test it validates mail gateway', function (array $attributes, array $errors)
|
||||||
})->with([
|
})->with([
|
||||||
[['name' => ''], ['name' => 'required']],
|
[['name' => ''], ['name' => 'required']],
|
||||||
[['domain' => ''], ['domain' => 'required']],
|
[['domain' => ''], ['domain' => 'required']],
|
||||||
|
[['typeClass' => ''], ['typeClass' => 'required']],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
it('test it validates mailman type', function (array $attributes, array $errors) {
|
it('test it validates mailman type', function (array $attributes, array $errors) {
|
||||||
|
@ -67,20 +61,20 @@ it('test it validates mailman type', function (array $attributes, array $errors)
|
||||||
Livewire::test(Form::class)
|
Livewire::test(Form::class)
|
||||||
->set('name', 'lala')
|
->set('name', 'lala')
|
||||||
->set('domain', 'example.com')
|
->set('domain', 'example.com')
|
||||||
->set('cls', MailmanType::class)
|
->set('typeClass', MailmanType::class)
|
||||||
->set('params.url', 'exampl.com')
|
->set('type.url', 'exampl.com')
|
||||||
->set('params.user', '::user::')
|
->set('type.user', '::user::')
|
||||||
->set('params.password', 'password')
|
->set('type.password', 'password')
|
||||||
->setArray($attributes)
|
->setArray($attributes)
|
||||||
->call('onSave')
|
->call('onSave')
|
||||||
->assertHasErrors($errors)
|
->assertHasErrors($errors)
|
||||||
->assertNotDispatched('closeModal');
|
->assertNotDispatched('closeModal');
|
||||||
})->with([
|
})->with([
|
||||||
[['params.url' => ''], ['params.url' => 'required']],
|
[['type.url' => ''], ['type.url' => 'required']],
|
||||||
[['params.user' => ''], ['params.user' => 'required']],
|
[['type.user' => ''], ['type.user' => 'required']],
|
||||||
[['params.password' => ''], ['params.password' => 'required']],
|
[['type.password' => ''], ['type.password' => 'required']],
|
||||||
[['params.owner' => ''], ['params.owner' => 'required']],
|
[['type.owner' => ''], ['type.owner' => 'required']],
|
||||||
[['params.owner' => 'aaa'], ['params.owner' => 'email']],
|
[['type.owner' => 'aaa'], ['type.owner' => 'email']],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
it('test it stores mailman gateway', function () {
|
it('test it stores mailman gateway', function () {
|
||||||
|
@ -92,16 +86,16 @@ it('test it stores mailman gateway', function () {
|
||||||
->setArray([
|
->setArray([
|
||||||
'name' => 'lala',
|
'name' => 'lala',
|
||||||
'domain' => 'https://example.com',
|
'domain' => 'https://example.com',
|
||||||
'cls' => MailmanType::class,
|
'typeClass' => MailmanType::class,
|
||||||
'params' => $typeParams
|
|
||||||
])
|
])
|
||||||
|
->setArray('type', $typeParams)
|
||||||
->call('onSave')
|
->call('onSave')
|
||||||
->assertDispatched('closeModal');
|
->assertDispatched('closeModal');
|
||||||
|
|
||||||
$this->assertDatabaseHas('mailgateways', [
|
test()->assertDatabaseHas('mailgateways', [
|
||||||
'type' => json_encode([
|
'type' => json_encode([
|
||||||
'cls' => MailmanType::class,
|
'type' => MailmanType::class,
|
||||||
'params' => $typeParams,
|
'data' => $typeParams,
|
||||||
]),
|
]),
|
||||||
'name' => 'lala',
|
'name' => 'lala',
|
||||||
'domain' => 'https://example.com',
|
'domain' => 'https://example.com',
|
||||||
|
@ -117,12 +111,12 @@ it('test it checks mailman connection', function () {
|
||||||
->setArray([
|
->setArray([
|
||||||
'name' => 'lala',
|
'name' => 'lala',
|
||||||
'domain' => 'https://example.com',
|
'domain' => 'https://example.com',
|
||||||
'cls' => MailmanType::class,
|
'typeClass' => MailmanType::class,
|
||||||
'params' => $typeParams
|
|
||||||
])
|
])
|
||||||
|
->setArray('type', $typeParams)
|
||||||
->call('onSave')
|
->call('onSave')
|
||||||
->assertHasErrors('connection')
|
->assertHasErrors('connection')
|
||||||
->assertNotDispatched('closeModal');
|
->assertNotDispatched('closeModal');
|
||||||
|
|
||||||
$this->assertDatabaseCount('mailgateways', 0);
|
test()->assertDatabaseCount('mailgateways', 0);
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,47 +17,52 @@ uses(TestCase::class);
|
||||||
it('test it sets attributes for mailman', function () {
|
it('test it sets attributes for mailman', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
$typeParams = MailmanTypeRequest::new()->create(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner']);
|
$typeParams = MailmanTypeRequest::new()->state(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner']);
|
||||||
$mailgateway = Mailgateway::factory()->type(MailmanType::class, $typeParams)->create(['name' => '::name::', 'domain' => 'example.com']);
|
$mailgateway = Mailgateway::factory()->type($typeParams->toData())->create(['name' => '::name::', 'domain' => 'example.com']);
|
||||||
|
|
||||||
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
||||||
->assertSet('model', fn ($m) => $m->is($mailgateway))
|
->assertSet('model', fn ($m) => $m->is($mailgateway))
|
||||||
->assertSet('name', '::name::')
|
->assertSet('name', '::name::')
|
||||||
->assertSet('domain', 'example.com')
|
->assertSet('domain', 'example.com')
|
||||||
->assertSet('cls', MailmanType::class)
|
->assertSet(
|
||||||
->assertSet('params.url', 'https://mailman.example.com')
|
'type',
|
||||||
->assertSet('params.user', 'user')
|
fn ($type) => $type instanceof MailmanType
|
||||||
->assertSet('params.password', 'password')
|
&& $type->url === 'https://mailman.example.com'
|
||||||
->assertSet('params.owner', 'owner');
|
&& $type->user === 'user' &&
|
||||||
|
$type->password === 'password'
|
||||||
|
&& $type->owner === 'owner'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test it sets attributes for local', function () {
|
it('test it sets attributes for local', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
$mailgateway = Mailgateway::factory()->type(LocalType::class, [])->create(['name' => '::name::', 'domain' => 'example.com']);
|
$mailgateway = Mailgateway::factory()->create(['name' => '::name::', 'domain' => 'example.com']);
|
||||||
|
|
||||||
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
||||||
->assertSet('name', '::name::')
|
->assertSet('name', '::name::')
|
||||||
->assertSet('domain', 'example.com')
|
->assertSet('domain', 'example.com')
|
||||||
->assertSet('cls', LocalType::class)
|
->assertSet('type', fn ($type) => $type instanceof LocalType);
|
||||||
->assertSet('params', []);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test it validates type', function () {
|
it('test it validates type', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
$mailgateway = Mailgateway::factory()->type(LocalType::class, [])->create(['name' => '::name::', 'domain' => 'example.com']);
|
$mailgateway = Mailgateway::factory()->create(['name' => '::name::', 'domain' => 'example.com']);
|
||||||
|
|
||||||
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
||||||
->set('cls', '')
|
->set('typeClass', '')
|
||||||
->assertHasErrors(['cls' => 'required']);
|
->assertHasErrors(['typeClass' => 'required']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test it updates a mailman gateway without updating password', function () {
|
it('test it updates a mailman gateway without updating password', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
$typeParams = MailmanTypeRequest::new()->succeeds()->create(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com']);
|
$typeParams = MailmanTypeRequest::new()
|
||||||
$mailgateway = Mailgateway::factory()->type(MailmanType::class, $typeParams)->create(['name' => '::name::', 'domain' => 'example.com']);
|
->succeeds()
|
||||||
|
->state(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com'])
|
||||||
|
->toData();
|
||||||
|
$mailgateway = Mailgateway::factory()->type($typeParams)->create(['name' => '::name::', 'domain' => 'example.com']);
|
||||||
|
|
||||||
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
||||||
->set('name', '::newname::')
|
->set('name', '::newname::')
|
||||||
|
@ -70,37 +75,37 @@ it('test it updates a mailman gateway without updating password', function () {
|
||||||
$this->assertDatabaseCount('mailgateways', 1);
|
$this->assertDatabaseCount('mailgateways', 1);
|
||||||
$this->assertDatabaseHas('mailgateways', [
|
$this->assertDatabaseHas('mailgateways', [
|
||||||
'name' => '::newname::',
|
'name' => '::newname::',
|
||||||
'type' => json_encode(['cls' => MailmanType::class, 'params' => $typeParams]),
|
'type' => json_encode(['type' => MailmanType::class, 'data' => $typeParams]),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test it updates a mailman gateway with password', function () {
|
it('test it updates a mailman gateway with password', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
$typeParams = MailmanTypeRequest::new()->create(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com']);
|
$typeParams = MailmanTypeRequest::new()->state(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com']);
|
||||||
$newTypeParams = MailmanTypeRequest::new()->succeeds()->create(['url' => 'https://mailman.example.com', 'user' => 'newuser', 'password' => 'password', 'owner' => 'owner@example.com']);
|
$newTypeParams = MailmanTypeRequest::new()->succeeds()->create(['url' => 'https://mailman.example.com', 'user' => 'newuser', 'password' => 'password', 'owner' => 'owner@example.com']);
|
||||||
$mailgateway = Mailgateway::factory()->type(MailmanType::class, $typeParams)->create();
|
$mailgateway = Mailgateway::factory()->type($typeParams->toData())->create();
|
||||||
|
|
||||||
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
||||||
->set('params.user', 'newuser')
|
->set('type.user', 'newuser')
|
||||||
->call('onSave')
|
->call('onSave')
|
||||||
->assertHasNoErrors();
|
->assertHasNoErrors();
|
||||||
|
|
||||||
$this->assertDatabaseCount('mailgateways', 1);
|
$this->assertDatabaseCount('mailgateways', 1);
|
||||||
$this->assertDatabaseHas('mailgateways', [
|
$this->assertDatabaseHas('mailgateways', [
|
||||||
'type' => json_encode(['cls' => MailmanType::class, 'params' => $newTypeParams]),
|
'type' => json_encode(['type' => MailmanType::class, 'data' => $newTypeParams]),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test it checks mailgateway connection when updating', function () {
|
it('test it checks mailgateway connection when updating', function () {
|
||||||
test()->withoutExceptionHandling()->login()->loginNami();
|
test()->withoutExceptionHandling()->login()->loginNami();
|
||||||
|
|
||||||
$typeParams = MailmanTypeRequest::new()->create(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com']);
|
$typeParams = MailmanTypeRequest::new()->state(['url' => 'https://mailman.example.com', 'user' => 'user', 'password' => 'password', 'owner' => 'owner@example.com']);
|
||||||
MailmanTypeRequest::new()->fails()->create(['url' => 'https://mailman.example.com', 'user' => 'newuser', 'password' => 'password', 'owner' => 'owner@example.com']);
|
MailmanTypeRequest::new()->fails()->create(['url' => 'https://mailman.example.com', 'user' => 'newuser', 'password' => 'password', 'owner' => 'owner@example.com']);
|
||||||
$mailgateway = Mailgateway::factory()->type(MailmanType::class, $typeParams)->create();
|
$mailgateway = Mailgateway::factory()->type($typeParams->toData())->create();
|
||||||
|
|
||||||
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
Livewire::test(Form::class, ['id' => $mailgateway->id])
|
||||||
->set('params.user', 'newuser')
|
->set('type.user', 'newuser')
|
||||||
->call('onSave')
|
->call('onSave')
|
||||||
->assertHasErrors('connection');
|
->assertHasErrors('connection');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue