Files
coolify/tests/Unit/ServiceApplicationPrerequisitesTest.php
Andras BacsaiandClaude Opus 5.5 d3ef4d1c57 fix(service): route the rybbit /api path to the backend
The Rybbit template had a proxy route only for the client, so the
/api requests of the browser got a 404 from the client and sign-up
and login failed. The backend now declares SERVICE_URL_RYBBIT_3001=/api
on the same host and keeps the /api prefix. The backend is listed
before the client, so SERVICE_URL_RYBBIT (used in BASE_URL) stays the
root URL.

Closes #9055

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:19:27 +01:00

172 lines
5.3 KiB
PHP

<?php
use App\Models\Service;
use Illuminate\Support\Facades\Log;
beforeEach(function () {
Log::shouldReceive('error')->andReturn(null);
});
it('applies beszel gzip prerequisite correctly', function () {
// Create a simple object to track the property change
$application = new class
{
public $is_gzip_enabled = true;
public function save() {}
};
$query = Mockery::mock();
$query->shouldReceive('whereName')
->with('beszel')
->once()
->andReturnSelf();
$query->shouldReceive('first')
->once()
->andReturn($application);
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'beszel-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldReceive('applications')
->once()
->andReturn($query);
applyServiceApplicationPrerequisites($service);
expect($application->is_gzip_enabled)->toBeFalse();
});
it('applies appwrite stripprefix prerequisite correctly', function () {
$applications = [];
foreach (['appwrite', 'appwrite-console', 'appwrite-realtime'] as $name) {
$app = new class
{
public $is_stripprefix_enabled = true;
public function save() {}
};
$applications[$name] = $app;
}
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'appwrite-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldReceive('applications')->times(3)->andReturnUsing(function () use (&$applications) {
static $callCount = 0;
$names = ['appwrite', 'appwrite-console', 'appwrite-realtime'];
$currentName = $names[$callCount++];
$query = Mockery::mock();
$query->shouldReceive('whereName')
->with($currentName)
->once()
->andReturnSelf();
$query->shouldReceive('first')
->once()
->andReturn($applications[$currentName]);
return $query;
});
applyServiceApplicationPrerequisites($service);
foreach ($applications as $app) {
expect($app->is_stripprefix_enabled)->toBeFalse();
}
});
it('keeps the /api prefix for the rybbit backend', function () {
$application = new class
{
public $is_stripprefix_enabled = true;
public function save() {}
};
$query = Mockery::mock();
$query->shouldReceive('whereName')->with('rybbit_backend')->once()->andReturnSelf();
$query->shouldReceive('first')->once()->andReturn($application);
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'rybbit-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3';
$service->id = 1;
$service->shouldReceive('applications')->once()->andReturn($query);
applyServiceApplicationPrerequisites($service);
expect($application->is_stripprefix_enabled)->toBeFalse();
});
it('handles missing applications gracefully', function () {
$query = Mockery::mock();
$query->shouldReceive('whereName')
->with('beszel')
->once()
->andReturnSelf();
$query->shouldReceive('first')
->once()
->andReturn(null);
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'beszel-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldReceive('applications')
->once()
->andReturn($query);
// Should not throw exception
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});
it('skips services without prerequisites', function () {
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'unknown-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldNotReceive('applications');
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});
it('correctly parses service name with single hyphen', function () {
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'docker-registry-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldNotReceive('applications');
// Should not throw exception - validates that 'docker-registry' is correctly parsed
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});
it('correctly parses service name with multiple hyphens', function () {
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'elasticsearch-with-kibana-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldNotReceive('applications');
// Should not throw exception - validates that 'elasticsearch-with-kibana' is correctly parsed
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});
it('correctly parses service name with hyphens in template name', function () {
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'apprise-api-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldNotReceive('applications');
// Should not throw exception - validates that 'apprise-api' is correctly parsed
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});