Skip to content

Commit 3fde1e0

Browse files
committed
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.
1 parent 9e96a20 commit 3fde1e0

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

app/Livewire/Project/Application/General.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ public function setRedirect()
735735
$this->authorize('update', $this->application);
736736

737737
try {
738+
$this->application->redirect = $this->redirect;
738739
$has_www = collect($this->application->fqdns)->filter(fn ($fqdn) => str($fqdn)->contains('www.'))->count();
739740
if ($has_www === 0 && $this->application->redirect === 'www') {
740741
$this->dispatch('error', 'You want to redirect to www, but you do not have a www domain set.<br><br>Please add www to your domain list and as an A DNS record (if applicable).');
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
use App\Livewire\Project\Application\General;
4+
use App\Models\Application;
5+
use App\Models\Environment;
6+
use App\Models\Project;
7+
use App\Models\Team;
8+
use App\Models\User;
9+
use Illuminate\Foundation\Testing\RefreshDatabase;
10+
use Livewire\Livewire;
11+
12+
uses(RefreshDatabase::class);
13+
14+
beforeEach(function () {
15+
$this->team = Team::factory()->create();
16+
$this->user = User::factory()->create();
17+
$this->team->members()->attach($this->user->id, ['role' => 'owner']);
18+
19+
$this->actingAs($this->user);
20+
session(['currentTeam' => $this->team]);
21+
22+
$this->project = Project::factory()->create(['team_id' => $this->team->id]);
23+
$this->environment = Environment::factory()->create(['project_id' => $this->project->id]);
24+
});
25+
26+
describe('Application Redirect', function () {
27+
test('setRedirect persists the redirect value to the database', function () {
28+
$application = Application::factory()->create([
29+
'environment_id' => $this->environment->id,
30+
'fqdn' => 'https://example.com,https://www.example.com',
31+
'redirect' => 'both',
32+
]);
33+
34+
Livewire::test(General::class, ['application' => $application])
35+
->assertSuccessful()
36+
->set('redirect', 'www')
37+
->call('setRedirect')
38+
->assertDispatched('success');
39+
40+
$application->refresh();
41+
expect($application->redirect)->toBe('www');
42+
});
43+
44+
test('setRedirect rejects www redirect when no www domain exists', function () {
45+
$application = Application::factory()->create([
46+
'environment_id' => $this->environment->id,
47+
'fqdn' => 'https://example.com',
48+
'redirect' => 'both',
49+
]);
50+
51+
Livewire::test(General::class, ['application' => $application])
52+
->assertSuccessful()
53+
->set('redirect', 'www')
54+
->call('setRedirect')
55+
->assertDispatched('error');
56+
57+
$application->refresh();
58+
expect($application->redirect)->toBe('both');
59+
});
60+
});

0 commit comments

Comments
 (0)