Queue::fake()); it('manual-study по сайту создаёт ручного конкурента и study-прогон', function () { $tenant = Tenant::factory()->create(['balance_rub' => '100000.00']); $user = User::factory()->create(['tenant_id' => $tenant->id]); SystemSetting::updateOrCreate(['key' => 'autopodbor_price_study_rub'], ['value' => '1', 'type' => 'decimal']); $this->actingAs($user)->postJson('/api/autopodbor/manual-study', [ 'site_url' => 'https://okna-komfort-kzn.ru/contacts', 'region_code' => 16, ])->assertCreated()->assertJsonPath('data.kind', 'study'); DB::statement("SET app.current_tenant_id = ".$tenant->id); expect(AutopodborCompetitor::where('tenant_id', $tenant->id)->where('origin', 'manual')->exists())->toBeTrue(); }); it('manual-study без названия и без сайта → 422', function () { $tenant = Tenant::factory()->create(['balance_rub' => '100000.00']); $user = User::factory()->create(['tenant_id' => $tenant->id]); SystemSetting::updateOrCreate(['key' => 'autopodbor_price_study_rub'], ['value' => '1', 'type' => 'decimal']); $this->actingAs($user)->postJson('/api/autopodbor/manual-study', ['region_code' => 16]) ->assertStatus(422); }); it('sources/manual добавляет источник изученному конкуренту', function () { $tenant = Tenant::factory()->create(); $user = User::factory()->create(['tenant_id' => $tenant->id]); DB::statement("SET app.current_tenant_id = ".$tenant->id); $run = AutopodborRun::create(['tenant_id'=>$tenant->id,'kind'=>'study','status'=>'done','region_code'=>16,'params'=>[]]); $comp = AutopodborCompetitor::create(['tenant_id'=>$tenant->id,'search_run_id'=>$run->id,'study_run_id'=>$run->id,'studied_at'=>now(),'name'=>'Окна Комфорт','origin'=>'auto','dedup_key'=>'okna']); $this->actingAs($user)->postJson('/api/autopodbor/sources/manual', [ 'competitor_id' => $comp->id, 'raw' => 'okna-komfort.ru', ])->assertCreated()->assertJsonPath('data.signal_type', 'site'); expect(AutopodborSource::where('competitor_id', $comp->id)->where('identifier', 'okna-komfort.ru')->exists())->toBeTrue(); }); it('sources/manual телефоном создаёт call-источник', function () { $tenant = Tenant::factory()->create(); $user = User::factory()->create(['tenant_id' => $tenant->id]); DB::statement("SET app.current_tenant_id = ".$tenant->id); $run = AutopodborRun::create(['tenant_id'=>$tenant->id,'kind'=>'study','status'=>'done','region_code'=>16,'params'=>[]]); $comp = AutopodborCompetitor::create(['tenant_id'=>$tenant->id,'search_run_id'=>$run->id,'study_run_id'=>$run->id,'studied_at'=>now(),'name'=>'Окна','origin'=>'auto','dedup_key'=>'okna2']); $this->actingAs($user)->postJson('/api/autopodbor/sources/manual', [ 'competitor_id' => $comp->id, 'raw' => '+7 (843) 200-11-22', ])->assertCreated()->assertJsonPath('data.signal_type', 'call'); });