Implement Gitea user connection foundation

This commit is contained in:
2026-03-26 08:56:52 +01:00
parent ec5b531e5e
commit 5f52d050ee
23 changed files with 1206 additions and 1 deletions
@@ -0,0 +1,43 @@
<?php
namespace Tests\Feature\Models;
use App\Actions\Git\GitProviderKey;
use App\Models\UserGitConnection;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class UserGitConnectionTest extends TestCase
{
use RefreshDatabase;
/**
* Ensure the user git connection factory creates a valid encrypted Gitea connection.
*/
public function test_factory_creates_a_gitea_connection_with_an_encrypted_token(): void
{
$gitConnection = UserGitConnection::factory()->create([
'api_token' => 'plain-test-token',
]);
$storedToken = DB::table('user_git_connections')
->where('id', $gitConnection->id)
->value('api_token');
$this->assertNotSame('plain-test-token', $storedToken);
$this->assertSame('plain-test-token', $gitConnection->fresh()->api_token);
$this->assertSame(GitProviderKey::Gitea, $gitConnection->fresh()->provider);
}
/**
* Ensure the model belongs to a user for per-account credential scoping.
*/
public function test_git_connections_belong_to_a_user(): void
{
$gitConnection = UserGitConnection::factory()->create();
$this->assertTrue($gitConnection->user()->exists());
$this->assertTrue($gitConnection->user->is($gitConnection->fresh()->user));
}
}