123 lines
4.0 KiB
PHP
123 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\Mailgateway;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Livewire\Livewire;
|
|
use Modules\Mailgateway\Components\Form;
|
|
use Modules\Mailgateway\Types\LocalType;
|
|
use Modules\Mailgateway\Types\MailmanType;
|
|
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('typeClass', LocalType::class)
|
|
->set('name', 'lala')
|
|
->set('domain', 'example.com')
|
|
->call('onSave')
|
|
->assertHasNoErrors()
|
|
->assertDispatched('closeModal')
|
|
->assertDispatched('refresh-page')
|
|
->assertDispatched('success');
|
|
|
|
test()->assertDatabaseHas('mailgateways', [
|
|
'domain' => 'example.com',
|
|
'name' => 'lala',
|
|
'type' => json_encode([
|
|
'type' => LocalType::class,
|
|
'data' => [],
|
|
]),
|
|
]);
|
|
});
|
|
|
|
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')
|
|
->set('typeClass', LocalType::class)
|
|
->setArray($attributes)
|
|
->call('onSave')
|
|
->assertHasErrors($errors)
|
|
->assertNotDispatched('closeModal')
|
|
->assertNotDispatched('refresh-page')
|
|
->assertNotDispatched('success');
|
|
})->with([
|
|
[['name' => ''], ['name' => 'required']],
|
|
[['domain' => ''], ['domain' => 'required']],
|
|
[['typeClass' => ''], ['typeClass' => 'required']],
|
|
]);
|
|
|
|
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('typeClass', MailmanType::class)
|
|
->set('type.url', 'exampl.com')
|
|
->set('type.user', '::user::')
|
|
->set('type.password', 'password')
|
|
->setArray($attributes)
|
|
->call('onSave')
|
|
->assertHasErrors($errors)
|
|
->assertNotDispatched('closeModal');
|
|
})->with([
|
|
[['type.url' => ''], ['type.url' => 'required']],
|
|
[['type.user' => ''], ['type.user' => 'required']],
|
|
[['type.password' => ''], ['type.password' => 'required']],
|
|
[['type.owner' => ''], ['type.owner' => 'required']],
|
|
[['type.owner' => 'aaa'], ['type.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',
|
|
'typeClass' => MailmanType::class,
|
|
])
|
|
->setArray('type', $typeParams)
|
|
->call('onSave')
|
|
->assertDispatched('closeModal');
|
|
|
|
test()->assertDatabaseHas('mailgateways', [
|
|
'type' => json_encode([
|
|
'type' => MailmanType::class,
|
|
'data' => $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',
|
|
'typeClass' => MailmanType::class,
|
|
])
|
|
->setArray('type', $typeParams)
|
|
->call('onSave')
|
|
->assertHasErrors('connection')
|
|
->assertNotDispatched('closeModal');
|
|
|
|
test()->assertDatabaseCount('mailgateways', 0);
|
|
});
|