mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Replaces all Jetstream model trait functions and relations
This commit is contained in:
committed by
Constantin Graf
parent
5eb1a6a006
commit
734aab6353
@@ -4,9 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Filament\Resources;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Exceptions\Api\CanNotDeleteUserWhoIsOwnerOfOrganizationWithMultipleMembers;
|
||||
use App\Filament\Resources\TimeEntryResource;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use App\Service\DeletionService;
|
||||
@@ -103,7 +105,7 @@ class UserResourceTest extends FilamentTestCase
|
||||
$this->assertSame($userFake->email, $user->email);
|
||||
$this->assertSame($userFake->timezone, $user->timezone);
|
||||
$this->assertSame($userFake->week_start->value, $user->week_start->value);
|
||||
$organization = $user->ownedTeams()->first();
|
||||
$organization = $user->ownedOrganizations()->first();
|
||||
$this->assertNotNull($organization);
|
||||
$this->assertSame('EUR', $organization->currency);
|
||||
$this->assertTrue(Hash::check('password', $user->password));
|
||||
@@ -152,7 +154,9 @@ class UserResourceTest extends FilamentTestCase
|
||||
// Arrange
|
||||
$user = User::factory()->create();
|
||||
$ownedOrganization = Organization::factory()->withOwner($user)->create();
|
||||
Member::factory()->forOrganization($ownedOrganization)->forUser($user)->role(Role::Owner)->create();
|
||||
$organization = Organization::factory()->create();
|
||||
Member::factory()->forOrganization($organization)->forUser($user)->role(Role::Employee)->create();
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(UserResource\RelationManagers\OrganizationsRelationManager::class, [
|
||||
@@ -163,7 +167,7 @@ class UserResourceTest extends FilamentTestCase
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$response->assertCanSeeTableRecords($user->organizations()->get());
|
||||
$response->assertCanNotSeeTableRecords($user->ownedTeams()->get());
|
||||
$response->assertCanSeeTableRecords($user->ownedOrganizations()->get());
|
||||
}
|
||||
|
||||
public function test_can_list_related_owned_organizations(): void
|
||||
@@ -171,7 +175,9 @@ class UserResourceTest extends FilamentTestCase
|
||||
// Arrange
|
||||
$user = User::factory()->create();
|
||||
$ownedOrganization = Organization::factory()->withOwner($user)->create();
|
||||
Member::factory()->forOrganization($ownedOrganization)->forUser($user)->role(Role::Owner)->create();
|
||||
$organization = Organization::factory()->create();
|
||||
Member::factory()->forOrganization($organization)->forUser($user)->role(Role::Employee)->create();
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(UserResource\RelationManagers\OwnedOrganizationsRelationManager::class, [
|
||||
@@ -181,7 +187,7 @@ class UserResourceTest extends FilamentTestCase
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$response->assertCanSeeTableRecords($user->ownedTeams()->get());
|
||||
$response->assertCanNotSeeTableRecords($user->organizations()->get());
|
||||
$response->assertCanSeeTableRecords($user->ownedOrganizations()->get());
|
||||
$response->assertCanNotSeeTableRecords([$organization]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,9 @@ class UserModelTest extends ModelTestAbstract
|
||||
$user->organizations()->attach($organization, [
|
||||
'role' => Role::Employee->value,
|
||||
]);
|
||||
$owner->organizations()->attach($organization, [
|
||||
'role' => Role::Owner->value,
|
||||
]);
|
||||
$otherOrganization = Organization::factory()->create();
|
||||
$otherUser = User::factory()->create();
|
||||
$otherUser->organizations()->attach($otherOrganization, [
|
||||
@@ -80,6 +83,70 @@ class UserModelTest extends ModelTestAbstract
|
||||
$this->assertContains($owner->getKey(), $userIds);
|
||||
}
|
||||
|
||||
public function test_is_member_of_organization_returns_true_for_user_attached_to_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$user->organizations()->attach($organization, [
|
||||
'role' => Role::Employee->value,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$isMemberOfOrganization = $user->isMemberOfOrganization($organization);
|
||||
|
||||
// Assert
|
||||
$this->assertTrue($isMemberOfOrganization);
|
||||
}
|
||||
|
||||
public function test_is_member_of_organization_returns_false_for_user_not_attached_to_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
|
||||
// Act
|
||||
$isMemberOfOrganization = $user->isMemberOfOrganization($organization);
|
||||
|
||||
// Assert
|
||||
$this->assertFalse($isMemberOfOrganization);
|
||||
}
|
||||
|
||||
public function test_is_member_of_organization_uses_loaded_organizations_relation(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$user = User::factory()
|
||||
->attachToOrganization($organization, [
|
||||
'role' => Role::Employee->value,
|
||||
])
|
||||
->create();
|
||||
$user->load('organizations');
|
||||
|
||||
// Act
|
||||
$isMemberOfOrganization = $user->isMemberOfOrganization($organization);
|
||||
|
||||
// Assert
|
||||
$this->assertTrue($isMemberOfOrganization);
|
||||
}
|
||||
|
||||
public function test_is_member_of_organization_does_not_query_when_organizations_relation_is_loaded(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$user = User::factory()->create();
|
||||
$user->load('organizations');
|
||||
$user->organizations()->attach($organization, [
|
||||
'role' => Role::Employee->value,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$isMemberOfOrganization = $user->isMemberOfOrganization($organization);
|
||||
|
||||
// Assert
|
||||
$this->assertFalse($isMemberOfOrganization);
|
||||
}
|
||||
|
||||
public function test_it_has_many_time_entries(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user