mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Fix wrong path, implement tests
This commit is contained in:
+5
-5
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Functions\Http\Deployments\Status;
|
||||
namespace Appwrite\Platform\Modules\Functions\Http\Functions\Deployment;
|
||||
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Extend\Exception;
|
||||
@@ -22,16 +22,16 @@ class Update extends Action
|
||||
|
||||
public static function getName()
|
||||
{
|
||||
return 'updateDeploymentStatus';
|
||||
return 'updateFunctionDeployment';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH)
|
||||
->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId/status')
|
||||
->setHttpPath('/v1/functions/:functionId/deployment')
|
||||
->httpAlias('/v1/functions/:functionId/deployments/:deploymentId')
|
||||
->desc('Update deployment status')
|
||||
->desc('Update function\'s deployment')
|
||||
->groups(['api', 'functions'])
|
||||
->label('scope', 'functions.write')
|
||||
->label('event', 'functions.[functionId].deployments.[deploymentId].update')
|
||||
@@ -39,7 +39,7 @@ class Update extends Action
|
||||
->label('audits.resource', 'function/{request.functionId}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'functions',
|
||||
name: 'updateDeploymentStatus',
|
||||
name: 'updateFunctionDeployment',
|
||||
description: <<<EOT
|
||||
Update the function active deployment. Use this endpoint to switch the code deployment that should be used when visitor opens your function.
|
||||
EOT,
|
||||
@@ -8,7 +8,6 @@ use Appwrite\Platform\Modules\Functions\Http\Deployments\Create as CreateDeploym
|
||||
use Appwrite\Platform\Modules\Functions\Http\Deployments\Delete as DeleteDeployment;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Deployments\Download\Get as DownloadDeployment;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Deployments\Get as GetDeployment;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Deployments\Status\Update as UpdateDeploymentStatus;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Deployments\Template\Create as CreateTemplateDeployment;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Deployments\Vcs\Create as CreateVcsDeployment;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Deployments\XList as ListDeployments;
|
||||
@@ -18,6 +17,7 @@ use Appwrite\Platform\Modules\Functions\Http\Executions\Get as GetExecution;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Executions\XList as ListExecutions;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Functions\Create as CreateFunction;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Functions\Delete as DeleteFunction;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Functions\Deployment\Update as UpdateFunctionDeployment;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Functions\Get as GetFunction;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Functions\Update as UpdateFunction;
|
||||
use Appwrite\Platform\Modules\Functions\Http\Functions\XList as ListFunctions;
|
||||
@@ -56,7 +56,7 @@ class Http extends Service
|
||||
// Deployments
|
||||
$this->addAction(CreateDeployment::getName(), new CreateDeployment());
|
||||
$this->addAction(GetDeployment::getName(), new GetDeployment());
|
||||
$this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus());
|
||||
$this->addAction(UpdateFunctionDeployment::getName(), new UpdateFunctionDeployment());
|
||||
$this->addAction(ListDeployments::getName(), new ListDeployments());
|
||||
$this->addAction(DeleteDeployment::getName(), new DeleteDeployment());
|
||||
$this->addAction(CreateTemplateDeployment::getName(), new CreateTemplateDeployment());
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Sites\Http\Deployments\Status;
|
||||
namespace Appwrite\Platform\Modules\Sites\Http\Sites\Deployment;
|
||||
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Extend\Exception;
|
||||
@@ -20,16 +20,16 @@ class Update extends Action
|
||||
|
||||
public static function getName()
|
||||
{
|
||||
return 'updateDeploymentStatus';
|
||||
return 'updateSiteDeployment';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH)
|
||||
->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/status')
|
||||
->setHttpPath('/v1/sites/:siteId/deployment')
|
||||
->httpAlias('/v1/sites/:siteId/deployments/:deploymentId')
|
||||
->desc('Update deployment status')
|
||||
->desc('Update site\'s deployment')
|
||||
->groups(['api', 'sites'])
|
||||
->label('scope', 'sites.write')
|
||||
->label('event', 'sites.[siteId].deployments.[deploymentId].update')
|
||||
@@ -37,7 +37,7 @@ class Update extends Action
|
||||
->label('audits.resource', 'site/{request.siteId}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'sites',
|
||||
name: 'updateDeploymentStatus',
|
||||
name: 'updateSiteDeployment',
|
||||
description: <<<EOT
|
||||
Update the site active deployment. Use this endpoint to switch the code deployment that should be used when visitor opens your site.
|
||||
EOT,
|
||||
@@ -8,7 +8,6 @@ use Appwrite\Platform\Modules\Sites\Http\Deployments\Create as CreateDeployment;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Deployments\Delete as DeleteDeployment;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Deployments\Download\Get as DownloadDeployment;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Deployments\Get as GetDeployment;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Deployments\Status\Update as UpdateDeploymentStatus;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Deployments\Template\Create as CreateTemplateDeployment;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Deployments\Vcs\Create as CreateVcsDeployment;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Deployments\XList as ListDeployments;
|
||||
@@ -18,6 +17,7 @@ use Appwrite\Platform\Modules\Sites\Http\Logs\Get as GetLog;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Logs\XList as ListLogs;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Sites\Create as CreateSite;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Sites\Delete as DeleteSite;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Sites\Deployment\Update as UpdateSiteDeployment;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Sites\Get as GetSite;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Sites\Update as UpdateSite;
|
||||
use Appwrite\Platform\Modules\Sites\Http\Sites\XList as ListSites;
|
||||
@@ -54,7 +54,7 @@ class Http extends Service
|
||||
$this->addAction(CreateVcsDeployment::getName(), new CreateVcsDeployment());
|
||||
$this->addAction(GetDeployment::getName(), new GetDeployment());
|
||||
$this->addAction(ListDeployments::getName(), new ListDeployments());
|
||||
$this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus());
|
||||
$this->addAction(UpdateSiteDeployment::getName(), new UpdateSiteDeployment());
|
||||
$this->addAction(DeleteDeployment::getName(), new DeleteDeployment());
|
||||
$this->addAction(DownloadDeployment::getName(), new DownloadDeployment());
|
||||
$this->addAction(CreateBuild::getName(), new CreateBuild());
|
||||
|
||||
@@ -324,4 +324,16 @@ trait FunctionsBase
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function updateFunctionDeployment(string $functionId, string $deploymentId): mixed
|
||||
{
|
||||
$function = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployment', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'deploymentId' => $deploymentId
|
||||
]);
|
||||
|
||||
return $function;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1992,6 +1992,58 @@ class FunctionsCustomServerTest extends Scope
|
||||
|
||||
public function testUpdateDeploymentStatus(): void
|
||||
{
|
||||
// TODO: Create function, create deployment A, create execution A. create deployment B, ensure function B. Activate deployment A, ensure execution A. Cleanup
|
||||
|
||||
$functionId = $this->setupFunction([
|
||||
'functionId' => ID::unique(),
|
||||
'runtime' => 'php-8.0',
|
||||
'name' => 'Re-activate Test',
|
||||
'entrypoint' => 'index.php',
|
||||
]);
|
||||
$this->assertNotEmpty($functionId);
|
||||
|
||||
$deploymentId1 = $this->setupDeployment($functionId, [
|
||||
'code' => $this->packageFunction('php-cookie'),
|
||||
'activate' => true
|
||||
]);
|
||||
$this->assertNotEmpty($deploymentId1);
|
||||
|
||||
$execution = $this->createExecution($functionId, [
|
||||
'headers' => [ 'cookie' => 'cookieName=cookieValue' ]
|
||||
]);
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertNotEmpty($execution['body']['$id']);
|
||||
$this->assertStringContainsString('cookieValue', $execution['body']['responseBody']);
|
||||
|
||||
$deploymentId2 = $this->setupDeployment($functionId, [
|
||||
'code' => $this->packageFunction('php'),
|
||||
'activate' => true
|
||||
]);
|
||||
$this->assertNotEmpty($deploymentId2);
|
||||
|
||||
$execution = $this->createExecution($functionId);
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertNotEmpty($execution['body']['$id']);
|
||||
$this->assertStringContainsString('UNICODE_TEST', $execution['body']['responseBody']);
|
||||
|
||||
$function = $this->getFunction($functionId);
|
||||
$this->assertEquals(200, $function['headers']['status-code']);
|
||||
$this->assertEquals($deploymentId2, $function['body']['deployment']);
|
||||
|
||||
$function = $this->updateFunctionDeployment($functionId, $deploymentId1);
|
||||
$this->assertEquals(200, $function['headers']['status-code']);
|
||||
$this->assertEquals($deploymentId1, $function['body']['deployment']);
|
||||
|
||||
$function = $this->getFunction($functionId);
|
||||
$this->assertEquals(200, $function['headers']['status-code']);
|
||||
$this->assertEquals($deploymentId1, $function['body']['deployment']);
|
||||
|
||||
$execution = $this->createExecution($functionId, [
|
||||
'headers' => [ 'cookie' => 'cookieName=cookieValue' ]
|
||||
]);
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertNotEmpty($execution['body']['$id']);
|
||||
$this->assertStringContainsString('cookieValue', $execution['body']['responseBody']);
|
||||
|
||||
$this->cleanupFunction($functionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,4 +359,16 @@ trait SitesBase
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
protected function updateFunctionDeployment(string $siteId, string $deploymentId): mixed
|
||||
{
|
||||
$site = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployment', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'deploymentId' => $deploymentId
|
||||
]);
|
||||
|
||||
return $site;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1750,6 +1750,59 @@ class SitesCustomServerTest extends Scope
|
||||
|
||||
public function testUpdateDeploymentStatus(): void
|
||||
{
|
||||
// TODO: Create site, create deployment A, ensure site A. create dpeloyment B, ensure site B. Activate deploymnt A, ensure site A. Cleanup
|
||||
$siteId = $this->setupSite([
|
||||
'buildRuntime' => 'ssr-22',
|
||||
'framework' => 'other',
|
||||
'name' => 'Activate test Site',
|
||||
'siteId' => ID::unique()
|
||||
]);
|
||||
$this->assertNotEmpty($siteId);
|
||||
|
||||
$domain = $this->setupSiteDomain($siteId);
|
||||
$this->assertNotEmpty($domain);
|
||||
|
||||
$deploymentId1 = $this->setupDeployment($siteId, [
|
||||
'code' => $this->packageSite('static'),
|
||||
'activate' => true
|
||||
]);
|
||||
$this->assertNotEmpty($deploymentId1);
|
||||
|
||||
$proxyClient = new Client();
|
||||
$proxyClient->setEndpoint('http://' . $domain);
|
||||
$response = $proxyClient->call(Client::METHOD_GET, '/');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
// TODO: Ensure response from static
|
||||
|
||||
$deploymentId2 = $this->setupDeployment($siteId, [
|
||||
'code' => $this->packageSite('static-spa'),
|
||||
'activate' => true
|
||||
]);
|
||||
$this->assertNotEmpty($deploymentId2);
|
||||
|
||||
$proxyClient = new Client();
|
||||
$proxyClient->setEndpoint('http://' . $domain);
|
||||
$response = $proxyClient->call(Client::METHOD_GET, '/');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
// TODO: Ensure response from static-spa
|
||||
|
||||
$function = $this->getSite($siteId);
|
||||
$this->assertEquals(200, $function['headers']['status-code']);
|
||||
$this->assertEquals($deploymentId2, $function['body']['deploymentId']);
|
||||
|
||||
$function = $this->updateFunctionDeployment($siteId, $deploymentId1);
|
||||
$this->assertEquals(200, $function['headers']['status-code']);
|
||||
$this->assertEquals($deploymentId1, $function['body']['deploymentId']);
|
||||
|
||||
$function = $this->getSite($siteId);
|
||||
$this->assertEquals(200, $function['headers']['status-code']);
|
||||
$this->assertEquals($deploymentId1, $function['body']['deploymentId']);
|
||||
|
||||
$proxyClient = new Client();
|
||||
$proxyClient->setEndpoint('http://' . $domain);
|
||||
$response = $proxyClient->call(Client::METHOD_GET, '/');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
// TODO: Ensure response from static
|
||||
|
||||
$this->cleanupSite($siteId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user