Files
portal/app/tests/Feature/Support/SupportRequestControllerTest.php
T
Дмитрий 88ace4e3d9
Accessibility (Pa11y live) / a11y (push) Has been cancelled
test: дозакрытие оздоровления — protekateli pd-аудита, видимость supplier, новый флоу регистрации
Снижение остатка 19 to 5. Всё тест-сторона:
- PdErasureServiceTest + AdminPdSubjectRequestsControllerTest: SharesSupplierPdo —
  перестали коммитить pd_processing_log через pgsql_supplier, что ломало
  глобальный audit:verify-chains (6 падений) и амплифицировало PhoneRegionSmoke.
- ReportFileDeletePdLogTest: SharesSupplierPdo — cron reports:cleanup-expired
  теперь видит незакоммиченные job'ы теста.
- AdminSuppliersControllerTest: устойчивый ассерт (с фазы 3 в suppliers есть direct).
- AuthLogCoverageTest/AuthFlowIntegrationTest: новый флоу самозаписи G1/SP1 —
  register_success пишется после confirm-email; добавлен шаг подтверждения.
- ImpersonationTest end: verify (G7-B) ставит маркер impersonation → admin-зона
  закрыта by design; помечаем токен used напрямую вместо session-takeover.
- CleanupInactiveSupplierProjectsJobTest: phase A читает pivot project_supplier_links —
  добавлена привязка linkProjectToSupplier (раньше был только legacy FK).
- Pint-нормализация uses() FQN to import в ранее тронутых файлах.

Остаток 5 (НЕ слепой патч): webhook B-префикс ×2 (решение владельца), advisory-lock
audit-цепочки (возможный дрейф схемы, флажок), SupplierConnection WARN#2 (cap-3,
поведенческое), SupplierPortalClientTest (пре-существующий, не от этих правок).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 08:19:53 +03:00

61 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
use App\Mail\SupportRequestMail;
use App\Models\SupportRequest;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Mail;
uses(DatabaseTransactions::class);
use function Pest\Laravel\actingAs;
use function Pest\Laravel\postJson;
beforeEach(function () {
$this->tenant = Tenant::factory()->create();
$this->user = User::factory()->create(['tenant_id' => $this->tenant->id]);
});
it('создаёт заявку в БД и ставит письмо в очередь', function () {
Mail::fake();
actingAs($this->user);
postJson('/api/support-requests', [
'name' => 'Иван',
'contact' => '+79991234567',
'message' => 'Не приходят лиды.',
])->assertCreated()->assertJson(['ok' => true]);
$row = SupportRequest::query()->where('tenant_id', $this->tenant->id)->first();
expect($row)->not->toBeNull()
->and($row->user_id)->toBe($this->user->id)
->and($row->name)->toBe('Иван')
->and($row->contact)->toBe('+79991234567')
->and($row->message)->toBe('Не приходят лиды.');
Mail::assertQueued(SupportRequestMail::class, fn (SupportRequestMail $m) => $m->hasTo(config('services.support.email')));
});
it('валидирует обязательные поля (422)', function () {
Mail::fake();
actingAs($this->user);
postJson('/api/support-requests', ['name' => '', 'contact' => '', 'message' => ''])
->assertStatus(422)
->assertJsonValidationErrors(['name', 'contact', 'message']);
});
it('не теряет заявку при сбое почты', function () {
Mail::shouldReceive('to')->andThrow(new RuntimeException('smtp down'));
actingAs($this->user);
postJson('/api/support-requests', [
'name' => 'Пётр', 'contact' => 'p@example.org', 'message' => 'Вопрос.',
])->assertCreated();
expect(SupportRequest::query()->where('tenant_id', $this->tenant->id)->count())->toBe(1);
});