2026-02-23 15:32:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Models\Application;
|
|
|
|
|
use App\Models\ApplicationSetting;
|
|
|
|
|
use App\Models\Environment;
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
use App\Models\Server;
|
|
|
|
|
use App\Models\Team;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
|
|
|
|
describe('Application Rollback', function () {
|
2026-02-27 22:26:31 +00:00
|
|
|
beforeEach(function () {
|
2026-02-23 15:32:54 +00:00
|
|
|
$team = Team::factory()->create();
|
|
|
|
|
$project = Project::create([
|
|
|
|
|
'team_id' => $team->id,
|
|
|
|
|
'name' => 'Test Project',
|
|
|
|
|
'uuid' => (string) str()->uuid(),
|
|
|
|
|
]);
|
|
|
|
|
$environment = Environment::create([
|
|
|
|
|
'project_id' => $project->id,
|
|
|
|
|
'name' => 'rollback-test-env',
|
|
|
|
|
'uuid' => (string) str()->uuid(),
|
|
|
|
|
]);
|
|
|
|
|
$server = Server::factory()->create(['team_id' => $team->id]);
|
|
|
|
|
|
2026-02-27 22:26:31 +00:00
|
|
|
$this->application = Application::factory()->create([
|
2026-02-23 15:32:54 +00:00
|
|
|
'environment_id' => $environment->id,
|
|
|
|
|
'destination_id' => $server->id,
|
|
|
|
|
'git_commit_sha' => 'HEAD',
|
|
|
|
|
]);
|
2026-02-27 22:26:31 +00:00
|
|
|
});
|
2026-02-23 15:32:54 +00:00
|
|
|
|
2026-02-27 22:26:31 +00:00
|
|
|
test('setGitImportSettings uses passed commit instead of application git_commit_sha', function () {
|
2026-02-23 15:32:54 +00:00
|
|
|
ApplicationSetting::create([
|
2026-02-27 22:26:31 +00:00
|
|
|
'application_id' => $this->application->id,
|
2026-02-23 15:32:54 +00:00
|
|
|
'is_git_shallow_clone_enabled' => false,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$rollbackCommit = 'abc123def456';
|
|
|
|
|
|
2026-02-27 22:26:31 +00:00
|
|
|
$result = $this->application->setGitImportSettings(
|
2026-02-23 15:32:54 +00:00
|
|
|
deployment_uuid: 'test-uuid',
|
|
|
|
|
git_clone_command: 'git clone',
|
|
|
|
|
public: true,
|
|
|
|
|
commit: $rollbackCommit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect($result)->toContain($rollbackCommit);
|
|
|
|
|
});
|
2026-02-27 22:26:31 +00:00
|
|
|
|
|
|
|
|
test('setGitImportSettings with shallow clone fetches specific commit', function () {
|
|
|
|
|
ApplicationSetting::create([
|
|
|
|
|
'application_id' => $this->application->id,
|
|
|
|
|
'is_git_shallow_clone_enabled' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$rollbackCommit = 'abc123def456';
|
|
|
|
|
|
|
|
|
|
$result = $this->application->setGitImportSettings(
|
|
|
|
|
deployment_uuid: 'test-uuid',
|
|
|
|
|
git_clone_command: 'git clone',
|
|
|
|
|
public: true,
|
|
|
|
|
commit: $rollbackCommit
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect($result)
|
|
|
|
|
->toContain('git fetch --depth=1 origin')
|
|
|
|
|
->toContain($rollbackCommit);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('setGitImportSettings falls back to git_commit_sha when no commit passed', function () {
|
|
|
|
|
$this->application->update(['git_commit_sha' => 'def789abc012']);
|
|
|
|
|
|
|
|
|
|
ApplicationSetting::create([
|
|
|
|
|
'application_id' => $this->application->id,
|
|
|
|
|
'is_git_shallow_clone_enabled' => false,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$result = $this->application->setGitImportSettings(
|
|
|
|
|
deployment_uuid: 'test-uuid',
|
|
|
|
|
git_clone_command: 'git clone',
|
|
|
|
|
public: true,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect($result)->toContain('def789abc012');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('setGitImportSettings does not append checkout when commit is HEAD', function () {
|
|
|
|
|
ApplicationSetting::create([
|
|
|
|
|
'application_id' => $this->application->id,
|
|
|
|
|
'is_git_shallow_clone_enabled' => false,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$result = $this->application->setGitImportSettings(
|
|
|
|
|
deployment_uuid: 'test-uuid',
|
|
|
|
|
git_clone_command: 'git clone',
|
|
|
|
|
public: true,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect($result)->not->toContain('advice.detachedHead=false checkout');
|
|
|
|
|
});
|
2026-02-23 15:32:54 +00:00
|
|
|
});
|