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, 'name' => 'Окна', 'dedup_key' => 'okna']); $project = Project::factory()->create(['tenant_id' => $tenant->id, 'is_active' => true, 'preflight_blocked_at' => null]); // источник в работе с активным проектом AutopodborSource::create([ 'tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id, 'signal_type' => 'call', 'identifier' => '78432001122', 'phone_kind' => 'real', 'phone_type' => 'city', 'dedup_key' => 'call:78432001122', 'box' => 'field', 'created_project_id' => $project->id, ]); // источник-предложение без проекта AutopodborSource::create([ 'tenant_id' => $tenant->id, 'competitor_id' => $comp->id, 'study_run_id' => $run->id, 'signal_type' => 'site', 'identifier' => 'okna.ru', 'dedup_key' => 'site:okna.ru', 'box' => 'proposal', ]); $resp = $this->actingAs($user)->getJson("/api/autopodbor/competitors/{$comp->id}") ->assertOk() ->assertJsonStructure(['data' => ['id', 'name'], 'sources' => [['id', 'box', 'phone_type', 'project']]]); $byId = collect($resp->json('sources'))->keyBy('identifier'); expect($byId['78432001122']['box'])->toBe('field') ->and($byId['78432001122']['phone_type'])->toBe('city') ->and($byId['78432001122']['project'])->not->toBeNull() ->and($byId['78432001122']['project']['is_active'])->toBeTrue() ->and($byId['okna.ru']['box'])->toBe('proposal') ->and($byId['okna.ru']['project'])->toBeNull(); });