Fixed bugs in current organization; Add database consistency checks; Add foreign key

This commit is contained in:
Constantin Graf
2025-05-16 12:51:27 +02:00
committed by Constantin Graf
parent c80d51c2e1
commit d64f0c52be
13 changed files with 440 additions and 3 deletions

View File

@@ -150,6 +150,24 @@ class DeletionServiceTest extends TestCaseWithDatabase
$this->assertSame($specialCase ? 7 : 6, TimeEntry::query()->whereBelongsTo($organization, 'organization')->count());
}
public function test_delete_organization_resets_the_current_organization_of_users_that_had_the_deleted_organization_as_current_organization(): void
{
// Arrange
$userOwner = User::factory()->create();
$organization = Organization::factory()->withOwner($userOwner)->create();
$userOwner->currentOrganization()->associate($organization);
$userOwner->save();
// Act
$this->deletionService->deleteOrganization($organization);
// Assert
$this->assertOrganizationDeleted($organization);
$userOwner->refresh();
$this->assertNull($userOwner->current_team_id);
$this->assertNotSame($organization->id, $userOwner->current_team_id);
}
public function test_delete_organization_deletes_all_resources_of_the_organization_but_does_not_delete_other_resources(): void
{
// Arrange

View File

@@ -114,6 +114,41 @@ class MemberServiceTest extends TestCaseWithDatabase
$this->assertSame(1, $otherUser->organizations()->count());
}
public function test_make_member_to_placeholder_resets_current_organization_of_user_if_user_is_no_longer_member_to_newly_created_organization(): void
{
// Arrange
$organization = Organization::factory()->create();
$user = User::factory()->forCurrentOrganization($organization)->create();
$member = Member::factory()->forOrganization($organization)->forUser($user)->role(Role::Employee)->create();
// Act
$this->memberService->makeMemberToPlaceholder($member);
// Assert
$user->refresh();
$this->assertNotNull($user->current_team_id);
$this->assertNotSame($organization->id, $user->current_team_id);
}
public function test_make_member_to_placeholder_resets_current_organization_of_user_if_user_is_no_longer_member_to_already_existing_other_organization(): void
{
// Arrange
$organization = Organization::factory()->create();
$user = User::factory()->forCurrentOrganization($organization)->create();
$member = Member::factory()->forOrganization($organization)->forUser($user)->role(Role::Employee)->create();
$otherOrganization = Organization::factory()->create();
$otherMember = Member::factory()->forOrganization($otherOrganization)->forUser($user)->role(Role::Employee)->create();
// Act
$this->memberService->makeMemberToPlaceholder($member);
// Assert
$user->refresh();
$this->assertNotNull($user->current_team_id);
$this->assertSame($otherOrganization->id, $user->current_team_id);
}
public function test_assign_organization_entities_to_different_member_without_any_entries(): void
{
// Arrange