61 lines
2.2 KiB
PHP
61 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Models;
|
|
|
|
use App\Actions\Git\Data\GitRepository;
|
|
use App\Actions\Git\GitProviderKey;
|
|
use App\Models\RepositoryConnection;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class RepositoryConnectionTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* Ensure the repository connection factory creates a project-scoped Gitea link.
|
|
*/
|
|
public function test_factory_creates_a_project_repository_connection(): void
|
|
{
|
|
$repositoryConnection = RepositoryConnection::factory()->create();
|
|
|
|
$this->assertSame(GitProviderKey::Gitea, $repositoryConnection->fresh()->provider);
|
|
$this->assertNotNull($repositoryConnection->project_id);
|
|
$this->assertNotSame('', $repositoryConnection->repository_full_name);
|
|
}
|
|
|
|
/**
|
|
* Ensure repository connections belong to a project.
|
|
*/
|
|
public function test_repository_connections_belong_to_a_project(): void
|
|
{
|
|
$repositoryConnection = RepositoryConnection::factory()->create();
|
|
|
|
$this->assertTrue($repositoryConnection->project()->exists());
|
|
$this->assertTrue($repositoryConnection->project->is($repositoryConnection->fresh()->project));
|
|
}
|
|
|
|
/**
|
|
* Ensure repository connections can be used as Git provider repository data.
|
|
*/
|
|
public function test_repository_connections_convert_to_git_repository_data(): void
|
|
{
|
|
$repositoryConnection = RepositoryConnection::factory()->create([
|
|
'base_url' => 'https://git.example.test',
|
|
'owner_name' => 'core-team',
|
|
'provider_repository_id' => '501',
|
|
'repository_full_name' => 'core-team/kanbangit',
|
|
'repository_name' => 'kanbangit',
|
|
'repository_url' => 'https://git.example.test/core-team/kanbangit',
|
|
]);
|
|
|
|
$repository = $repositoryConnection->toGitRepository();
|
|
|
|
$this->assertInstanceOf(GitRepository::class, $repository);
|
|
$this->assertSame('https://git.example.test', $repository->baseUrl);
|
|
$this->assertSame('core-team', $repository->owner);
|
|
$this->assertSame('kanbangit', $repository->name);
|
|
$this->assertSame('core-team/kanbangit', $repository->fullName);
|
|
}
|
|
}
|