feat(KAN-38): rebuild personal Git connection settings
This commit is contained in:
@@ -25,11 +25,15 @@ class GitConnectionTest extends TestCase
|
||||
'base_url' => 'https://git.example.test',
|
||||
]);
|
||||
|
||||
UserGitConnection::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('git-connections.edit'))
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('settings/GitConnections')
|
||||
->has('gitConnections', 1)
|
||||
->missing('gitConnections.0.api_token')
|
||||
->where('gitConnections.0.account_login', 'nico')
|
||||
->where('gitConnections.0.base_url', 'https://git.example.test')
|
||||
->where('gitConnections.0.provider', GitProviderKey::Gitea->value),
|
||||
@@ -93,7 +97,8 @@ class GitConnectionTest extends TestCase
|
||||
'api_token' => 'wrong-token',
|
||||
])
|
||||
->assertRedirect(route('git-connections.edit'))
|
||||
->assertSessionHasErrors('api_token');
|
||||
->assertSessionHasErrors('api_token')
|
||||
->assertSessionMissing('_old_input.api_token');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,4 +186,59 @@ class GitConnectionTest extends TestCase
|
||||
'id' => $gitConnection->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_empty_personal_connections_are_displayed(): void
|
||||
{
|
||||
UserGitConnection::factory()->create();
|
||||
|
||||
$this->actingAs(User::factory()->create())
|
||||
->get(route('git-connections.edit'))
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('settings/GitConnections')
|
||||
->where('gitConnections', []),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_guests_cannot_access_git_connections(): void
|
||||
{
|
||||
$this->get(route('git-connections.edit'))->assertRedirect(route('login'));
|
||||
}
|
||||
|
||||
public function test_users_cannot_delete_foreign_connections(): void
|
||||
{
|
||||
$connection = UserGitConnection::factory()->create();
|
||||
|
||||
$this->actingAs(User::factory()->create())
|
||||
->delete(route('git-connections.destroy', $connection))
|
||||
->assertForbidden();
|
||||
|
||||
$this->assertModelExists($connection);
|
||||
}
|
||||
|
||||
public function test_failed_provider_update_preserves_connection_and_does_not_flash_token(): void
|
||||
{
|
||||
Http::preventStrayRequests();
|
||||
Http::fake(['https://git.changed.test/api/v1/user' => Http::response([], 503)]);
|
||||
$user = User::factory()->create();
|
||||
$connection = UserGitConnection::factory()->for($user)->create([
|
||||
'base_url' => 'https://git.original.test',
|
||||
'api_token' => 'original-secret',
|
||||
]);
|
||||
$original = $connection->fresh()->getAttributes();
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('git-connections.edit'))
|
||||
->patch(route('git-connections.update', $connection), [
|
||||
'provider' => 'gitea',
|
||||
'base_url' => 'https://git.changed.test',
|
||||
'api_token' => 'replacement-secret',
|
||||
])
|
||||
->assertRedirect(route('git-connections.edit'))
|
||||
->assertSessionHasErrors('api_token')
|
||||
->assertSessionMissing('_old_input.api_token');
|
||||
|
||||
$this->assertSame($original, $connection->fresh()->getAttributes());
|
||||
$this->assertSame('original-secret', $connection->fresh()->api_token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Settings;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GitConnectionsUiTest extends TestCase
|
||||
{
|
||||
public function test_personal_git_connections_rendering_and_localization(): void
|
||||
{
|
||||
$process = new Process(['node', 'tests/Fixtures/git-connections.mjs'], base_path());
|
||||
$process->setTimeout(60);
|
||||
$process->run();
|
||||
$this->assertTrue($process->isSuccessful(), $process->getOutput().$process->getErrorOutput());
|
||||
$this->assertStringContainsString('Git connections rendering checks passed.', $process->getOutput());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user