akaunting/tests/Feature/Email/TooManyEmailsSentTest.php
2023-05-03 00:14:25 +03:00

52 lines
1.2 KiB
PHP

<?php
namespace Tests\Feature\Email;
use App\Events\Email\TooManyEmailsSent;
use Tests\Feature\FeatureTestCase;
class TooManyEmailsSentTest extends FeatureTestCase
{
public function testItShouldNotBlockIpDueToTooManyEmailsSent()
{
$this->loginAs();
config(['firewall.enabled' => true]);
for ($i = 0; $i < 19; $i++) {
event(new TooManyEmailsSent(user_id()));
}
$this->assertDatabaseHas('firewall_logs', [
'user_id' => user_id(),
'middleware' => 'too_many_emails_sent',
]);
$this->assertDatabaseCount('firewall_logs', 19);
$this->assertDatabaseEmpty('firewall_ips');
}
public function testItShouldBlockIpDueToTooManyEmailsSent()
{
$this->loginAs();
config(['firewall.enabled' => true]);
for ($i = 0; $i < 20; $i++) {
event(new TooManyEmailsSent(user_id()));
}
$this->assertDatabaseHas('firewall_logs', [
'user_id' => user_id(),
'middleware' => 'too_many_emails_sent',
]);
$this->assertDatabaseCount('firewall_logs', 20);
$this->assertDatabaseHas('firewall_ips', [
'ip' => request()->ip(),
]);
}
}