Added placeholder users; Better exception handling; Enhanced local setup

This commit is contained in:
Constantin Graf
2024-03-08 13:31:49 +01:00
parent 0ed5d14817
commit 77e7a63b83
38 changed files with 882 additions and 89 deletions

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Tests\Unit\Model;
use App\Models\Organization;
use App\Models\TimeEntry;
use App\Models\User;
use App\Providers\Filament\AdminPanelProvider;
use Filament\Panel;
@@ -42,4 +44,47 @@ class UserModelTest extends ModelTestAbstract
// Assert
$this->assertTrue($canAccess);
}
public function test_scope_belongs_to_organization_returns_only_users_of_organization_including_owners(): void
{
// Arrange
$owner = User::factory()->create();
$organization = Organization::factory()->withOwner($owner)->create();
$user = User::factory()->create();
$user->organizations()->attach($organization, [
'role' => 'employee',
]);
$otherOrganization = Organization::factory()->create();
$otherUser = User::factory()->create();
$otherUser->organizations()->attach($otherOrganization, [
'role' => 'employee',
]);
// Act
$users = User::query()
->belongsToOrganization($organization)
->get();
// Assert
$this->assertCount(2, $users);
$userIds = $users->pluck('id')->toArray();
$this->assertContains($user->getKey(), $userIds);
$this->assertContains($owner->getKey(), $userIds);
}
public function test_it_has_many_time_entries(): void
{
// Arrange
$user = User::factory()->create();
$timeEntries = TimeEntry::factory()->forUser($user)->createMany(3);
// Act
$user->refresh();
$timeEntriesRel = $user->timeEntries;
// Assert
$this->assertNotNull($timeEntriesRel);
$this->assertCount(3, $timeEntriesRel);
$this->assertTrue($timeEntriesRel->first()->is($timeEntries->first()));
}
}