Files
portal/app/tests/Feature/Auth/LoginUnconfirmedEmailTest.php
T
Дмитрий 80de6ecbbd fix/auth: косяк 05 — неподтверждённая почта зовёт подтвердить, а не «заблокирован»
При входе с email_verified_at=null (новый клиент не ввёл код из письма)
AuthController возвращает дружелюбное «Подтвердите почту — мы отправили код
на ...» с флагом email_not_confirmed, а не пугающее «Аккаунт заблокирован».
Реальная блокировка админом (verified + is_active=false) по-прежнему даёт
«Аккаунт заблокирован». Фронт по флагу уводит на /confirm-email с переносом
email в store (там кнопка «Отправить код повторно»).
TDD: Pest 2 кейса (неподтверждённый vs заблокирован), vitest redirect-кейс,
все GREEN. Проверено глазами на 8000.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 16:15:06 +03:00

54 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Hash;
uses(DatabaseTransactions::class);
beforeEach(function () {
$this->tenant = Tenant::factory()->create();
});
test('косяк 05: вход с неподтверждённой почтой зовёт подтвердить, а не «заблокирован»', function () {
User::factory()->create([
'tenant_id' => $this->tenant->id,
'email' => 'unconfirmed@example.ru',
'password_hash' => Hash::make('right-pass-123'),
'is_active' => false,
'email_verified_at' => null,
]);
$response = $this->postJson('/api/auth/login', [
'email' => 'unconfirmed@example.ru',
'password' => 'right-pass-123',
]);
$response->assertStatus(422);
$response->assertJsonPath('email_not_confirmed', true);
expect($response->json('errors.email.0'))->toContain('одтвердите почту')
->and($response->json('errors.email.0'))->not->toContain('аблокирован');
});
test('косяк 05: подтверждённая почта но is_active=false остаётся «Аккаунт заблокирован»', function () {
User::factory()->create([
'tenant_id' => $this->tenant->id,
'email' => 'really-blocked@example.ru',
'password_hash' => Hash::make('right-pass-123'),
'is_active' => false,
'email_verified_at' => now(),
]);
$response = $this->postJson('/api/auth/login', [
'email' => 'really-blocked@example.ru',
'password' => 'right-pass-123',
]);
$response->assertStatus(422);
$response->assertJsonPath('errors.email.0', 'Аккаунт заблокирован.');
expect($response->json('email_not_confirmed'))->toBeNull();
});