mirror of
https://github.com/ConvoyPanel/panel.git
synced 2026-05-08 16:09:44 +08:00
Shift automatically applies the Laravel coding style - which uses the PSR-12 coding style as a base with some minor additions. You may customize the code style applied by configuring [Pint](https://laravel.com/docs/pint), [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer), or [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for your project root. For more information on customizing the code style applied by Shift, [watch this short video](https://laravelshift.com/videos/shift-code-style).
73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
use Convoy\Jobs\Server\MonitorBackupJob;
|
|
use Convoy\Jobs\Server\MonitorBackupRestorationJob;
|
|
use Convoy\Models\Backup;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
beforeEach(fn () => Http::preventStrayRequests());
|
|
|
|
it('can create backups', function () {
|
|
Queue::fake();
|
|
Http::fake([
|
|
'*' => Http::response(['data' => 'upid'], 200),
|
|
]);
|
|
|
|
[$user, $_, $_, $server] = createServerModel();
|
|
|
|
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/backups", [
|
|
'name' => 'Test Backup',
|
|
'mode' => 'snapshot',
|
|
'compression_type' => 'none',
|
|
'is_locked' => false,
|
|
]);
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('data.name', 'Test Backup')
|
|
->assertJsonPath('data.is_locked', (int) false);
|
|
|
|
Queue::assertPushed(MonitorBackupJob::class);
|
|
});
|
|
|
|
it('can restore backups', function () {
|
|
Queue::fake();
|
|
Http::fake([
|
|
'*/status/current' => Http::response(file_get_contents(base_path('tests/Fixtures/Repositories/Server/GetStoppedServerStatusData.json')), 200),
|
|
'*' => Http::response(['data' => 'dummy-upid'], 200),
|
|
|
|
]);
|
|
|
|
[$user, $_, $_, $server] = createServerModel();
|
|
|
|
$backup = Backup::factory()->create([
|
|
'is_successful' => true,
|
|
'is_locked' => false,
|
|
'server_id' => $server->id,
|
|
]);
|
|
|
|
$response = $this->actingAs($user)->postJson("/api/client/servers/{$server->uuid}/backups/{$backup->uuid}/restore");
|
|
|
|
$response->assertNoContent();
|
|
|
|
Queue::assertPushed(MonitorBackupRestorationJob::class);
|
|
});
|
|
|
|
it('can delete backups', function () {
|
|
Http::fake([
|
|
'*' => Http::response(['data' => 'dummy-upid'], 200),
|
|
]);
|
|
|
|
[$user, $_, $_, $server] = createServerModel();
|
|
|
|
$backup = Backup::factory()->create([
|
|
'is_successful' => true,
|
|
'is_locked' => false,
|
|
'server_id' => $server->id,
|
|
]);
|
|
|
|
$response = $this->actingAs($user)->deleteJson("/api/client/servers/{$server->uuid}/backups/{$backup->uuid}");
|
|
|
|
$response->assertNoContent();
|
|
});
|