getJson('/api/dashboard/summary')->assertStatus(401); }); test('GET /api/managers без авторизации возвращает 401', function () { $this->getJson('/api/managers')->assertStatus(401); }); test('GET /api/lead-statuses без авторизации возвращает 401', function () { $this->getJson('/api/lead-statuses')->assertStatus(401); }); // --- cross-tenant: tenant_id из user, параметр чужого тенанта игнорируется --- test('dashboard/summary берёт tenant из authed-user, игнорирует ?tenant_id чужого', function () { $mine = Tenant::factory()->create(['balance_rub' => '111.00', 'balance_leads' => 11]); $other = Tenant::factory()->create(['balance_rub' => '999.00', 'balance_leads' => 99]); $this->actingAs(User::factory()->for($mine)->create()); $this->getJson("/api/dashboard/summary?tenant_id={$other->id}") ->assertOk() ->assertJsonPath('balance.amount_rub', '111.00'); }); test('managers берёт tenant из authed-user, не отдаёт пользователей чужого тенанта', function () { $mine = Tenant::factory()->create(); $other = Tenant::factory()->create(); $me = User::factory()->for($mine)->create(['first_name' => 'Свой', 'last_name' => 'Менеджер', 'is_active' => true]); User::factory()->for($other)->create(['first_name' => 'Чужой', 'last_name' => 'Менеджер', 'is_active' => true]); $this->actingAs($me); $names = $this->getJson("/api/managers?tenant_id={$other->id}") ->assertOk() ->json('managers.*.name'); expect($names)->toContain('Свой М.'); expect($names)->not->toContain('Чужой М.'); });