Files
api/services/nginx/app/tests/Unit/Selfserve/EdgeGatewayModuleRouteWiringTest.php
T

46 lines
2.6 KiB
PHP

<?php
it('registers module-scoped edge gateway operator routes', function (): void {
$route = file_get_contents(app_path('modules/edgegateway/routes/moduleEdgeGatewayRoute.php'));
expect($route)->not->toBeFalse();
expect($route)->toContain("'/modules/edge-gateways'");
expect($route)->toContain("'/modules/edge-gateways/workspace/departments'");
expect($route)->toContain("'/modules/edge-gateways/workspace/departments/{id}'");
expect($route)->toContain("'/modules/edge-gateways/{id}'");
expect($route)->toContain("'/modules/edge-gateways/install-token'");
expect($route)->toContain("'/modules/edge-gateways/install-token/{id}/status'");
expect($route)->toContain("'/modules/edge-gateways/{id}/discovery'");
expect($route)->toContain("'/modules/edge-gateways/{id}/bindings'");
expect($route)->toContain("'/modules/edge-gateways/{id}/operations'");
expect($route)->toContain("'/modules/edge-gateways/{id}/operations/{operationId}/cancel'");
expect($route)->toContain("'/modules/edge-gateways/{id}/operations/{operationId}/events'");
expect($route)->toContain("'/modules/edge-gateways/{id}/rotate-credentials'");
expect($route)->toContain("'/modules/edge-gateways/departments/{id}/cutover'");
expect($route)->toContain('requireModuleEnabled()');
expect($route)->not->toContain("'/modules/edge-gateways/{id}/shell-sessions'");
});
it('registers edge gateway config endpoints from the module route directory', function (): void {
$route = file_get_contents(app_path('modules/edgegateway/routes/edgeGatewayConfigRoute.php'));
$legacyRoute = file_get_contents(app_path('routes/moduleConfigRoute.php'));
expect($route)->not->toBeFalse();
expect($route)->toContain("'/edgegateway/config'");
expect($route)->toContain('new edgegateway()');
expect($legacyRoute)->not->toContain("'/edgegateway/config'");
});
it('keeps only the module facade in the global classes directory and conditionally loads module routes', function (): void {
$classes = glob(app_path('classes/*.php')) ?: [];
$edgeGatewayClasses = array_values(array_filter($classes, static function (string $path): bool {
$name = basename($path);
return str_contains($name, 'edgegateway') || str_contains($name, 'edge_gateway');
}));
$index = file_get_contents(app_path('index.php'));
expect($edgeGatewayClasses)->toEqual([app_path('classes/edgegateway.php')]);
expect($index)->toContain("\$routes_path = \$modules_path . DIRECTORY_SEPARATOR . \$module_dir . DIRECTORY_SEPARATOR . 'routes'");
expect($index)->toContain("method_exists(\$module, 'isEnabled') && !\$module->isEnabled()");
});