new funcionality
This commit is contained in:
45
tests/Feature/EventRegistrationTest.php
Normal file
45
tests/Feature/EventRegistrationTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Passport\Client;
|
||||
use Laravel\Passport\Events\AccessTokenCreated;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Regresión: los listeners bajo app/Listeners se auto-descubren por su
|
||||
* handle() tipado (Laravel 11+). Registrarlos TAMBIÉN a mano con
|
||||
* Event::listen() en un ServiceProvider los duplica — cada evento real
|
||||
* termina disparando el listener dos veces (visto con "php artisan
|
||||
* event:list" listando el mismo listener dos veces por evento). Pasó acá:
|
||||
* cada login_event/webhook se creaba duplicado. Este test evita que vuelva.
|
||||
*/
|
||||
class EventRegistrationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_access_token_created_records_exactly_one_login_event(): void
|
||||
{
|
||||
$user = User::factory()->approved()->create();
|
||||
$client = Client::create([
|
||||
'name' => 'Regression Test Client',
|
||||
'secret' => null,
|
||||
'provider' => null,
|
||||
'redirect_uris' => [],
|
||||
'grant_types' => ['client_credentials'],
|
||||
'revoked' => false,
|
||||
]);
|
||||
|
||||
event(new AccessTokenCreated('fake-token-id', (string) $user->id, $client->id));
|
||||
|
||||
$this->assertDatabaseCount('login_events', 1);
|
||||
$this->assertDatabaseHas('login_events', [
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'type' => 'oauth',
|
||||
'outcome' => 'success',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user