2024-10-20 21:19:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Mailgateway;
|
|
|
|
|
|
|
|
use App\Mailgateway\Types\LocalType;
|
|
|
|
use App\Mailgateway\Types\MailmanType;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Livewire\Livewire;
|
|
|
|
use Modules\Mailgateway\Components\Form;
|
|
|
|
use Tests\RequestFactories\MailmanTypeRequest;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
uses(TestCase::class);
|
|
|
|
|
|
|
|
it('test it saves a mail gateway', function () {
|
|
|
|
test()->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
|
|
|
|
Livewire::test(Form::class)
|
|
|
|
->set('name', 'lala')
|
|
|
|
->set('domain', 'example.com')
|
2024-10-23 21:02:42 +02:00
|
|
|
->set('type', new LocalType())
|
2024-10-20 21:19:07 +02:00
|
|
|
->call('onSave')
|
2024-10-23 21:02:42 +02:00
|
|
|
->assertHasNoErrors()
|
2024-10-20 21:19:07 +02:00
|
|
|
->assertDispatched('closeModal')
|
2024-10-20 21:23:47 +02:00
|
|
|
->assertDispatched('refresh-page')
|
2024-10-20 21:19:07 +02:00
|
|
|
->assertDispatched('success');
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('mailgateways', [
|
|
|
|
'domain' => 'example.com',
|
|
|
|
'name' => 'lala',
|
|
|
|
'type' => json_encode([
|
2024-10-23 21:02:42 +02:00
|
|
|
'type' => LocalType::class,
|
|
|
|
'data' => [],
|
2024-10-20 21:19:07 +02:00
|
|
|
]),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test it validates mail gateway', function (array $attributes, array $errors) {
|
|
|
|
test()->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
|
|
|
|
Livewire::test(Form::class)
|
|
|
|
->set('name', 'lala')
|
|
|
|
->set('domain', 'example.com')
|
2024-10-23 21:02:42 +02:00
|
|
|
->set('type', new LocalType())
|
2024-10-20 21:19:07 +02:00
|
|
|
->setArray($attributes)
|
|
|
|
->call('onSave')
|
|
|
|
->assertHasErrors($errors)
|
|
|
|
->assertNotDispatched('closeModal')
|
2024-10-20 21:23:47 +02:00
|
|
|
->assertNotDispatched('refresh-page')
|
2024-10-20 21:19:07 +02:00
|
|
|
->assertNotDispatched('success');
|
|
|
|
})->with([
|
|
|
|
[['name' => ''], ['name' => 'required']],
|
|
|
|
[['domain' => ''], ['domain' => 'required']],
|
2024-10-23 21:02:42 +02:00
|
|
|
[['type' => ''], ['type' => 'required']],
|
2024-10-20 21:19:07 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
it('test it validates mailman type', function (array $attributes, array $errors) {
|
|
|
|
test()->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
|
|
|
|
Livewire::test(Form::class)
|
|
|
|
->set('name', 'lala')
|
|
|
|
->set('domain', 'example.com')
|
|
|
|
->set('cls', MailmanType::class)
|
|
|
|
->set('params.url', 'exampl.com')
|
|
|
|
->set('params.user', '::user::')
|
|
|
|
->set('params.password', 'password')
|
|
|
|
->setArray($attributes)
|
|
|
|
->call('onSave')
|
|
|
|
->assertHasErrors($errors)
|
|
|
|
->assertNotDispatched('closeModal');
|
|
|
|
})->with([
|
|
|
|
[['params.url' => ''], ['params.url' => 'required']],
|
|
|
|
[['params.user' => ''], ['params.user' => 'required']],
|
|
|
|
[['params.password' => ''], ['params.password' => 'required']],
|
|
|
|
[['params.owner' => ''], ['params.owner' => 'required']],
|
|
|
|
[['params.owner' => 'aaa'], ['params.owner' => 'email']],
|
|
|
|
]);
|
|
|
|
|
|
|
|
it('test it stores mailman gateway', function () {
|
|
|
|
test()->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
|
|
|
|
$typeParams = MailmanTypeRequest::new()->succeeds()->create(['url' => 'https://example.com', 'user' => 'user', 'password' => 'secret', 'owner' => 'owner@example.com']);
|
|
|
|
|
|
|
|
Livewire::test(Form::class)
|
|
|
|
->setArray([
|
|
|
|
'name' => 'lala',
|
|
|
|
'domain' => 'https://example.com',
|
|
|
|
'cls' => MailmanType::class,
|
|
|
|
'params' => $typeParams
|
|
|
|
])
|
|
|
|
->call('onSave')
|
|
|
|
->assertDispatched('closeModal');
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('mailgateways', [
|
|
|
|
'type' => json_encode([
|
|
|
|
'cls' => MailmanType::class,
|
|
|
|
'params' => $typeParams,
|
|
|
|
]),
|
|
|
|
'name' => 'lala',
|
|
|
|
'domain' => 'https://example.com',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('test it checks mailman connection', function () {
|
|
|
|
test()->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
|
|
|
|
$typeParams = MailmanTypeRequest::new()->fails()->create(['url' => 'https://example.com', 'user' => 'user', 'password' => 'secret', 'owner' => 'owner@example.com']);
|
|
|
|
|
|
|
|
Livewire::test(Form::class)
|
|
|
|
->setArray([
|
|
|
|
'name' => 'lala',
|
|
|
|
'domain' => 'https://example.com',
|
|
|
|
'cls' => MailmanType::class,
|
|
|
|
'params' => $typeParams
|
|
|
|
])
|
|
|
|
->call('onSave')
|
|
|
|
->assertHasErrors('connection')
|
|
|
|
->assertNotDispatched('closeModal');
|
|
|
|
|
|
|
|
$this->assertDatabaseCount('mailgateways', 0);
|
|
|
|
});
|