Removed Laravel Jetstream

This commit is contained in:
Constantin Graf
2026-06-08 16:37:02 +02:00
parent 42f9efd570
commit cb42daecbf
57 changed files with 964 additions and 1357 deletions

View File

@@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Enums\Role;
use App\Events\AfterCreateOrganization;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class CreateOrganizationTest extends TestCase
{
use RefreshDatabase;
public function test_organizations_can_be_created(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$this->actingAs($user);
Event::fake([
AfterCreateOrganization::class,
]);
// Act
$response = $this->post('/teams', [
'name' => 'Test Organization',
]);
// Assert
$response->assertStatus(302);
/** @var Organization|null $newOrganization */
$ownedOrganizations = $user->fresh()->ownedOrganizations;
$this->assertCount(2, $ownedOrganizations);
$this->assertTrue($ownedOrganizations->contains('name', 'Test Organization'));
$newOrganization = $ownedOrganizations->firstWhere('name', 'Test Organization');
/** @var Member $member */
$member = Member::query()->whereBelongsTo($user, 'user')->whereBelongsTo($newOrganization, 'organization')->firstOrFail();
$this->assertSame(Role::Owner->value, $member->role);
Event::assertDispatched(AfterCreateOrganization::class, function (AfterCreateOrganization $event) use ($newOrganization): bool {
return $event->organization->is($newOrganization);
});
}
}

View File

@@ -1,68 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Enums\Role;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DeleteAccountTest extends TestCase
{
use RefreshDatabase;
public function test_user_accounts_can_be_deleted(): void
{
// Arrange
$user = User::factory()->create();
$this->actingAs($user);
// Act
$response = $this->delete('/user', [
'password' => 'password',
]);
// Assert
$response->assertStatus(302);
$this->assertNull($user->fresh());
}
public function test_correct_password_must_be_provided_before_account_can_be_deleted(): void
{
// Arrange
$user = User::factory()->create();
$this->actingAs($user);
// Act
$response = $this->delete('/user', [
'password' => 'wrong-password',
]);
// Assert
$this->assertNotNull($user->fresh());
}
public function test_user_account_can_not_be_deleted_if_attached_to_a_organization_with_multiple_users(): void
{
// Arrange
$user = User::factory()->create();
$organization = Organization::factory()->withOwner($user)->create();
$userMember = Member::factory()->forOrganization($organization)->forUser($user)->role(Role::Owner)->create();
$otherUser = User::factory()->create();
$otherMember = Member::factory()->forOrganization($organization)->forUser($otherUser)->role(Role::Admin)->create();
$this->actingAs($user);
// Act
$response = $this->delete('/user', [
'password' => 'password',
]);
// Assert
$response->assertInvalid(['password']);
$this->assertNotNull($user->fresh());
}
}

View File

@@ -1,84 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Enums\Role;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DeleteOrganizationTest extends TestCase
{
use RefreshDatabase;
public function test_organizations_can_be_deleted_and_users_of_the_organization_that_have_no_organization_get_a_new_one(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$this->actingAs($user);
$organization = Organization::factory()->withOwner($user)->create([
'personal_team' => false,
]);
Member::factory()->forOrganization($organization)->forUser($user)->role(Role::Owner)->create();
$otherUser = User::factory()->create();
$organization->users()->attach(
$otherUser, ['role' => 'test-role']
);
// Act
$response = $this->delete('/teams/'.$organization->getKey());
// Assert
$this->assertNull($organization->fresh());
$this->assertCount(1, $otherUser->fresh()->organizations);
$this->assertFalse($otherUser->fresh()->organizations->first()->is($organization));
}
public function test_personal_organizations_can_be_deleted_but_user_gets_an_new_one_if_this_is_the_only_one_left(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$organization = $user->currentOrganization;
$this->actingAs($user);
// Act
$response = $this->delete('/teams/'.$organization->getKey());
// Assert
$user->refresh();
$this->assertDatabaseMissing(Organization::class, [
'id' => $organization->getKey(),
]);
$this->assertTrue($user->currentOrganization->isNot($organization));
}
public function test_organization_can_not_be_deleted_if_user_is_not_owner(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$organization = Organization::factory()->withOwner($user)->create([
'personal_team' => false,
]);
$this->actingAs($user);
$otherUser = User::factory()->create();
$organization->users()->attach(
$otherUser, ['role' => Role::Admin->value]
);
// Act
$response = $this->delete('/teams/'.$organization->getKey());
// Assert
$response->assertForbidden();
$this->assertDatabaseHas(Organization::class, [
'id' => $organization->getKey(),
]);
}
}

View File

@@ -17,44 +17,6 @@ class InviteTeamMemberTest extends TestCase
{
use RefreshDatabase;
public function test_team_members_can_no_longer_be_invited_to_team_over_jetstream(): void
{
// Arrange
Mail::fake();
$this->actingAs($user = User::factory()->withPersonalOrganization()->create());
// Act
$response = $this->post('/teams/'.$user->currentOrganization->id.'/members', [
'email' => 'test@example.com',
'role' => 'admin',
]);
// Assert
$response->assertStatus(403);
$response->assertSee('Moved to API');
Mail::assertNothingSent();
}
public function test_team_member_invitations_can_no_longer_be_cancelled_over_jetstream(): void
{
// Arrange
Mail::fake();
$this->actingAs($user = User::factory()->withPersonalOrganization()->create());
$invitation = $user->currentOrganization->organizationInvitations()->create([
'email' => 'test@example.com',
'role' => 'admin',
]);
// Act
$response = $this->delete('/team-invitations/'.$invitation->id);
// Assert
$response->assertStatus(403);
$this->assertCount(1, $user->currentOrganization->fresh()->organizationInvitations);
}
public function test_team_member_invitations_can_be_accepted(): void
{
// Arrange

View File

@@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class LeaveTeamTest extends TestCase
{
use RefreshDatabase;
public function test_users_can_no_longer_leave_team_over_jetstream(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$user->currentOrganization->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
$this->actingAs($otherUser);
// Act
$response = $this->delete('/teams/'.$user->currentOrganization->id.'/members/'.$otherUser->id);
// Assert
$response->assertStatus(403);
$this->assertCount(2, $user->currentOrganization->fresh()->users);
}
}

View File

@@ -17,20 +17,7 @@ class ProfileInformationTest extends TestCase
{
use RefreshDatabase;
public function test_show_profile_information_succeeds(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$this->actingAs($user);
// Act
$response = $this->get('/user/profile');
// Assert
$response->assertSuccessful();
}
public function test_profile_information_can_be_updated(): void
public function test_profile_information_can_no_longer_be_updated_via_inertia(): void
{
// Arrange
$user = User::factory()->create([
@@ -48,99 +35,9 @@ class ProfileInformationTest extends TestCase
]);
// Assert
$response->assertValid(errorBag: 'updateProfileInformation');
$response->assertStatus(403);
$user = $user->fresh();
$this->assertEquals('Test Name', $user->name);
$this->assertEquals('test@example.com', $user->email);
$this->assertEquals($timezone, $user->timezone);
$this->assertEquals(Weekday::Sunday, $user->week_start);
}
public function test_email_update_keeps_current_email_verified_until_new_email_is_verified(): void
{
// Arrange
Mail::fake();
$user = User::factory()->create([
'email' => 'current@example.com',
'email_verified_at' => now(),
]);
$timezone = app(TimezoneService::class)->getTimezones()[0];
$this->actingAs($user);
// Act
$response = $this->put('/user/profile-information', [
'name' => 'Test Name',
'email' => 'New.Email@Example.com',
'timezone' => $timezone,
'week_start' => Weekday::Sunday->value,
]);
// Assert
$response->assertValid(errorBag: 'updateProfileInformation');
$user = $user->fresh();
$this->assertEquals('current@example.com', $user->email);
$this->assertEquals('new.email@example.com', $user->pending_email);
$this->assertNotNull($user->email_verified_at);
Mail::assertSent(VerifyUpdatedEmailMail::class, function (VerifyUpdatedEmailMail $mail): bool {
return $mail->hasTo('new.email@example.com') && $mail->email === 'new.email@example.com';
});
}
public function test_pending_email_can_be_verified(): void
{
// Arrange
$user = User::factory()->create([
'email' => 'current@example.com',
'pending_email' => 'new.email@example.com',
]);
$this->actingAs($user);
$verificationUrl = URL::temporarySignedRoute(
'users.verify-email-change',
now()->addMinutes(60),
[
'user' => $user->getKey(),
'email' => 'new.email@example.com',
],
false
);
// Act
$response = $this->get($verificationUrl);
// Assert
$response->assertRedirect(route('dashboard'));
$response->assertSessionHas('bannerStyle', 'success');
$response->assertSessionHas('bannerText', 'Your email address has been updated successfully.');
$user = $user->fresh();
$this->assertEquals('new.email@example.com', $user->email);
$this->assertNull($user->pending_email);
$this->assertNotNull($user->email_verified_at);
}
public function test_profile_update_does_not_clear_pending_email_when_email_is_unchanged(): void
{
// Arrange
$user = User::factory()->create([
'email' => 'current@example.com',
'pending_email' => 'new.email@example.com',
]);
$timezone = app(TimezoneService::class)->getTimezones()[0];
$this->actingAs($user);
// Act
$response = $this->put('/user/profile-information', [
'name' => 'Updated Name',
'email' => 'current@example.com',
'timezone' => $timezone,
'week_start' => Weekday::Sunday->value,
]);
// Assert
$response->assertValid(errorBag: 'updateProfileInformation');
$user = $user->fresh();
$this->assertEquals('Updated Name', $user->name);
$this->assertEquals('current@example.com', $user->email);
$this->assertEquals('new.email@example.com', $user->pending_email);
$this->assertEquals($user->name, $user->name);
}
public function test_pending_email_verification_redirects_with_danger_banner_when_email_already_in_use(): void

View File

@@ -17,7 +17,6 @@ use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Jetstream;
use Tests\TestCaseWithDatabase;
use TiMacDonald\Log\LogEntry;
@@ -47,7 +46,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
]);
// Assert
@@ -78,7 +77,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
]);
// Assert
@@ -97,7 +96,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'peter.test@gmail',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
]);
// Assert
@@ -112,7 +111,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'PETER.test@gmail.com ',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
]);
// Assert
@@ -132,7 +131,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
'newsletter_consent' => true,
]);
@@ -154,7 +153,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
'timezone' => 'Europe/Berlin',
]);
@@ -182,7 +181,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
'timezone' => 'Europe/Berlin',
]);
@@ -213,7 +212,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
'timezone' => null,
]);
@@ -244,7 +243,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
'timezone' => 'Unknown timezone',
]);
@@ -275,7 +274,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
'timezone' => 'Asia/Calcutta',
]);
@@ -296,7 +295,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
'timezone' => 'Unknown timezone',
]);
@@ -319,7 +318,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
]);
$this->assertFalse($this->isAuthenticated(), 'The user is authenticated');
@@ -340,7 +339,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
]);
$this->assertAuthenticated();
@@ -365,7 +364,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
]);
$this->assertAuthenticated();
@@ -398,7 +397,7 @@ class RegistrationTest extends TestCaseWithDatabase
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
'terms' => true,
]);
// Assert

View File

@@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class RemoveTeamMemberTest extends TestCase
{
use RefreshDatabase;
public function test_team_members_can_no_longer_be_removed_from_teams_over_jetstream_endpoints(): void
{
// Arrange
$this->actingAs($user = User::factory()->withPersonalOrganization()->create());
$user->currentOrganization->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
// Act
$response = $this->delete('/teams/'.$user->currentOrganization->id.'/members/'.$otherUser->id);
// Assert
$response->assertStatus(403);
$response->assertSee('Moved to API');
}
}

View File

@@ -1,35 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Enums\Role;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UpdateTeamMemberRoleTest extends TestCase
{
use RefreshDatabase;
public function test_team_member_roles_can_no_longer_be_updated_over_jetstream(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$this->actingAs($user);
$user->currentOrganization->users()->attach(
$otherUser = User::factory()->create(), ['role' => 'admin']
);
// Act
$response = $this->put('/teams/'.$user->currentOrganization->id.'/members/'.$otherUser->id, [
'role' => Role::Employee->value,
]);
// Assert
$response->assertStatus(403);
$response->assertSee('Moved to API');
}
}

View File

@@ -1,47 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UpdateTeamTest extends TestCase
{
use RefreshDatabase;
public function test_team_update_page_shows_not_found_if_id_is_not_uuid(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$this->actingAs($user);
// Act
$response = $this->get('/teams/1');
// Assert
$response->assertStatus(404);
}
public function test_team_names_can_be_updated(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$this->actingAs($user);
// Act
$response = $this->put('/teams/'.$user->currentOrganization->id, [
'name' => 'Test Organization',
'currency' => 'USD',
]);
// Assert
$response->assertValid(errorBag: 'updateTeamName');
$this->assertCount(1, $user->fresh()->ownedOrganizations);
$organization = $user->currentOrganization->fresh();
$this->assertEquals('Test Organization', $organization->name);
$this->assertEquals('USD', $organization->currency);
}
}