akaunting/tests/Feature/Email/TooManyEmailsSentTest.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2023-05-03 00:14:25 +03:00
<?php
namespace Tests\Feature\Email;
use App\Events\Email\TooManyEmailsSent;
use Tests\Feature\FeatureTestCase;
class TooManyEmailsSentTest extends FeatureTestCase
{
public function testItShouldNotBlockIpDueToTooManyEmailsSent()
{
$this->loginAs();
2023-08-03 00:29:12 +03:00
config(['firewall.middleware.too_many_emails_sent.enabled' => true]);
2023-05-03 00:14:25 +03:00
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();
2023-08-03 00:29:12 +03:00
config(['firewall.middleware.too_many_emails_sent.enabled' => true]);
2023-05-03 00:14:25 +03:00
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(),
]);
}
}