mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 15:32:35 +00:00
Add endpoint for reading and updating site .env file (#564)
* feat(api): Add endpoint for reading site .env file - Add GET /api/projects/{project}/servers/{server}/sites/{site}/env endpoint - Add feature tests with SSH mocking * added updating env * fix coding style * generate docs --------- Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com>
This commit is contained in:
@ -312,6 +312,81 @@ public function test_show_deployment_script(): void
|
||||
->assertJsonPath('script', $scriptContent);
|
||||
}
|
||||
|
||||
public function test_show_env(): void
|
||||
{
|
||||
$envContent = "APP_NAME=Laravel\nAPP_ENV=production";
|
||||
SSH::fake($envContent);
|
||||
|
||||
Sanctum::actingAs($this->user, ['read']);
|
||||
|
||||
/** @var Site $site */
|
||||
$site = Site::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
$this->json('GET', route('api.projects.servers.sites.env.show', [
|
||||
'project' => $this->server->project,
|
||||
'server' => $this->server,
|
||||
'site' => $site,
|
||||
]))
|
||||
->assertSuccessful()
|
||||
->assertJsonStructure([
|
||||
'data' => [
|
||||
'env',
|
||||
],
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'env' => $envContent,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_show_env_unauthorized(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
Sanctum::actingAs($this->user, []); // no abilities
|
||||
|
||||
/** @var Site $site */
|
||||
$site = Site::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
$this->json('GET', route('api.projects.servers.sites.env.show', [
|
||||
'project' => $this->server->project,
|
||||
'server' => $this->server,
|
||||
'site' => $site,
|
||||
]))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_update_env(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
Sanctum::actingAs($this->user, ['read', 'write']);
|
||||
|
||||
/** @var Site $site */
|
||||
$site = Site::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
]);
|
||||
|
||||
$envContent = "APP_NAME=Laravel\nAPP_ENV=production";
|
||||
|
||||
$this->json('PUT', route('api.projects.servers.sites.env', [
|
||||
'project' => $this->server->project,
|
||||
'server' => $this->server,
|
||||
'site' => $site,
|
||||
]), [
|
||||
'env' => $envContent,
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertJsonFragment([
|
||||
'domain' => $site->domain,
|
||||
]);
|
||||
|
||||
SSH::assertExecuted('edit-file');
|
||||
}
|
||||
|
||||
public static function create_data(): array
|
||||
{
|
||||
return \Tests\Feature\SitesTest::create_data();
|
||||
|
Reference in New Issue
Block a user