diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.php index 61bd2bd6f2..5915724f1e 100644 --- a/app/Http/Controllers/Api/ApplicationsController.php +++ b/app/Http/Controllers/Api/ApplicationsController.php @@ -2327,6 +2327,10 @@ class ApplicationsController extends Controller $application->fqdn = generateUrl(server: $server, random: $application->uuid); $application->save(); } + if (isset($isAutoDeployEnabled)) { + $application->settings->is_auto_deploy_enabled = $isAutoDeployEnabled; + $application->settings->save(); + } if (isset($isForceHttpsEnabled)) { $application->settings->is_force_https_enabled = $isForceHttpsEnabled; $application->settings->save(); @@ -2458,6 +2462,10 @@ class ApplicationsController extends Controller $application->fqdn = generateUrl(server: $server, random: $application->uuid); $application->save(); } + if (isset($isAutoDeployEnabled)) { + $application->settings->is_auto_deploy_enabled = $isAutoDeployEnabled; + $application->settings->save(); + } if (isset($isForceHttpsEnabled)) { $application->settings->is_force_https_enabled = $isForceHttpsEnabled; $application->settings->save(); diff --git a/tests/Feature/Api/ApplicationAutoDeploySettingApiTest.php b/tests/Feature/Api/ApplicationAutoDeploySettingApiTest.php new file mode 100644 index 0000000000..30a7a133b2 --- /dev/null +++ b/tests/Feature/Api/ApplicationAutoDeploySettingApiTest.php @@ -0,0 +1,66 @@ + InstanceSettings::firstOrCreate(['id' => 0])); + + $this->team = Team::factory()->create(); + $this->user = User::factory()->create(); + $this->team->members()->attach($this->user->id, ['role' => 'owner']); + session(['currentTeam' => $this->team]); + + $this->bearerToken = $this->user->createToken('auto-deploy-api-test', ['*'])->plainTextToken; + $this->server = Server::factory()->create(['team_id' => $this->team->id]); + $this->project = Project::factory()->create(['team_id' => $this->team->id]); + $this->environment = Environment::factory()->create(['project_id' => $this->project->id]); +}); + +describe('application creation endpoints is_auto_deploy_enabled', function () { + test('stores the requested auto deploy setting', function (string $endpoint, array $payload, bool $isAutoDeployEnabled) { + $response = $this->withHeaders(['Authorization' => 'Bearer '.$this->bearerToken]) + ->postJson("/api/v1/applications/{$endpoint}", [ + 'project_uuid' => $this->project->uuid, + 'environment_uuid' => $this->environment->uuid, + 'server_uuid' => $this->server->uuid, + 'is_auto_deploy_enabled' => $isAutoDeployEnabled, + 'instant_deploy' => false, + 'autogenerate_domain' => false, + ...$payload, + ]) + ->assertCreated(); + + $application = Application::where('uuid', $response->json('uuid'))->firstOrFail(); + + expect($application->settings->is_auto_deploy_enabled)->toBe($isAutoDeployEnabled); + })->with([ + 'Docker image' => ['dockerimage', [ + 'docker_registry_image_name' => 'nginx', + 'docker_registry_image_tag' => 'alpine', + 'ports_exposes' => '80', + ]], + 'Dockerfile' => ['dockerfile', [ + 'dockerfile' => base64_encode("FROM nginx:alpine\nEXPOSE 80"), + ]], + 'public repository' => ['public', [ + 'git_repository' => 'https://gitlab.com/coolify/auto-deploy-test', + 'git_branch' => 'main', + 'build_pack' => 'dockerfile', + 'ports_exposes' => '3000', + ]], + ])->with([ + 'disabled' => false, + 'enabled' => true, + ]); +});