Delete old mailgateway tests

This commit is contained in:
philipp lang 2024-10-20 18:29:32 +02:00
parent ee5b923f25
commit 908f99f403
4 changed files with 0 additions and 267 deletions

View File

@ -1,92 +0,0 @@
<?php
namespace Tests\Feature\Mailgateway;
use App\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\LocalType;
use App\Mailgateway\Types\MailmanType;
use App\Mailman\Support\MailmanService;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Phake;
use Tests\RequestFactories\MailmanTypeRequest;
use Tests\TestCase;
class IndexTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
$this->login()->loginNami();
}
public function testItCanViewIndexPage(): void
{
$response = $this->get('/setting/mailgateway');
$response->assertOk();
}
public function testItDisplaysLocalGateways(): void
{
$this->withoutExceptionHandling();
$mailgateway = Mailgateway::factory()->type(LocalType::class, [])->name('Lore')->domain('example.com')->create();
$response = $this->get('/setting/mailgateway');
$this->assertInertiaHas('example.com', $response, 'data.data.0.domain');
$this->assertInertiaHas('Lore', $response, 'data.data.0.name');
$this->assertInertiaHas('Lokal', $response, 'data.data.0.type_human');
$this->assertInertiaHas(true, $response, 'data.data.0.works');
$this->assertInertiaHas($mailgateway->id, $response, 'data.data.0.id');
$this->assertInertiaHas(route('mailgateway.update', ['mailgateway' => $mailgateway->id]), $response, 'data.data.0.links.update');
}
public function testItDisplaysMailmanGateways(): void
{
$this->stubIo(MailmanService::class, function ($mock) {
Phake::when($mock)->setCredentials()->thenReturn($mock);
Phake::when($mock)->check()->thenReturn(true);
});
$this->withoutExceptionHandling();
Mailgateway::factory()->type(MailmanType::class, MailmanTypeRequest::new()->create())->create();
$this->get('/setting/mailgateway')->assertOk();
}
public function testItHasMeta(): void
{
$this->withoutExceptionHandling();
$response = $this->get('/setting/mailgateway');
$this->assertInertiaHas(route('mailgateway.store'), $response, 'data.meta.links.store');
$this->assertInertiaHas([
'id' => null,
'name' => '-- kein --',
], $response, 'data.meta.types.0');
$this->assertInertiaHas([
'id' => LocalType::class,
'name' => 'Lokal',
], $response, 'data.meta.types.1');
$this->assertInertiaHas([
'id' => MailmanType::class,
'fields' => [
[
'name' => 'url',
'is_required' => true,
],
],
], $response, 'data.meta.types.2');
$this->assertInertiaHas([
'domain' => '',
'name' => '',
'type' => [
'params' => [],
'cls' => null,
],
], $response, 'data.meta.default');
}
}

View File

@ -1,48 +0,0 @@
<?php
namespace Tests\Feature\Mailgateway;
use App\Mailgateway\Types\MailmanType;
use App\Mailman\Support\MailmanService;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Phake;
use Tests\TestCase;
class MailmanTypeTest extends TestCase
{
use DatabaseTransactions;
public function testItChecksForWorks(): void
{
$this->withoutExceptionHandling();
$this->stubIo(MailmanService::class, function ($mock) {
Phake::when($mock)->setCredentials('https://example.com', 'user', 'secret')->thenReturn($mock);
Phake::when($mock)->check()->thenReturn(true);
Phake::when($mock)->setOwner('owner@example.com')->thenReturn($mock);
});
$type = app(MailmanType::class)->setParams([
'url' => 'https://example.com',
'user' => 'user',
'password' => 'secret',
'owner' => 'owner@example.com',
]);
$this->assertTrue($type->works());
}
public function testItCanReturnFalse(): void
{
$this->withoutExceptionHandling();
$this->stubIo(MailmanService::class, function ($mock) {
Phake::when($mock)->setCredentials('https://example.com', 'user', 'secret')->thenReturn($mock);
Phake::when($mock)->check()->thenReturn(false);
});
$type = app(MailmanType::class)->setParams([
'url' => 'https://example.com',
'user' => 'user',
'password' => 'secret',
]);
$this->assertFalse($type->works());
}
}

View File

@ -1,96 +0,0 @@
<?php
namespace Tests\Feature\Mailgateway;
use App\Mailgateway\Types\LocalType;
use App\Mailgateway\Types\MailmanType;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Phake;
use Tests\RequestFactories\MailgatewayRequestFactory;
use Tests\RequestFactories\MailmanTypeRequest;
use Tests\TestCase;
class StoreTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
$this->login()->loginNami();
}
public function testItCanStoreALocalGateway(): void
{
$response = $this->postJson('/api/mailgateway', MailgatewayRequestFactory::new()->name('lala')->type(LocalType::class, [])->domain('example.com')->create());
$response->assertOk();
$this->assertDatabaseHas('mailgateways', [
'domain' => 'example.com',
'name' => 'lala',
'type' => json_encode([
'cls' => LocalType::class,
'params' => [],
]),
]);
}
public function testItCanStoreAMailmanGateway(): void
{
$typeParams = ['url' => 'https://example.com', 'user' => 'user', 'password' => 'secret', 'owner' => 'owner@example.com'];
$this->stubIo(MailmanType::class, function ($mock) use ($typeParams) {
Phake::when($mock)->setParams($typeParams)->thenReturn($mock);
Phake::when($mock)->works()->thenReturn(true);
Phake::when($mock)->setOwner('owner@example.com')->thenReturn($mock);
});
$this->postJson('/api/mailgateway', MailgatewayRequestFactory::new()->type(MailmanType::class, MailmanTypeRequest::new()->create($typeParams))->create());
$this->assertDatabaseHas('mailgateways', [
'type' => json_encode([
'cls' => MailmanType::class,
'params' => $typeParams,
]),
]);
}
public function testItThrowsErrorWhenMailmanConnectionFailed(): void
{
$typeParams = ['url' => 'https://example.com', 'user' => 'user', 'password' => 'secret', 'owner' => 'owner@example.com'];
$this->stubIo(MailmanType::class, function ($mock) use ($typeParams) {
Phake::when($mock)->setParams($typeParams)->thenReturn($mock);
Phake::when($mock)->works()->thenReturn(false);
Phake::when($mock)->setOwner('owner@example.com')->thenReturn($mock);
});
$this->postJson('/api/mailgateway', MailgatewayRequestFactory::new()->type(MailmanType::class, MailmanTypeRequest::new()->create($typeParams))->create())
->assertJsonValidationErrors('connection');
}
public function testItValidatesCustomFields(): void
{
$typeParams = ['url' => 'https://example.com', 'user' => '', 'password' => 'secret', 'owner' => 'aaaa'];
$this->stubIo(MailmanType::class, function ($mock) use ($typeParams) {
Phake::when($mock)->setParams($typeParams)->thenReturn($mock);
Phake::when($mock)->works()->thenReturn(false);
});
$this->postJson('/api/mailgateway', MailgatewayRequestFactory::new()->type(MailmanType::class, MailmanTypeRequest::new()->create($typeParams))->create())
->assertJsonValidationErrors([
'type.params.user' => 'Benutzer ist erforderlich.',
'type.params.owner' => 'E-Mail-Adresse des Eigentümers muss eine gültige E-Mail-Adresse sein.',
]);
}
public function testItValidatesType(): void
{
$this->postJson('/api/mailgateway', MailgatewayRequestFactory::new()->missingType()->create())
->assertJsonValidationErrors('type.cls');
}
public function testItValidatesNameAndDomain(): void
{
$this->postJson('/api/mailgateway', MailgatewayRequestFactory::new()->withoutName()->withoutDomain()->create())
->assertJsonValidationErrors('domain')
->assertJsonValidationErrors('name');
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace Tests\Feature\Mailgateway;
use App\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\LocalType;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\RequestFactories\MailgatewayRequestFactory;
use Tests\TestCase;
class UpdateTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
$this->login()->loginNami();
}
public function testItCanUpdateALocalGateway(): void
{
$mailgateway = Mailgateway::factory()->type(LocalType::class, [])->create();
$response = $this->patchJson("/api/mailgateway/{$mailgateway->id}", MailgatewayRequestFactory::new()->name('lala')->type(LocalType::class, [])->domain('example.com')->create());
$response->assertOk();
$this->assertDatabaseCount('mailgateways', 1);
}
}