adrema/tests/EndToEnd/Maildispatcher/UpdateTest.php

89 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2023-07-17 11:50:26 +02:00
<?php
2024-01-28 11:42:32 +01:00
namespace Tests\EndToEnd\Maildispatcher;
2023-07-17 11:50:26 +02:00
use App\Maildispatcher\Actions\ResyncAction;
use App\Maildispatcher\Models\Maildispatcher;
2024-10-24 23:17:23 +02:00
use Modules\Mailgateway\Models\Mailgateway;
2024-10-24 23:24:21 +02:00
use Modules\Mailgateway\Types\LocalType;
2023-07-17 11:50:26 +02:00
use App\Member\FilterScope;
use App\Member\Member;
2024-01-28 11:42:32 +01:00
use Tests\EndToEndTestCase;
2023-07-17 11:50:26 +02:00
2024-01-28 11:42:32 +01:00
class UpdateTest extends EndToEndTestCase
2023-07-17 11:50:26 +02:00
{
public function setUp(): void
{
parent::setUp();
$this->login()->loginNami();
}
public function testItCanUpdateFilters(): void
{
2024-01-28 11:42:32 +01:00
$this->withoutExceptionHandling();
2023-07-17 11:50:26 +02:00
$dispatcher = Maildispatcher::factory()
->for(Mailgateway::factory()->type(LocalType::class, [])->domain('example.com'), 'gateway')
->filter(FilterScope::from([]))
->create();
Member::factory()->defaults()->create(['email' => 'to@example.com']);
2024-01-28 11:42:32 +01:00
sleep(1);
$this->patchJson("/maildispatcher/{$dispatcher->id}", [
2023-07-17 11:50:26 +02:00
'name' => 'test',
'gateway_id' => $dispatcher->gateway->id,
'filter' => [],
]);
$this->assertDatabaseHas('localmaildispatchers', [
'from' => 'test@example.com',
'to' => 'to@example.com',
]);
}
public function testItUpdatesCurrentMails(): void
{
$dispatcher = Maildispatcher::factory()
->for(Mailgateway::factory()->type(LocalType::class, [])->domain('example.com'), 'gateway')
->filter(FilterScope::from([]))
->create();
Member::factory()->defaults()->create(['email' => 'to@example.com']);
ResyncAction::run();
2024-01-28 11:42:32 +01:00
sleep(1);
2023-07-17 11:50:26 +02:00
$response = $this->patchJson("/maildispatcher/{$dispatcher->id}", [
'name' => 'testa',
'gateway_id' => $dispatcher->gateway->id,
'filter' => [],
]);
$this->assertDatabaseMissing('localmaildispatchers', [
'from' => 'test@example.com',
]);
$this->assertDatabaseHas('localmaildispatchers', [
'from' => 'testa@example.com',
'to' => 'to@example.com',
]);
}
public function testItDeletesOldEmailAddresses(): void
{
$dispatcher = Maildispatcher::factory()
->for(Mailgateway::factory()->type(LocalType::class, [])->domain('example.com'), 'gateway')
->filter(FilterScope::from([]))
->create();
$member = Member::factory()->defaults()->create(['email' => 'to@example.com']);
2024-01-28 11:42:32 +01:00
sleep(1);
2023-07-17 11:50:26 +02:00
ResyncAction::run();
$member->update(['email' => 'to2@example.com']);
ResyncAction::run();
$this->assertDatabaseMissing('localmaildispatchers', [
'to' => 'to@example.com',
]);
$this->assertDatabaseHas('localmaildispatchers', [
'to' => 'to2@example.com',
]);
}
}