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' => 'search', 'status' => 'done', 'region_code' => 16, 'params' => []]); AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'Низкая', 'dedup_key' => 'low', 'box' => 'proposal', 'relevance_pct' => 40]); AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'Высокая', 'dedup_key' => 'high', 'box' => 'proposal', 'relevance_pct' => 95]); // в поле — не предложение, в группы не попадает AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'В поле', 'dedup_key' => 'fld', 'box' => 'field', 'relevance_pct' => 100]); $groups = $this->actingAs($user)->getJson('/api/autopodbor/proposals') ->assertOk() ->json('groups'); expect($groups['new'])->toHaveCount(2) ->and($groups['new'][0]['name'])->toBe('Высокая') // сорт по похожести ->and($groups['new'][1]['name'])->toBe('Низкая') ->and($groups['actualize'])->toBe([]) ->and($groups['archived'])->toBe([]); }); it('GET /api/autopodbor/proposals — чужой тенант своих не видит (группы пусты)', function () { $tenant = Tenant::factory()->create(); DB::statement('SET app.current_tenant_id = '.$tenant->id); $run = AutopodborRun::create(['tenant_id' => $tenant->id, 'kind' => 'search', 'status' => 'done', 'region_code' => 16, 'params' => []]); AutopodborCompetitor::create(['tenant_id' => $tenant->id, 'search_run_id' => $run->id, 'name' => 'Чужой', 'dedup_key' => 'a', 'box' => 'proposal']); $other = User::factory()->create(['tenant_id' => Tenant::factory()->create()->id]); $groups = $this->actingAs($other)->getJson('/api/autopodbor/proposals')->assertOk()->json('groups'); expect($groups['new'])->toBe([]) ->and($groups['actualize'])->toBe([]) ->and($groups['archived'])->toBe([]); });