fix: central company view page 404 + broken stats query

The /admin/companies/{id} view page (ViewCompany extends Page) 404'd because
the {record} route param could arrive as a JSON-encoded model (Livewire typed-
property hydration), so findOrFail() received a non-id and threw
ModelNotFoundException. Added resolveRecordKey() to normalize scalar id / model
/ JSON-string down to the integer key.

Also fixed getStats() referencing non-existent parts columns `stock` /
`low_stock_threshold` (real columns are `qty` / `min_qty`), which would 500 the
page once mount resolved.

Added CentralCompanyViewTest as regression (asserts 200 + company name). Full
suite: 100 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-28 10:24:08 +00:00
parent d6a0bfb890
commit ac7d5b4733
2 changed files with 60 additions and 3 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace Tests\Feature;
use App\Models\Central\Company;
use App\Models\Central\Plan;
use App\Models\Central\SuperAdmin;
use App\Tenancy\TenantManager;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CentralCompanyViewTest extends TestCase
{
use RefreshDatabase;
public function test_company_view_page_loads_for_existing_record(): void
{
$plan = Plan::create(['name' => 'Free', 'slug' => 'free', 'price' => 0, 'features' => []]);
$company = Company::create([
'plan_id' => $plan->id, 'slug' => 'viewco', 'name' => 'View Co',
'status' => 'active',
]);
$admin = SuperAdmin::create([
'name' => 'Op', 'email' => 'op@example.com',
'password' => bcrypt('secret'), 'is_active' => true, 'role' => 'owner',
]);
app(TenantManager::class)->setCurrent(null);
$response = $this->actingAs($admin, 'central')
->get("http://service.mir.md/admin/companies/{$company->id}");
$response->assertStatus(200);
$response->assertSee('View Co');
}
}