Files
coolify/tests/Unit/DatabaseImportOpenApiTest.php
T
Andras Bacsai 9e7cb60b0d feat: add import restore options, OAuth confirmation, and fixes
- database import: add keep_owners (restore PostgreSQL owners and
  privileges) and sqlite_database (pick the target SQLite file) to the
  API, OpenAPI spec, and import form
- oauth: require password confirmation and support team selection on
  OAuth login
- remote process: send team broadcast events to the team of the server
  that ran the process instead of the causer's user id
- servers API: handle the legacy build server setting
- compose: support parent bind paths and volume driver options
- dns: improve record hints and provider management
- notifications: fix throttling and missing backup notifications
- ui: rework the confirmation modal
- add feature and unit tests for the new behavior
2026-09-30 13:35:22 +02:00

101 lines
4.7 KiB
PHP

<?php
test('documents standalone and service database import endpoints', function () {
$document = json_decode((string) file_get_contents(__DIR__.'/../../openapi.json'), true, flags: JSON_THROW_ON_ERROR);
expect($document['paths'])
->toHaveKey('/databases/{uuid}/imports/uploads')
->toHaveKey('/databases/{uuid}/imports')
->toHaveKey('/databases/{uuid}/imports/{activity_id}')
->toHaveKey('/services/{uuid}/databases/{database_uuid}/imports/uploads')
->toHaveKey('/services/{uuid}/databases/{database_uuid}/imports')
->toHaveKey('/services/{uuid}/databases/{database_uuid}/imports/{activity_id}');
foreach ($document['components']['schemas']['DatabaseImportRequest']['oneOf'] as $source) {
expect($source['properties']['replace_existing'])
->toMatchArray(['type' => 'boolean', 'default' => false]);
}
$statusRef = [
'description' => 'Import status',
'content' => [
'application/json' => [
'schema' => [
'$ref' => '#/components/schemas/DatabaseImportStatus',
],
],
],
];
expect($document['paths']['/databases/{uuid}/imports/{activity_id}']['get']['responses']['200'])
->toMatchArray($statusRef)
->and($document['paths']['/services/{uuid}/databases/{database_uuid}/imports/{activity_id}']['get']['responses']['200'])
->toMatchArray($statusRef)
->and($document['components']['schemas'])
->toHaveKey('DatabaseImportStatus');
});
test('documents path parameters for database import endpoints', function () {
$document = json_decode((string) file_get_contents(__DIR__.'/../../openapi.json'), true, flags: JSON_THROW_ON_ERROR);
$operations = [
['/databases/{uuid}/imports/uploads', 'post', ['uuid']],
['/databases/{uuid}/imports', 'post', ['uuid']],
['/databases/{uuid}/imports/{activity_id}', 'get', ['uuid', 'activity_id']],
['/services/{uuid}/databases/{database_uuid}/imports/uploads', 'post', ['uuid', 'database_uuid']],
['/services/{uuid}/databases/{database_uuid}/imports', 'post', ['uuid', 'database_uuid']],
['/services/{uuid}/databases/{database_uuid}/imports/{activity_id}', 'get', ['uuid', 'database_uuid', 'activity_id']],
];
foreach ($operations as [$path, $method, $expectedNames]) {
$parameters = $document['paths'][$path][$method]['parameters'] ?? [];
$pathParameters = collect($parameters)
->filter(fn (array $parameter): bool => ($parameter['in'] ?? null) === 'path')
->map(fn (array $parameter): string => $parameter['name'])
->values()
->all();
expect($pathParameters)->toEqual($expectedNames);
}
});
test('constrains additional properties on each database import source branch', function () {
$document = json_decode((string) file_get_contents(__DIR__.'/../../openapi.json'), true, flags: JSON_THROW_ON_ERROR);
$schema = $document['components']['schemas']['DatabaseImportRequest'];
expect($schema)->not->toHaveKey('additionalProperties');
$expectedProperties = [
['source', 'upload_id', 'dump_all', 'replace_existing', 'keep_owners', 'sqlite_database'],
['source', 's3_storage_uuid', 'path', 'dump_all', 'replace_existing', 'keep_owners', 'sqlite_database'],
['source', 'path', 'dump_all', 'replace_existing', 'keep_owners', 'sqlite_database'],
];
expect($schema['oneOf'])->toHaveCount(count($expectedProperties));
foreach ($schema['oneOf'] as $index => $source) {
expect($source['additionalProperties'])->toBeFalse()
->and($source['properties'])->toHaveKeys($expectedProperties[$index])
->and($source['properties']['replace_existing'])
->toMatchArray(['type' => 'boolean', 'default' => false])
->and($source['properties']['keep_owners'])
->toMatchArray(['type' => 'boolean', 'default' => false])
->and($source['properties']['sqlite_database'])
->toMatchArray(['type' => 'string']);
}
});
test('documents the 409 response of database start, restart, and import endpoints', function () {
$document = json_decode((string) file_get_contents(__DIR__.'/../../openapi.json'), true, flags: JSON_THROW_ON_ERROR);
$inProgress = 'Another start, restart or import of this database is already in progress.';
foreach ([
['/databases/{uuid}/start', 'post'],
['/databases/{uuid}/restart', 'post'],
['/databases/{uuid}/imports', 'post'],
['/services/{uuid}/databases/{database_uuid}/imports', 'post'],
] as [$path, $method]) {
expect($document['paths'][$path][$method]['responses']['409']['description'] ?? null)->toBe($inProgress);
}
});