feat(api): add service database management endpoints

Add service database CRUD, logs, and lifecycle actions, and document service application operations with OpenAPI tests.
This commit is contained in:
Andras Bacsai committed 2026-07-15 12:29:58 +02:00
1 parent 64667574f6
commit 908b5cc09d
13 files changed
+870 -3

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
<?php
use App\Models\Application;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
it('documents application settings under the settings property', function () {
$schema = (new ReflectionClass(Application::class))
->getAttributes(Schema::class)[0]
->newInstance();
$openApi = json_decode(
file_get_contents(__DIR__.'/../../openapi.json'),
true,
flags: JSON_THROW_ON_ERROR,
);
$settingsProperty = collect($schema->properties)
->first(fn (mixed $property): bool => $property instanceof Property
&& $property->property === 'settings');
expect($settingsProperty)
->not->toBeNull()
->and($openApi['components']['schemas']['Application']['properties'])
->toHaveKey('settings')
->not->toHaveKey('');
});
@@ -0,0 +1,32 @@
<?php
it('documents both supported methods for service application actions', function () {
$openApi = json_decode(
file_get_contents(__DIR__.'/../../openapi.json'),
true,
flags: JSON_THROW_ON_ERROR,
);
$actionPaths = [
'/services/{uuid}/applications/{app_uuid}/logs',
'/services/{uuid}/applications/{app_uuid}/start',
'/services/{uuid}/applications/{app_uuid}/restart',
'/services/{uuid}/applications/{app_uuid}/stop',
];
foreach ($actionPaths as $path) {
expect($openApi['paths'][$path])
->toHaveKeys(['get', 'post'])
->and($openApi['paths'][$path]['post']['responses'])
->toHaveKeys(['200', '400', '401', '404', '501']);
}
expect($openApi['paths'][$actionPaths[0]]['post']['responses']['200']['content']['application/json']['schema']['properties'])
->toHaveKey('logs')
->and($openApi['paths'][$actionPaths[1]]['post']['responses']['200']['content']['application/json']['schema']['properties'])
->toHaveKey('message')
->and($openApi['paths'][$actionPaths[2]]['post']['responses']['200']['content']['application/json']['schema']['properties'])
->toHaveKey('message')
->and($openApi['paths'][$actionPaths[3]]['post']['responses']['200']['content']['application/json']['schema']['properties'])
->toHaveKey('message');
});
@@ -0,0 +1,29 @@
<?php
it('documents service database management endpoints', function () {
$openApi = json_decode(
file_get_contents(__DIR__.'/../../openapi.json'),
true,
flags: JSON_THROW_ON_ERROR,
);
expect($openApi['paths'])
->toHaveKey('/services/{uuid}/databases')
->toHaveKey('/services/{uuid}/databases/{database_uuid}')
->toHaveKey('/services/{uuid}/databases/{database_uuid}/logs')
->toHaveKey('/services/{uuid}/databases/{database_uuid}/start')
->toHaveKey('/services/{uuid}/databases/{database_uuid}/restart')
->toHaveKey('/services/{uuid}/databases/{database_uuid}/stop')
->and($openApi['paths']['/services/{uuid}/databases']['get'])
->toBeArray()
->and($openApi['paths']['/services/{uuid}/databases/{database_uuid}'])
->toHaveKeys(['get', 'patch'])
->and($openApi['paths']['/services/{uuid}/databases/{database_uuid}/logs']['get'])
->toBeArray()
->and($openApi['paths']['/services/{uuid}/databases/{database_uuid}/start']['post'])
->toBeArray()
->and($openApi['paths']['/services/{uuid}/databases/{database_uuid}/restart']['post'])
->toBeArray()
->and($openApi['paths']['/services/{uuid}/databases/{database_uuid}/stop']['post'])
->toBeArray();
});
+28
View File
@@ -0,0 +1,28 @@
<?php
use App\Http\Controllers\Api\ServicesController;
use OpenApi\Attributes\Patch;
it('only documents fields supported by the update service endpoint', function () {
$method = new ReflectionMethod(ServicesController::class, 'update_by_uuid');
$patch = $method->getAttributes(Patch::class)[0]->newInstance();
$documentedProperties = $patch->requestBody->content[0]->schema->properties;
$openApi = json_decode(
file_get_contents(__DIR__.'/../../openapi.json'),
true,
flags: JSON_THROW_ON_ERROR,
);
$generatedProperties = $openApi['paths']['/services/{uuid}']['patch']['requestBody']['content']['application/json']['schema']['properties'];
$unsupportedFields = [
'project_uuid',
'environment_name',
'environment_uuid',
'server_uuid',
'destination_uuid',
];
expect(array_keys($generatedProperties))->toBe(array_keys($documentedProperties))
->and(array_intersect($unsupportedFields, array_keys($documentedProperties)))->toBeEmpty();
});