Add endpoint for reading & updating site deployment script (#562)

* feat(api): Add endpoint for updating site deployment script

- Add PUT /api/projects/{project}/servers/{server}/sites/{site}/deployment-script endpoint
- Add feature tests for successful and failed updates

* added reading deployment script as well

* generate docs

---------

Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
Dimitar Yanakiev
2025-03-29 22:49:28 +02:00
committed by GitHub
parent 03be2d3ee2
commit 7882d2022c
33 changed files with 4072 additions and 1701 deletions

View File

@ -190,6 +190,79 @@ public function test_update_load_balancer(): void
]);
}
public function test_update_deployment_script(): void
{
SSH::fake();
Sanctum::actingAs($this->user, ['read', 'write']);
/** @var Site $site */
$site = Site::factory()->create([
'server_id' => $this->server->id,
]);
$scriptContent = "git pull\ncomposer install\nphp artisan migrate";
$this->json('PUT', route('api.projects.servers.sites.deployment-script', [
'project' => $this->server->project,
'server' => $this->server,
'site' => $site,
]), [
'script' => $scriptContent,
])
->assertSuccessful()
->assertNoContent();
$this->assertDatabaseHas('deployment_scripts', [
'site_id' => $site->id,
'content' => $scriptContent,
]);
}
public function test_update_deployment_script_without_content(): void
{
SSH::fake();
Sanctum::actingAs($this->user, ['read', 'write']);
/** @var Site $site */
$site = Site::factory()->create([
'server_id' => $this->server->id,
]);
$this->json('PUT', route('api.projects.servers.sites.deployment-script', [
'project' => $this->server->project,
'server' => $this->server,
'site' => $site,
]), [])
->assertStatus(422)
->assertJsonValidationErrors(['script']);
}
public function test_show_deployment_script(): void
{
Sanctum::actingAs($this->user, ['read']);
/** @var Site $site */
$site = Site::factory()->create([
'server_id' => $this->server->id,
]);
$scriptContent = "git pull\ncomposer install";
$site->deploymentScript->update([
'content' => $scriptContent,
]);
$this->json('GET', route('api.projects.servers.sites.deployment-script.show', [
'project' => $this->server->project,
'server' => $this->server,
'site' => $site,
]))
->assertSuccessful()
->assertJsonPath('script', $scriptContent);
}
public static function create_data(): array
{
return \Tests\Feature\SitesTest::create_data();