mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 08:12:17 +01:00
Added placeholder users; Better exception handling; Enhanced local setup
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user