mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-11 17:52:15 +01:00
Removed Laravel Jetstream
This commit is contained in:
@@ -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