From 3fde1e0f9f74f44dd5f0620e1f5db17d9ca0c35f Mon Sep 17 00:00:00 2001
From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
Date: Sun, 29 Mar 2026 20:50:03 +0200
Subject: [PATCH] fix(application): persist redirect value in setRedirect
Assign the selected redirect option before validation so valid changes are saved.
Add feature tests to verify redirect persistence and rejection when no www domain exists.
---
app/Livewire/Project/Application/General.php | 1 +
tests/Feature/ApplicationRedirectTest.php | 60 ++++++++++++++++++++
2 files changed, 61 insertions(+)
create mode 100644 tests/Feature/ApplicationRedirectTest.php
diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php
index c12fec76a..6fd063cf3 100644
--- a/app/Livewire/Project/Application/General.php
+++ b/app/Livewire/Project/Application/General.php
@@ -735,6 +735,7 @@ public function setRedirect()
$this->authorize('update', $this->application);
try {
+ $this->application->redirect = $this->redirect;
$has_www = collect($this->application->fqdns)->filter(fn ($fqdn) => str($fqdn)->contains('www.'))->count();
if ($has_www === 0 && $this->application->redirect === 'www') {
$this->dispatch('error', 'You want to redirect to www, but you do not have a www domain set.
Please add www to your domain list and as an A DNS record (if applicable).');
diff --git a/tests/Feature/ApplicationRedirectTest.php b/tests/Feature/ApplicationRedirectTest.php
new file mode 100644
index 000000000..55b124f81
--- /dev/null
+++ b/tests/Feature/ApplicationRedirectTest.php
@@ -0,0 +1,60 @@
+team = Team::factory()->create();
+ $this->user = User::factory()->create();
+ $this->team->members()->attach($this->user->id, ['role' => 'owner']);
+
+ $this->actingAs($this->user);
+ session(['currentTeam' => $this->team]);
+
+ $this->project = Project::factory()->create(['team_id' => $this->team->id]);
+ $this->environment = Environment::factory()->create(['project_id' => $this->project->id]);
+});
+
+describe('Application Redirect', function () {
+ test('setRedirect persists the redirect value to the database', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'fqdn' => 'https://example.com,https://www.example.com',
+ 'redirect' => 'both',
+ ]);
+
+ Livewire::test(General::class, ['application' => $application])
+ ->assertSuccessful()
+ ->set('redirect', 'www')
+ ->call('setRedirect')
+ ->assertDispatched('success');
+
+ $application->refresh();
+ expect($application->redirect)->toBe('www');
+ });
+
+ test('setRedirect rejects www redirect when no www domain exists', function () {
+ $application = Application::factory()->create([
+ 'environment_id' => $this->environment->id,
+ 'fqdn' => 'https://example.com',
+ 'redirect' => 'both',
+ ]);
+
+ Livewire::test(General::class, ['application' => $application])
+ ->assertSuccessful()
+ ->set('redirect', 'www')
+ ->call('setRedirect')
+ ->assertDispatched('error');
+
+ $application->refresh();
+ expect($application->redirect)->toBe('both');
+ });
+});