adrema/tests/EndToEnd/Maildispatcher/StoreTest.php

86 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2023-06-12 13:12:46 +02:00
<?php
2024-01-28 11:42:32 +01:00
namespace Tests\EndToEnd\Maildispatcher;
2023-06-12 13:12:46 +02:00
use \Mockery as M;
2023-06-12 13:12:46 +02:00
use App\Activity;
2023-07-10 10:31:56 +02:00
use App\Maildispatcher\Models\Localmaildispatcher;
2023-06-12 13:12:46 +02:00
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-06-12 13:12:46 +02:00
use App\Member\Member;
use App\Member\Membership;
2024-01-28 11:42:32 +01:00
use Tests\EndToEndTestCase;
2023-06-12 13:12:46 +02:00
2024-01-28 11:42:32 +01:00
class StoreTest extends EndToEndTestCase
2023-06-12 13:12:46 +02:00
{
public function setUp(): void
{
parent::setUp();
$this->login()->loginNami();
}
public function testItCanStoreAMail(): void
{
$gateway = Mailgateway::factory()->type(LocalType::class, [])->domain('example.com')->create();
Member::factory()->defaults()->create();
Member::factory()->defaults()->has(Membership::factory()->inLocal('Leiter*in', 'Wölfling'))->create(['email' => 'jane@example.com']);
$activityId = Activity::first()->id;
2024-01-28 11:42:32 +01:00
sleep(1);
2023-06-15 00:12:20 +02:00
$response = $this->postJson('/maildispatcher', [
2023-06-12 13:12:46 +02:00
'name' => 'test',
'gateway_id' => $gateway->id,
2023-06-15 00:12:20 +02:00
'filter' => ['activity_ids' => [$activityId]],
2023-06-12 13:12:46 +02:00
]);
$response->assertStatus(201);
$this->assertDatabaseHas('maildispatchers', [
'name' => 'test',
'gateway_id' => $gateway->id,
2023-06-15 00:12:20 +02:00
'filter' => "{\"activity_ids\":[{$activityId}]}",
2023-06-12 13:12:46 +02:00
]);
$dispatcher = Maildispatcher::first();
$this->assertDatabaseCount('localmaildispatchers', 1);
$this->assertDatabaseHas('localmaildispatchers', [
'from' => 'test@example.com',
'to' => 'jane@example.com',
]);
}
2023-07-10 10:31:56 +02:00
public function testItDoesntStoreTwoMembersWithSameEmailAddress(): void
{
$type = M::mock(LocalType::class)->makePartial();
$type->shouldReceive('add')->once();
app()->instance(LocalType::class, $type);
$gateway = Mailgateway::factory()->type(LocalType::class, [])->domain('example.com')->create();
Member::factory()->defaults()->create(['email' => 'jane@example.com']);
Member::factory()->defaults()->create(['email' => 'jane@example.com']);
2024-01-28 11:42:32 +01:00
sleep(1);
$this->postJson('/maildispatcher', [
'name' => 'test',
'gateway_id' => $gateway->id,
'filter' => [],
]);
}
2023-07-10 10:31:56 +02:00
public function testMaildispatcherReceivesLowerVersionOfEmail(): void
{
$gateway = Mailgateway::factory()->type(LocalType::class, [])->create();
Member::factory()->defaults()->create(['email' => 'Jane@example.com']);
2024-01-28 11:42:32 +01:00
sleep(1);
2023-07-10 10:31:56 +02:00
$this->postJson('/maildispatcher', [
'name' => 'test',
'gateway_id' => $gateway->id,
'filter' => [],
]);
$this->assertEquals('jane@example.com', Localmaildispatcher::first()->to);
}
2023-06-12 13:12:46 +02:00
}