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); });