mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Removed Laravel Jetstream
This commit is contained in:
committed by
Constantin Graf
parent
bffd0773be
commit
89a9341d91
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ use App\Service\PermissionStore;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Jetstream\Jetstream;
|
||||
|
||||
abstract class TestCaseWithDatabase extends TestCase
|
||||
{
|
||||
@@ -25,8 +24,6 @@ abstract class TestCaseWithDatabase extends TestCase
|
||||
protected function createUserWithPermission(array $permissions = [], bool $isOwner = false): object
|
||||
{
|
||||
$roleName = 'custom-test-'.Str::uuid();
|
||||
Jetstream::role($roleName, 'Custom Test', $permissions)
|
||||
->description('Role custom for testing');
|
||||
PermissionStore::registerCustomRole($roleName, $permissions);
|
||||
$user = User::factory()->create();
|
||||
if ($isOwner) {
|
||||
|
||||
@@ -193,7 +193,7 @@ class InvitationEndpointTest extends ApiEndpointTestAbstract
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.invitations.store', $data->organization->getKey()), [
|
||||
$response = $this->withoutExceptionHandling()->postJson(route('api.v1.invitations.store', $data->organization->getKey()), [
|
||||
'email' => $user->email,
|
||||
'role' => Role::Employee->value,
|
||||
]);
|
||||
|
||||
44
tests/Unit/Endpoint/Api/V1/TimeZoneEndpointTest.php
Normal file
44
tests/Unit/Endpoint/Api/V1/TimeZoneEndpointTest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Api\V1\TimeZoneController;
|
||||
use App\Service\TimezoneService;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
#[CoversClass(TimeZoneController::class)]
|
||||
#[CoversClass(TimezoneService::class)]
|
||||
class TimeZoneEndpointTest extends TestCase
|
||||
{
|
||||
public function test_index_returns_list_of_available_timezones(): void
|
||||
{
|
||||
// Arrange
|
||||
$timezones = app(TimezoneService::class)->getTimezones();
|
||||
|
||||
// Act
|
||||
$response = $this->getJson(route('api.v1.time-zones.index'));
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertJsonCount(count($timezones));
|
||||
$response->assertJsonStructure([
|
||||
[
|
||||
'key',
|
||||
],
|
||||
]);
|
||||
|
||||
$responseObj = collect($response->json());
|
||||
$this->assertSame([
|
||||
'key' => $timezones[0],
|
||||
], $responseObj->first());
|
||||
$this->assertSame([
|
||||
'key' => 'Europe/Vienna',
|
||||
], $responseObj->firstWhere('key', '=', 'Europe/Vienna'));
|
||||
$this->assertSame([
|
||||
'key' => 'America/New_York',
|
||||
], $responseObj->firstWhere('key', '=', 'America/New_York'));
|
||||
}
|
||||
}
|
||||
@@ -310,7 +310,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$photoDisk = (string) config('jetstream.profile_photo_disk', 'public');
|
||||
$photoDisk = (string) config('filesystems.public', 'public');
|
||||
$previousPhotoPath = 'profile-photos/previous.png';
|
||||
$photo = file_get_contents(resource_path('testfiles/test.png'));
|
||||
$this->assertIsString($photo);
|
||||
@@ -491,7 +491,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$photoDisk = (string) config('jetstream.profile_photo_disk', 'public');
|
||||
$photoDisk = (string) config('filesystems.public', 'public');
|
||||
$photoPath = 'profile-photos/existing.png';
|
||||
Storage::fake($photoDisk);
|
||||
Storage::disk($photoDisk)->put($photoPath, 'photo contents');
|
||||
@@ -515,7 +515,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$photoDisk = (string) config('jetstream.profile_photo_disk', 'public');
|
||||
$photoDisk = (string) config('filesystems.public', 'public');
|
||||
Storage::fake($photoDisk);
|
||||
$data->user->profile_photo_path = null;
|
||||
$data->user->save();
|
||||
@@ -536,7 +536,7 @@ class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$photoDisk = (string) config('jetstream.profile_photo_disk', 'public');
|
||||
$photoDisk = (string) config('filesystems.public', 'public');
|
||||
$photoPath = 'profile-photos/existing.png';
|
||||
Storage::fake($photoDisk);
|
||||
Storage::disk($photoDisk)->put($photoPath, 'photo contents');
|
||||
|
||||
174
tests/Unit/Endpoint/Web/OrganizationEndpointTest.php
Normal file
174
tests/Unit/Endpoint/Web/OrganizationEndpointTest.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Web;
|
||||
|
||||
use App\Http\Controllers\Web\OrganizationController;
|
||||
use App\Models\Organization;
|
||||
use App\Models\OrganizationInvitation;
|
||||
use App\Models\User;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
|
||||
#[CoversClass(OrganizationController::class)]
|
||||
class OrganizationEndpointTest extends EndpointTestAbstract
|
||||
{
|
||||
public function test_organization_create_succeeds(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->withPersonalOrganization()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('organizations.create'));
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertInertia(fn (Assert $page) => $page
|
||||
->component('Teams/Create')
|
||||
);
|
||||
}
|
||||
|
||||
public function test_legacy_teams_create_redirects_to_new_organization_create(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->withPersonalOrganization()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('teams.create'));
|
||||
|
||||
// Assert
|
||||
$response->assertRedirect(route('organizations.create'));
|
||||
}
|
||||
|
||||
public function test_organization_show_succeeds(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'organizations:view',
|
||||
]);
|
||||
$this->actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('organizations.show', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertInertia(fn (Assert $page) => $page
|
||||
->component('Teams/Show')
|
||||
->where('team.id', $data->organization->getKey())
|
||||
->where('team.name', $data->organization->name)
|
||||
->where('team.currency', $data->organization->currency)
|
||||
->where('team.owner.id', $data->owner->getKey())
|
||||
->where('team.owner.name', $data->owner->name)
|
||||
->has('team.owner.profile_photo_url')
|
||||
->has('currencies')
|
||||
->where('availableRoles', [])
|
||||
->where('availablePermissions', [])
|
||||
->where('defaultPermissions', [])
|
||||
->where('permissions.canAddTeamMembers', true)
|
||||
->where('permissions.canDeleteTeam', true)
|
||||
->where('permissions.canRemoveTeamMembers', true)
|
||||
->where('permissions.canUpdateTeam', true)
|
||||
->where('permissions.canUpdateTeamMembers', true)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_legacy_team_show_redirects_to_organization_show(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'organizations:view',
|
||||
]);
|
||||
$this->actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('teams.show', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertRedirect(route('organizations.show', [$data->organization->getKey()]));
|
||||
}
|
||||
|
||||
public function test_team_show_redirects_to_dashboard_for_invalid_organization_id(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->withPersonalOrganization()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('organizations.show', ['not-a-uuid']));
|
||||
|
||||
// Assert
|
||||
$response->assertRedirect(route('dashboard'));
|
||||
}
|
||||
|
||||
public function test_organization_show_redirects_to_dashboard_for_unknown_organization_id(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->withPersonalOrganization()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('organizations.show', ['00000000-0000-4000-8000-000000000000']));
|
||||
|
||||
// Assert
|
||||
$response->assertRedirect(route('dashboard'));
|
||||
}
|
||||
|
||||
public function test_organization_show_redirects_to_dashboard_without_organization_view_permission(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
$this->actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('organizations.show', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertRedirect(route('dashboard'));
|
||||
}
|
||||
|
||||
public function test_organization_show_redirects_to_dashboard_for_organization_outside_user_memberships(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'organizations:view',
|
||||
]);
|
||||
$otherOrganization = Organization::factory()->create();
|
||||
$this->actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('organizations.show', [$otherOrganization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertRedirect(route('dashboard'));
|
||||
}
|
||||
|
||||
public function test_organization_show_does_not_expose_member_roster_invitations_or_owner_email(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'organizations:view',
|
||||
]);
|
||||
OrganizationInvitation::factory()->forOrganization($data->organization)->create([
|
||||
'email' => 'pending@example.com',
|
||||
]);
|
||||
$this->actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->get(route('organizations.show', [$data->organization->getKey()]));
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertInertia(fn (Assert $page) => $page
|
||||
->missing('team.users')
|
||||
->missing('team.team_invitations')
|
||||
->missing('team.owner.email')
|
||||
->has('team.owner.id')
|
||||
->has('team.owner.name')
|
||||
->has('team.owner.profile_photo_url')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Web;
|
||||
|
||||
use App\Models\OrganizationInvitation;
|
||||
use App\Providers\JetstreamServiceProvider;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Laravel\Jetstream\Jetstream;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
|
||||
#[CoversClass(JetstreamServiceProvider::class)]
|
||||
class TeamShowEndpointTest extends EndpointTestAbstract
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
Jetstream::$inertiaManager = null;
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function test_team_show_does_not_expose_member_roster_invitations_or_owner_email(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([]);
|
||||
OrganizationInvitation::factory()->forOrganization($data->organization)->create([
|
||||
'email' => 'pending@example.com',
|
||||
]);
|
||||
$this->actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->get('/teams/'.$data->organization->getKey());
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertInertia(fn (Assert $page) => $page
|
||||
->missing('team.users')
|
||||
->missing('team.team_invitations')
|
||||
->missing('team.owner.email')
|
||||
->has('team.owner.id')
|
||||
->has('team.owner.name')
|
||||
->has('team.owner.profile_photo_url')
|
||||
);
|
||||
}
|
||||
}
|
||||
138
tests/Unit/Endpoint/Web/UserProfileEndpointTest.php
Normal file
138
tests/Unit/Endpoint/Web/UserProfileEndpointTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Endpoint\Web;
|
||||
|
||||
use App\Enums\Weekday;
|
||||
use App\Http\Controllers\Web\UserProfileController;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
|
||||
#[CoversClass(UserProfileController::class)]
|
||||
class UserProfileEndpointTest extends EndpointTestAbstract
|
||||
{
|
||||
public function test_showing_profile_succeeds_and_exposes_profile_settings_data(): void
|
||||
{
|
||||
// Arrange
|
||||
config(['session.driver' => 'array']);
|
||||
$user = User::factory()->withPersonalOrganization()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
// Act
|
||||
$response = $this->get('/user/profile');
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertInertia(fn (Assert $page) => $page
|
||||
->component('Profile/Show')
|
||||
->has('timezones')
|
||||
->where('weekdays', Weekday::toSelectArray())
|
||||
->where('confirmsTwoFactorAuthentication', true)
|
||||
->where('sessions', [])
|
||||
);
|
||||
}
|
||||
|
||||
public function test_showing_profile_exposes_database_sessions_for_current_user(): void
|
||||
{
|
||||
// Arrange
|
||||
config(['session.driver' => 'database']);
|
||||
$this->travelTo(Carbon::parse('2024-01-02 12:00:00', 'UTC'));
|
||||
$user = User::factory()->withPersonalOrganization()->create();
|
||||
$otherUser = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
DB::table('sessions')->insert([
|
||||
[
|
||||
'id' => 'older-session',
|
||||
'user_id' => $user->getKey(),
|
||||
'ip_address' => '192.0.2.10',
|
||||
'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||
'payload' => '',
|
||||
'last_activity' => now()->subMinutes(5)->timestamp,
|
||||
],
|
||||
[
|
||||
'id' => 'newer-session',
|
||||
'user_id' => $user->getKey(),
|
||||
'ip_address' => '192.0.2.20',
|
||||
'user_agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
|
||||
'payload' => '',
|
||||
'last_activity' => now()->subMinute()->timestamp,
|
||||
],
|
||||
[
|
||||
'id' => 'other-user-session',
|
||||
'user_id' => $otherUser->getKey(),
|
||||
'ip_address' => '192.0.2.30',
|
||||
'user_agent' => '',
|
||||
'payload' => '',
|
||||
'last_activity' => now()->timestamp,
|
||||
],
|
||||
]);
|
||||
|
||||
// Act
|
||||
$response = $this->get('/user/profile');
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertInertia(fn (Assert $page) => $page
|
||||
->component('Profile/Show')
|
||||
->has('sessions', 2)
|
||||
->where('sessions.0.agent.is_desktop', true)
|
||||
->where('sessions.0.agent.platform', 'Linux')
|
||||
->where('sessions.0.agent.browser', 'Chrome')
|
||||
->where('sessions.0.ip_address', '192.0.2.20')
|
||||
->where('sessions.0.is_current_device', false)
|
||||
->where('sessions.0.last_active', '1 minute ago')
|
||||
->where('sessions.1.agent.is_desktop', true)
|
||||
->where('sessions.1.agent.platform', 'OS X')
|
||||
->where('sessions.1.agent.browser', 'Chrome')
|
||||
->where('sessions.1.ip_address', '192.0.2.10')
|
||||
->where('sessions.1.is_current_device', false)
|
||||
->where('sessions.1.last_active', '5 minutes ago')
|
||||
);
|
||||
}
|
||||
|
||||
public function test_showing_profile_marks_two_factor_authentication_as_empty_when_disabled(): void
|
||||
{
|
||||
// Arrange
|
||||
config(['session.driver' => 'array']);
|
||||
$user = User::factory()->withPersonalOrganization()->create([
|
||||
'two_factor_secret' => null,
|
||||
'two_factor_confirmed_at' => null,
|
||||
]);
|
||||
$this->actingAs($user);
|
||||
|
||||
// Act
|
||||
$response = $this->get('/user/profile');
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertSessionHas('two_factor_empty_at');
|
||||
}
|
||||
|
||||
public function test_showing_profile_disables_unconfirmed_two_factor_authentication_after_confirmation_was_abandoned(): void
|
||||
{
|
||||
// Arrange
|
||||
config(['session.driver' => 'array']);
|
||||
$user = User::factory()->withPersonalOrganization()->create([
|
||||
'two_factor_secret' => 'secret',
|
||||
'two_factor_recovery_codes' => '[]',
|
||||
'two_factor_confirmed_at' => null,
|
||||
]);
|
||||
$this->actingAs($user);
|
||||
$this->withSession(['two_factor_confirming_at' => time() - 1]);
|
||||
|
||||
// Act
|
||||
$response = $this->get('/user/profile');
|
||||
|
||||
// Assert
|
||||
$response->assertOk();
|
||||
$response->assertSessionHas('two_factor_empty_at');
|
||||
$response->assertSessionMissing('two_factor_confirming_at');
|
||||
$this->assertNull($user->fresh()->two_factor_secret);
|
||||
$this->assertNull($user->fresh()->two_factor_confirmed_at);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user