Files
portal/app/tests/Feature/Autopodbor/AutopodborBoxStateTest.php
T

66 lines
2.3 KiB
PHP
Raw Normal View History

<?php
use App\Models\AutopodborCompetitor;
use App\Models\AutopodborRun;
use App\Models\AutopodborSource;
use App\Models\Tenant;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\SharesSupplierPdo;
uses(DatabaseTransactions::class, SharesSupplierPdo::class);
function bsTenantRun(): array
{
$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' => [],
]);
return [$tenant, $run];
}
it('конкурент по умолчанию в ящике «предложение» и переводится в «поле»', function () {
[$tenant, $run] = bsTenantRun();
$comp = AutopodborCompetitor::create([
'tenant_id' => $tenant->id, 'search_run_id' => $run->id,
'name' => 'Окна Комфорт', 'dedup_key' => 'okna-komfort',
]);
expect($comp->fresh()->box)->toBe('proposal');
$comp->update(['box' => 'field']);
expect($comp->fresh()->box)->toBe('field');
});
it('источник по умолчанию в ящике «предложение» и переводится в «поле»', function () {
[$tenant, $run] = bsTenantRun();
$comp = AutopodborCompetitor::create([
'tenant_id' => $tenant->id, 'search_run_id' => $run->id,
'name' => 'Окна Комфорт', 'dedup_key' => 'okna-komfort',
]);
$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($src->fresh()->box)->toBe('proposal');
$src->update(['box' => 'field']);
expect($src->fresh()->box)->toBe('field');
});
it('ящик конкурента не принимает чужое значение (CHECK)', function () {
[$tenant, $run] = bsTenantRun();
expect(fn () => AutopodborCompetitor::create([
'tenant_id' => $tenant->id, 'search_run_id' => $run->id,
'name' => 'X', 'dedup_key' => 'x', 'box' => 'garbage',
]))->toThrow(QueryException::class);
});