fixed tests
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2023-07-19 10:44:17 +02:00
parent 07ca1d7903
commit debe9969ae
4 changed files with 12 additions and 156 deletions

View File

@ -69,8 +69,8 @@ class MailmanType extends Type
'name' => 'owner',
'label' => 'E-Mail-Adresse des Eigentümers',
'type' => 'email',
'storeValidator' => 'required|max:255',
'updateValidator' => 'required|max:255',
'storeValidator' => 'required|email|max:255',
'updateValidator' => 'required|email|max:255',
'default' => '',
],
];

View File

@ -39,10 +39,11 @@ class StoreTest extends TestCase
public function testItCanStoreAMailmanGateway(): void
{
$typeParams = ['url' => 'https://example.com', 'user' => 'user', 'password' => 'secret'];
$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());
@ -56,10 +57,11 @@ class StoreTest extends TestCase
public function testItThrowsErrorWhenMailmanConnectionFailed(): void
{
$typeParams = ['url' => 'https://example.com', 'user' => 'user', 'password' => 'secret'];
$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');
@ -67,13 +69,16 @@ class StoreTest extends TestCase
public function testItValidatesCustomFields(): void
{
$typeParams = ['url' => 'https://example.com', 'user' => '', 'password' => 'secret'];
$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.']);
->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

View File

@ -1,150 +0,0 @@
<?php
namespace Tests\Feature\Mailman;
use App\Mailman\Data\MailingList;
use App\Mailman\MailmanSettings;
use App\Mailman\Support\MailmanService;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\LazyCollection;
use Phake;
use Tests\RequestFactories\MailmanListRequestFactory;
use Tests\TestCase;
class SettingTest extends TestCase
{
use DatabaseTransactions;
public function testItGetsMailSettings(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$this->stubIo(MailmanService::class, function ($mock) {
Phake::when($mock)->fromSettings(Phake::anyParameters())->thenReturn($mock);
Phake::when($mock)->check()->thenReturn(true);
Phake::when($mock)->getLists()->thenReturn(LazyCollection::make(function () {
yield MailingList::from(MailmanListRequestFactory::new()->create(['list_id' => 'F', 'fqdn_listname' => 'admin@example.com']));
}));
});
MailmanSettings::fake([
'base_url' => 'http://mailman.test/api',
'username' => 'user',
'password' => 'secret',
'is_active' => true,
]);
$response = $this->get('/setting/mailman');
$response->assertOk();
$this->assertInertiaHas([
'base_url' => 'http://mailman.test/api',
'username' => 'user',
'password' => '',
'is_active' => true,
], $response, 'data');
$this->assertInertiaHas(true, $response, 'state');
$this->assertInertiaHas('admin@example.com', $response, 'lists.0.name');
$this->assertInertiaHas('F', $response, 'lists.0.id');
}
public function testItReturnsWrongStateWhenLoginFailed(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$this->stubIo(MailmanService::class, function ($mock) {
Phake::when($mock)->fromSettings(Phake::anyParameters())->thenReturn($mock);
Phake::when($mock)->check()->thenReturn(false);
});
MailmanSettings::fake([
'base_url' => 'http://mailman.test/api',
'username' => 'user',
'password' => 'secret',
'is_active' => true,
]);
$response = $this->get('/setting/mailman');
$response->assertOk();
$this->assertInertiaHas(false, $response, 'state');
}
public function testItDoesntReturnAnyStateWhenMailmanIsInactive(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$this->stubIo(MailmanService::class, fn ($mock) => $mock);
MailmanSettings::fake([
'base_url' => 'http://mailman.test/api',
'username' => 'user',
'password' => 'secret',
'is_active' => false,
]);
$response = $this->get('/setting/mailman');
$response->assertOk();
$this->assertInertiaHas(null, $response, 'state');
Phake::verifyNoInteraction(app(MailmanService::class));
}
public function testItSetsMailmanSettings(): void
{
$this->stubIo(MailmanService::class, function ($mock) {
Phake::when($mock)->setCredentials('http://mailman.test/api', 'user', 'secret')->thenReturn($mock);
Phake::when($mock)->check()->thenReturn(true);
});
$this->withoutExceptionHandling()->login()->loginNami();
$response = $this->from('/setting/mailman')->post('/setting/mailman', [
'base_url' => 'http://mailman.test/api',
'username' => 'user',
'password' => 'secret',
'is_active' => true,
'all_parents_list' => 'P',
'all_list' => 'X',
]);
$response->assertRedirect('/setting/mailman');
$settings = app(MailmanSettings::class);
$this->assertEquals('http://mailman.test/api', $settings->base_url);
$this->assertEquals('secret', $settings->password);
$this->assertEquals('user', $settings->username);
$this->assertEquals('X', $settings->all_list);
$this->assertEquals('P', $settings->all_parents_list);
Phake::verify(app(MailmanService::class))->setCredentials('http://mailman.test/api', 'user', 'secret');
Phake::verify(app(MailmanService::class))->check();
}
public function testItThrowsErrorWhenLoginFailed(): void
{
$this->stubIo(MailmanService::class, function ($mock) {
Phake::when($mock)->setCredentials('http://mailman.test/api', 'user', 'secret')->thenReturn($mock);
Phake::when($mock)->check()->thenReturn(false);
});
$this->login()->loginNami();
$response = $this->from('/setting/mailman')->post('/setting/mailman', [
'base_url' => 'http://mailman.test/api',
'username' => 'user',
'password' => 'secret',
'is_active' => true,
]);
$response->assertSessionHasErrors(['mailman' => 'Verbindung fehlgeschlagen.']);
Phake::verify(app(MailmanService::class))->setCredentials('http://mailman.test/api', 'user', 'secret');
Phake::verify(app(MailmanService::class))->check();
}
public function testItValidatesPassword(): void
{
$this->stubIo(MailmanService::class, fn ($mock) => $mock);
$this->login()->loginNami();
$response = $this->from('/setting/mailman')->post('/setting/mailman', [
'base_url' => 'http://mailman.test/api',
'username' => 'user',
'password' => '',
'is_active' => true,
]);
$response->assertSessionHasErrors(['password' => 'Passwort ist erforderlich.']);
Phake::verifyNoInteraction(app(MailmanService::class));
}
}

View File

@ -12,6 +12,7 @@ class MailmanTypeRequest extends RequestFactory
'url' => 'https://'.$this->faker->domainName(),
'user' => $this->faker->firstName(),
'password' => $this->faker->password(),
'owner' => $this->faker->safeEmail(),
];
}
}