add tests batch 20

This commit is contained in:
root
2026-06-09 01:03:53 -04:00
parent 95efb9652e
commit 6be4875c5e
1502 changed files with 13797 additions and 11313 deletions
@@ -22,9 +22,9 @@ use Tests\TestCase;
*/
class ApiFullSurfaceEndToEndContractTest extends TestCase
{
use AssertsE2EApiResponses;
use RefreshDatabase;
use SeedsE2ETestFixtures;
use AssertsE2EApiResponses;
/**
* @var array<string, int|string>
@@ -32,11 +32,8 @@ class ApiFullSurfaceEndToEndContractTest extends TestCase
private array $ids = [];
private User $admin;
private User $teacher;
private User $parent;
private User $studentUser;
protected function setUp(): void
@@ -98,7 +95,7 @@ class ApiFullSurfaceEndToEndContractTest extends TestCase
foreach ($this->probeableApiRoutes() as $route) {
$method = $this->primaryMethod($route);
$uri = '/'.$this->materializeUri($route->uri());
$uri = '/' . $this->materializeUri($route->uri());
$actor = $this->actorFor($route->uri());
$payload = $this->payloadFor($method, $route->uri());
@@ -107,17 +104,16 @@ class ApiFullSurfaceEndToEndContractTest extends TestCase
$status = $response->getStatusCode();
if ($status >= 500) {
$failures[] = "$method $uri crashed with $status: ".$response->getContent();
$failures[] = "$method $uri crashed with $status: " . $response->getContent();
continue;
}
if (! in_array($status, $this->allowedContractStatuses($method), true)) {
$failures[] = "$method $uri returned unexpected $status: ".$response->getContent();
$failures[] = "$method $uri returned unexpected $status: " . $response->getContent();
}
}
$this->assertSame([], $failures, "Full-surface API contract failures:\n".implode("\n", $failures));
$this->assertSame([], $failures, "Full-surface API contract failures:\n" . implode("\n", $failures));
}
public function test_all_mutating_api_routes_reject_empty_or_malformed_payloads_without_server_errors(): void
@@ -130,17 +126,17 @@ class ApiFullSurfaceEndToEndContractTest extends TestCase
continue;
}
$uri = '/'.$this->materializeUri($route->uri());
$uri = '/' . $this->materializeUri($route->uri());
$this->actingAs($this->actorFor($route->uri()), 'api');
$response = $this->json($method, $uri, []);
$status = $response->getStatusCode();
if ($status >= 500) {
$failures[] = "$method $uri malformed payload crashed with $status: ".$response->getContent();
$failures[] = "$method $uri malformed payload crashed with $status: " . $response->getContent();
}
}
$this->assertSame([], $failures, "Malformed-payload probes must fail cleanly, not explode:\n".implode("\n", $failures));
$this->assertSame([], $failures, "Malformed-payload probes must fail cleanly, not explode:\n" . implode("\n", $failures));
}
public function test_portal_routes_enforce_wrong_actor_boundaries_across_the_full_surface(): void
@@ -153,11 +149,11 @@ class ApiFullSurfaceEndToEndContractTest extends TestCase
$status = $response->getStatusCode();
if (! in_array($status, [401, 403, 404, 405, 419, 422], true)) {
$failures[] = "$method $uri allowed wrong actor with $status: ".$response->getContent();
$failures[] = "$method $uri allowed wrong actor with $status: " . $response->getContent();
}
}
$this->assertSame([], $failures, "Wrong-role portal boundary failures:\n".implode("\n", $failures));
$this->assertSame([], $failures, "Wrong-role portal boundary failures:\n" . implode("\n", $failures));
}
/**
@@ -233,14 +229,13 @@ class ApiFullSurfaceEndToEndContractTest extends TestCase
{
return preg_replace_callback('/\{([^}:]+)(?:\?)?[^}]*\}/', function (array $matches): string {
$key = $matches[1];
return (string) ($this->ids[$key] ?? $this->ids['id']);
}, $uri) ?? $uri;
}
private function materializePath(string $path): string
{
return '/'.ltrim($this->materializeUri(ltrim($path, '/')), '/');
return '/' . ltrim($this->materializeUri(ltrim($path, '/')), '/');
}
/**
@@ -314,7 +309,7 @@ class ApiFullSurfaceEndToEndContractTest extends TestCase
if (str_contains($uri, 'inventory') || str_contains($uri, 'suppliers') || str_contains($uri, 'supply')) {
return $base + [
'name' => 'Contract Probe Item',
'sku' => 'E2E-'.uniqid(),
'sku' => 'E2E-' . uniqid(),
'quantity' => 3,
'unit_cost' => 5.25,
];