Files
portal/app/tests/Feature/Import/ImportSchemaTest.php
T
Дмитрий 70f8b210f4 feat(import): H1+H2 — схема import_unknown_statuses + enrichment import_log
Sprint 4 Task 1 (schema delta §6):
- H1: новая таблица import_unknown_statuses (RLS tenant_isolation,
  UNIQUE(tenant_id,status_ru), FK→tenants/import_log/lead_statuses/users)
- H2: +5 колонок import_log (entity_type, source_system, mapping_config,
  unknown_statuses_count, dry_run)
- schema.sql v8.20→v8.21 (64 таблицы / 118 индексов / 40 RLS-политик)
- db/CHANGELOG_schema.md v8.21 entry
- db/02_grants.sql v8.21 section (crm_app_user/crm_app_admin/crm_readonly)
- migrate: hasTable/hasColumn guards (fresh-safe)
- tests: 3 Pest-теста (ImportSchemaTest) + SchemaDeltaTest v8.21 metrics
- ide-helper: _ide_helper.php + _ide_helper_models.php (были отсутствуют
  в worktree, phpstan падал молча из-за missing scanFiles entry)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 17:01:51 +03:00

37 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
test('import_log имеет 5 новых колонок enrichment', function (): void {
foreach (['entity_type', 'source_system', 'mapping_config', 'unknown_statuses_count', 'dry_run'] as $column) {
expect(Schema::hasColumn('import_log', $column))->toBeTrue("import_log.$column отсутствует");
}
});
test('import_unknown_statuses существует с RLS', function (): void {
expect(Schema::hasTable('import_unknown_statuses'))->toBeTrue();
$rls = DB::selectOne(
"SELECT relrowsecurity FROM pg_class WHERE relname = 'import_unknown_statuses'"
);
expect($rls)->not->toBeNull('pg_class row for import_unknown_statuses не найден');
/** @var object{relrowsecurity: bool} $rls */
expect($rls->relrowsecurity)->toBeTrue('RLS не включён на import_unknown_statuses');
$policy = DB::selectOne(
"SELECT 1 AS ok FROM pg_policies WHERE tablename = 'import_unknown_statuses' AND policyname = 'tenant_isolation'"
);
expect($policy)->not->toBeNull('Политика tenant_isolation отсутствует');
});
test('import_unknown_statuses имеет UNIQUE (tenant_id, status_ru)', function (): void {
$unique = DB::selectOne(
"SELECT 1 AS ok FROM pg_constraint
WHERE conrelid = 'import_unknown_statuses'::regclass AND contype = 'u'"
);
expect($unique)->not->toBeNull('UNIQUE-ограничение отсутствует');
});