global storage-providers, notification channels and server providers (#247)

This commit is contained in:
Saeed Vaziry
2024-06-29 12:52:03 +03:30
committed by GitHub
parent ad027eb033
commit 11e3b167cc
44 changed files with 678 additions and 77 deletions

View File

@ -21,12 +21,14 @@ public function test_add_email_channel(): void
'provider' => NotificationChannel::EMAIL,
'email' => 'email@example.com',
'label' => 'Email',
'global' => 1,
])->assertSessionDoesntHaveErrors();
/** @var \App\Models\NotificationChannel $channel */
$channel = \App\Models\NotificationChannel::query()
->where('provider', NotificationChannel::EMAIL)
->where('label', 'Email')
->whereNull('project_id')
->first();
$this->assertEquals('email@example.com', $channel->data['email']);

View File

@ -99,6 +99,8 @@ public function test_add_existing_key()
*/
public function test_create_ssh_key_handles_invalid_or_partial_keys(array $postBody, bool $expectedToSucceed): void
{
SSH::fake();
$this->actingAs($this->user);
// Some existing amount of seed data to make the test more realistic

View File

@ -32,6 +32,7 @@ public function test_connect_provider(string $provider, array $input): void
$this->assertDatabaseHas('server_providers', [
'provider' => $provider,
'profile' => 'profile',
'project_id' => isset($input['global']) ? null : $this->user->current_project_id,
]);
}
@ -136,6 +137,13 @@ public static function data(): array
'token' => 'token',
],
],
[
ServerProvider::LINODE,
[
'token' => 'token',
'global' => 1,
],
],
[
ServerProvider::DIGITALOCEAN,
[

View File

@ -13,21 +13,24 @@ class StorageProvidersTest extends TestCase
{
use RefreshDatabase;
public function test_connect_dropbox(): void
/**
* @dataProvider createData
*/
public function test_create(array $input): void
{
$this->actingAs($this->user);
Http::fake();
if ($input['provider'] === StorageProvider::DROPBOX) {
Http::fake();
}
$this->post(route('settings.storage-providers.connect'), [
'provider' => StorageProvider::DROPBOX,
'name' => 'profile',
'token' => 'token',
])->assertSessionDoesntHaveErrors();
$this->post(route('settings.storage-providers.connect'), $input)
->assertSessionDoesntHaveErrors();
$this->assertDatabaseHas('storage_providers', [
'provider' => StorageProvider::DROPBOX,
'profile' => 'profile',
'provider' => $input['provider'],
'profile' => $input['name'],
'project_id' => isset($input['global']) ? null : $this->user->current_project_id,
]);
}
@ -89,19 +92,69 @@ public function test_cannot_delete_provider(): void
]);
}
public function test_create_local_driver(): void
/**
* @TODO: complete FTP tests
*/
public static function createData(): array
{
$this->actingAs($this->user);
$this->post(route('settings.storage-providers.connect'), [
'provider' => StorageProvider::LOCAL,
'name' => 'profile',
'path' => '/home/vito/backups',
])->assertSessionDoesntHaveErrors();
$this->assertDatabaseHas('storage_providers', [
'provider' => StorageProvider::LOCAL,
'profile' => 'profile',
]);
return [
[
[
'provider' => StorageProvider::LOCAL,
'name' => 'local-test',
'path' => '/home/vito/backups',
],
],
[
[
'provider' => StorageProvider::LOCAL,
'name' => 'local-test',
'path' => '/home/vito/backups',
'global' => 1,
],
],
// [
// [
// 'provider' => StorageProvider::FTP,
// 'name' => 'ftp-test',
// 'host' => '1.2.3.4',
// 'port' => '22',
// 'path' => '/home/vito',
// 'username' => 'username',
// 'password' => 'password',
// 'ssl' => 1,
// 'passive' => 1,
// ],
// ],
// [
// [
// 'provider' => StorageProvider::FTP,
// 'name' => 'ftp-test',
// 'host' => '1.2.3.4',
// 'port' => '22',
// 'path' => '/home/vito',
// 'username' => 'username',
// 'password' => 'password',
// 'ssl' => 1,
// 'passive' => 1,
// 'global' => 1,
// ],
// ],
[
[
'provider' => StorageProvider::DROPBOX,
'name' => 'dropbox-test',
'token' => 'token',
],
],
[
[
'provider' => StorageProvider::DROPBOX,
'name' => 'dropbox-test',
'token' => 'token',
'global' => 1,
],
],
];
}
}