Files
KanbanGit/tests/Feature/Models/UserGitConnectionTest.php
T

44 lines
1.3 KiB
PHP

<?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));
}
}