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

@@ -51,21 +51,27 @@ class ImportDatabaseHelperTest extends TestCase
]);
}
public function test_get_key_not_attach_to_existing_returns_key_for_identifier_without_creating_model(): void
public function test_get_key_not_attach_to_existing_is_not_implemented_yet(): void
{
// Arrange
$project = Project::factory()->create();
$helper = new ImportDatabaseHelper(Project::class, ['name', 'organization_id'], false);
// Act
$key = $helper->getKey([
'name' => $project->name,
'organization_id' => $project->organization_id,
], [
'color' => '#000000',
]);
try {
$key = $helper->getKey([
'name' => $project->name,
'organization_id' => $project->organization_id,
], [
'color' => '#000000',
]);
} catch (\Exception $e) {
$this->assertSame('Not implemented', $e->getMessage());
return;
}
// Assert
$this->assertNotSame($project->getKey(), $key);
$this->fail();
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Service;
use App\Models\Organization;
use App\Models\TimeEntry;
use App\Models\User;
use App\Service\UserService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UserServiceTest extends TestCase
{
use RefreshDatabase;
public function test_assign_organization_entities_to_different_user(): void
{
// Arrange
$organization = Organization::factory()->create();
$otherUser = User::factory()->create();
$fromUser = User::factory()->create();
$toUser = User::factory()->create();
TimeEntry::factory()->forOrganization($organization)->forUser($otherUser)->createMany(3);
TimeEntry::factory()->forOrganization($organization)->forUser($fromUser)->createMany(3);
// Act
$userService = app(UserService::class);
$userService->assignOrganizationEntitiesToDifferentUser($organization, $fromUser, $toUser);
// Assert
$this->assertSame(3, TimeEntry::query()->whereBelongsTo($toUser, 'user')->count());
$this->assertSame(3, TimeEntry::query()->whereBelongsTo($otherUser, 'user')->count());
$this->assertSame(0, TimeEntry::query()->whereBelongsTo($fromUser, 'user')->count());
}
}