62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
it('logout writes auth_log event=logout', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'email' => 'logout-log@example.ru',
|
|
'password_hash' => Hash::make('secret-pass-123'),
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$this->postJson('/api/auth/login', [
|
|
'email' => 'logout-log@example.ru',
|
|
'password' => 'secret-pass-123',
|
|
])->assertOk();
|
|
|
|
$this->postJson('/api/auth/logout')->assertOk();
|
|
|
|
$row = DB::table('auth_log')
|
|
->where('event', 'logout')
|
|
->where('user_id', $user->id)
|
|
->latest('id')
|
|
->first();
|
|
|
|
expect($row)->not->toBeNull()
|
|
->and((int) $row->tenant_id)->toBe($tenant->id);
|
|
});
|
|
|
|
it('register writes auth_log event=register_success', function () {
|
|
Tenant::factory()->create();
|
|
|
|
$response = $this->postJson('/api/auth/register', [
|
|
'email' => 'reg-log-test@example.ru',
|
|
'password' => 'fresh-pass-123',
|
|
'accept_offer' => true,
|
|
'accept_pdn' => true,
|
|
]);
|
|
|
|
$response->assertStatus(201);
|
|
|
|
$user = User::where('email', 'reg-log-test@example.ru')->first();
|
|
|
|
$row = DB::table('auth_log')
|
|
->where('event', 'register_success')
|
|
->where('user_id', $user->id)
|
|
->latest('id')
|
|
->first();
|
|
|
|
expect($row)->not->toBeNull()
|
|
->and($row->email)->toBe('reg-log-test@example.ru');
|
|
});
|