mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-14 19:22:14 +01:00
Fix foreign keys and deletion service
This commit is contained in:
committed by
Constantin Graf
parent
4224fdd57e
commit
3b3f593080
@@ -13,6 +13,9 @@ use App\Models\User;
|
||||
use App\Providers\Filament\AdminPanelProvider;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Passport\AuthCode;
|
||||
use Laravel\Passport\Client;
|
||||
use Laravel\Passport\Token;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
@@ -138,4 +141,66 @@ class UserModelTest extends ModelTestAbstract
|
||||
$this->assertCount(1, $activeUsers);
|
||||
$this->assertTrue($activeUsers->first()->is($user));
|
||||
}
|
||||
|
||||
public function test_it_has_many_access_tokens(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->create();
|
||||
$client = new Client;
|
||||
$client->name = 'desktop';
|
||||
$client->redirect = 'solidtime://oauth/callback';
|
||||
$client->personal_access_client = false;
|
||||
$client->password_client = false;
|
||||
$client->revoked = false;
|
||||
$client->save();
|
||||
$token = new Token;
|
||||
$token->id = 'some-id';
|
||||
$token->user_id = $user->getKey();
|
||||
$token->client_id = $client->getKey();
|
||||
$token->revoked = false;
|
||||
$token->save();
|
||||
|
||||
// Act
|
||||
$user->refresh();
|
||||
$tokensRel = $user->accessTokens;
|
||||
|
||||
// Assert
|
||||
$this->assertNotNull($tokensRel);
|
||||
$this->assertCount(1, $tokensRel);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[$token->getKey()],
|
||||
$tokensRel->pluck('id')->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_has_many_auth_codes(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->create();
|
||||
$client = new Client;
|
||||
$client->name = 'desktop';
|
||||
$client->redirect = 'solidtime://oauth/callback';
|
||||
$client->personal_access_client = false;
|
||||
$client->password_client = false;
|
||||
$client->revoked = false;
|
||||
$client->save();
|
||||
$authCode = new AuthCode;
|
||||
$authCode->id = 'some-id';
|
||||
$authCode->user_id = $user->getKey();
|
||||
$authCode->client_id = $client->getKey();
|
||||
$authCode->revoked = false;
|
||||
$authCode->save();
|
||||
|
||||
// Act
|
||||
$user->refresh();
|
||||
$authCodesRel = $user->authCodes;
|
||||
|
||||
// Assert
|
||||
$this->assertNotNull($authCodesRel);
|
||||
$this->assertCount(1, $authCodesRel);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
[$authCode->getKey()],
|
||||
$authCodesRel->pluck('id')->toArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,20 +307,31 @@ class DeletionServiceTest extends TestCaseWithDatabase
|
||||
{
|
||||
// Arrange
|
||||
$user = User::factory()->create();
|
||||
$otherUser = User::factory()->create();
|
||||
$organizationOwned = Organization::factory()->withOwner($user)->create();
|
||||
$organizationNotOwned = Organization::factory()->create();
|
||||
$organizationNotOwned = Organization::factory()->withOwner($otherUser)->create();
|
||||
$memberOwned = Member::factory()->forUser($user)->forOrganization($organizationOwned)->role(Role::Owner)->create();
|
||||
$memberNotOwned = Member::factory()->forUser($user)->forOrganization($organizationNotOwned)->role(Role::Employee)->create();
|
||||
TimeEntry::factory()->forOrganization($organizationOwned)->forMember($memberOwned)->createMany(2);
|
||||
TimeEntry::factory()->forOrganization($organizationNotOwned)->forMember($memberNotOwned)->createMany(2);
|
||||
$this->assertDatabaseCount(User::class, 2);
|
||||
|
||||
// Act
|
||||
$this->deletionService->deleteUser($user);
|
||||
|
||||
// Assert
|
||||
$this->assertDatabaseCount(Organization::class, 1);
|
||||
$this->assertDatabaseCount(User::class, 2);
|
||||
$this->assertDatabaseMissing(User::class, [
|
||||
'id' => $user->getKey(),
|
||||
]);
|
||||
$this->assertDatabaseHas(User::class, [
|
||||
'id' => $otherUser->getKey(),
|
||||
'is_placeholder' => false,
|
||||
]);
|
||||
$this->assertDatabaseHas(User::class, [
|
||||
'is_placeholder' => true,
|
||||
]);
|
||||
$this->assertDatabaseMissing(Organization::class, [
|
||||
'id' => $organizationOwned->getKey(),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user