Files
portal/app/tests/Feature/Autopodbor/AutopodborModelsTest.php
T
Дмитрий df19af99f9 feat(автоподбор): Eloquent-модели run/competitor/source
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 13:12:35 +03:00

46 lines
1.4 KiB
PHP

<?php
use App\Models\AutopodborRun;
use App\Models\AutopodborCompetitor;
use App\Models\AutopodborSource;
use App\Models\Tenant;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
uses(DatabaseTransactions::class, \Tests\Concerns\SharesSupplierPdo::class);
it('связывает run → competitors → sources', function () {
$tenant = Tenant::factory()->create();
DB::statement("SET LOCAL app.current_tenant_id = " . $tenant->id);
$run = AutopodborRun::create([
'tenant_id' => $tenant->id,
'kind' => 'search',
'status' => 'done',
'region_code' => 16,
'params' => [],
]);
$comp = AutopodborCompetitor::create([
'tenant_id' => $tenant->id,
'search_run_id' => $run->id,
'name' => 'Окна Комфорт',
'dedup_key' => 'okna-komfort',
'relevance_pct' => 100,
]);
$src = AutopodborSource::create([
'tenant_id' => $tenant->id,
'competitor_id' => $comp->id,
'study_run_id' => $run->id,
'signal_type' => 'site',
'identifier' => 'okna-komfort.ru',
'dedup_key' => 'site:okna-komfort.ru',
]);
expect($comp->sources()->count())->toBe(1)
->and($comp->searchRun->id)->toBe($run->id)
->and($src->competitor->id)->toBe($comp->id)
->and($run->competitors()->count())->toBe(1);
});