|
| 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