feat: add support for selecting additional SSH keys from Hetzner in server creation form

This commit is contained in:
Andras Bacsai
2025-10-10 12:17:05 +02:00
parent ee211526ea
commit ac3af8a882
7 changed files with 413 additions and 34 deletions

View File

@@ -0,0 +1,53 @@
<?php
it('merges Coolify key with selected Hetzner keys', function () {
$coolifyKeyId = 123;
$selectedHetznerKeys = [456, 789];
// Simulate the merge logic from createHetznerServer
$sshKeys = array_merge(
[$coolifyKeyId],
$selectedHetznerKeys
);
expect($sshKeys)->toBe([123, 456, 789])
->and(count($sshKeys))->toBe(3);
});
it('removes duplicate SSH key IDs', function () {
$coolifyKeyId = 123;
$selectedHetznerKeys = [123, 456, 789]; // User also selected Coolify key
// Simulate the merge and deduplication logic
$sshKeys = array_merge(
[$coolifyKeyId],
$selectedHetznerKeys
);
$sshKeys = array_unique($sshKeys);
$sshKeys = array_values($sshKeys);
expect($sshKeys)->toBe([123, 456, 789])
->and(count($sshKeys))->toBe(3);
});
it('works with no selected Hetzner keys', function () {
$coolifyKeyId = 123;
$selectedHetznerKeys = [];
// Simulate the merge logic
$sshKeys = array_merge(
[$coolifyKeyId],
$selectedHetznerKeys
);
expect($sshKeys)->toBe([123])
->and(count($sshKeys))->toBe(1);
});
it('validates SSH key IDs are integers', function () {
$selectedHetznerKeys = [456, 789, 1011];
foreach ($selectedHetznerKeys as $keyId) {
expect($keyId)->toBeInt();
}
});