f208fe2f65
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
50 lines
3.1 KiB
PHP
50 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\AutopodborCompetitor;
|
|
use App\Models\AutopodborRun;
|
|
use App\Models\AutopodborSource;
|
|
use App\Models\Project;
|
|
use App\Models\Tenant;
|
|
use App\Services\Autopodbor\AutopodborProjectCreator;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
uses(DatabaseTransactions::class, \Tests\Concerns\SharesSupplierPdo::class);
|
|
|
|
it('создаёт проекты из выбранных источников с общими настройками', function () {
|
|
Queue::fake();
|
|
$tenant = Tenant::factory()->create(['balance_rub' => '500000.00']);
|
|
DB::statement("SET app.current_tenant_id = ".$tenant->id);
|
|
$run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'done', 'region_code' => 16]);
|
|
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'name' => 'Окна Комфорт', 'dedup_key' => 'okna']);
|
|
$s1 = 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']);
|
|
$s2 = AutopodborSource::create(['tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id, 'signal_type' => 'call', 'identifier' => '78432001122', 'phone_kind' => 'real', 'dedup_key' => 'call:78432001122']);
|
|
|
|
$projects = app(AutopodborProjectCreator::class)->createFromSources($tenant->id, [$s1->id, $s2->id], [
|
|
'regions' => [16], 'daily_limit_target' => 20, 'delivery_days_mask' => 127,
|
|
], launch: false);
|
|
|
|
expect($projects)->toHaveCount(2)
|
|
->and(Project::where('tenant_id', $tenant->id)->where('signal_identifier', 'okna-komfort.ru')->exists())->toBeTrue()
|
|
->and($s1->fresh()->created_project_id)->not->toBeNull();
|
|
});
|
|
|
|
it('разруливает коллизию одинаковых имён суффиксом', function () {
|
|
Queue::fake();
|
|
$tenant = Tenant::factory()->create(['balance_rub' => '500000.00']);
|
|
DB::statement("SET app.current_tenant_id = ".$tenant->id);
|
|
$run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'done', 'region_code' => 16]);
|
|
$comp = AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'name' => 'Окна Комфорт', 'dedup_key' => 'okna2']);
|
|
$s1 = AutopodborSource::create(['tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id, 'signal_type' => 'site', 'identifier' => 'a.ru', 'dedup_key' => 'site:a.ru']);
|
|
$s2 = AutopodborSource::create(['tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id, 'signal_type' => 'site', 'identifier' => 'b.ru', 'dedup_key' => 'site:b.ru']);
|
|
|
|
app(AutopodborProjectCreator::class)->createFromSources($tenant->id, [$s1->id, $s2->id], ['regions' => [16], 'daily_limit_target' => 20, 'delivery_days_mask' => 127], false);
|
|
|
|
$names = Project::where('tenant_id', $tenant->id)->pluck('name')->all();
|
|
expect($names)->toContain('Окна Комфорт')
|
|
->and(collect($names)->unique()->count())->toBe(2);
|
|
});
|