diff --git a/composer.json b/composer.json index 5f40f4d593..ca67bef867 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "utopia-php/database": "0.59.0", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", - "utopia-php/framework": "0.33.*", + "utopia-php/framework": "dev-fix-alias-params as 0.33.99", "utopia-php/fetch": "0.3.*", "utopia-php/image": "0.7.*", "utopia-php/locale": "0.4.*", diff --git a/composer.lock b/composer.lock index 3690e25ed0..0d39ca7340 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6883b3e81cfb0c5355997def668d5df2", + "content-hash": "ddd12adbfb90892b90d82377f5b47fb6", "packages": [ { "name": "adhocore/jwt", @@ -279,16 +279,16 @@ }, { "name": "brick/math", - "version": "0.12.2", + "version": "0.12.3", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "901eddb1e45a8e0f689302e40af871c181ecbe40" + "reference": "866551da34e9a618e64a819ee1e01c20d8a588ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/901eddb1e45a8e0f689302e40af871c181ecbe40", - "reference": "901eddb1e45a8e0f689302e40af871c181ecbe40", + "url": "https://api.github.com/repos/brick/math/zipball/866551da34e9a618e64a819ee1e01c20d8a588ba", + "reference": "866551da34e9a618e64a819ee1e01c20d8a588ba", "shasum": "" }, "require": { @@ -327,7 +327,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.12.2" + "source": "https://github.com/brick/math/tree/0.12.3" }, "funding": [ { @@ -335,7 +335,7 @@ "type": "github" } ], - "time": "2025-02-26T10:21:45+00:00" + "time": "2025-02-28T13:11:00+00:00" }, { "name": "chillerlan/php-qrcode", @@ -709,16 +709,16 @@ }, { "name": "google/protobuf", - "version": "v4.29.3", + "version": "v4.30.0", "source": { "type": "git", "url": "https://github.com/protocolbuffers/protobuf-php.git", - "reference": "ab5077c2cfdd1f415f42d11fdbdf903ba8e3d9b7" + "reference": "e1d66682f6836aa87820400f0aa07d9eb566feb6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/ab5077c2cfdd1f415f42d11fdbdf903ba8e3d9b7", - "reference": "ab5077c2cfdd1f415f42d11fdbdf903ba8e3d9b7", + "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/e1d66682f6836aa87820400f0aa07d9eb566feb6", + "reference": "e1d66682f6836aa87820400f0aa07d9eb566feb6", "shasum": "" }, "require": { @@ -747,9 +747,9 @@ "proto" ], "support": { - "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.29.3" + "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.30.0" }, - "time": "2025-01-08T21:00:13+00:00" + "time": "2025-03-04T22:54:49+00:00" }, { "name": "jean85/pretty-package-versions", @@ -2371,16 +2371,16 @@ }, { "name": "ramsey/collection", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/ramsey/collection.git", - "reference": "a4b48764bfbb8f3a6a4d1aeb1a35bb5e9ecac4a5" + "reference": "3c5990b8a5e0b79cd1cf11c2dc1229e58e93f109" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/collection/zipball/a4b48764bfbb8f3a6a4d1aeb1a35bb5e9ecac4a5", - "reference": "a4b48764bfbb8f3a6a4d1aeb1a35bb5e9ecac4a5", + "url": "https://api.github.com/repos/ramsey/collection/zipball/3c5990b8a5e0b79cd1cf11c2dc1229e58e93f109", + "reference": "3c5990b8a5e0b79cd1cf11c2dc1229e58e93f109", "shasum": "" }, "require": { @@ -2388,25 +2388,22 @@ }, "require-dev": { "captainhook/plugin-composer": "^5.3", - "ergebnis/composer-normalize": "^2.28.3", - "fakerphp/faker": "^1.21", + "ergebnis/composer-normalize": "^2.45", + "fakerphp/faker": "^1.24", "hamcrest/hamcrest-php": "^2.0", - "jangregor/phpstan-prophecy": "^1.0", - "mockery/mockery": "^1.5", + "jangregor/phpstan-prophecy": "^2.1", + "mockery/mockery": "^1.6", "php-parallel-lint/php-console-highlighter": "^1.0", - "php-parallel-lint/php-parallel-lint": "^1.3", - "phpcsstandards/phpcsutils": "^1.0.0-rc1", - "phpspec/prophecy-phpunit": "^2.0", - "phpstan/extension-installer": "^1.2", - "phpstan/phpstan": "^1.9", - "phpstan/phpstan-mockery": "^1.1", - "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5", - "psalm/plugin-mockery": "^1.1", - "psalm/plugin-phpunit": "^0.18.4", - "ramsey/coding-standard": "^2.0.3", - "ramsey/conventional-commits": "^1.3", - "vimeo/psalm": "^5.4" + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpspec/prophecy-phpunit": "^2.3", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-mockery": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^10.5", + "ramsey/coding-standard": "^2.3", + "ramsey/conventional-commits": "^1.6", + "roave/security-advisories": "dev-latest" }, "type": "library", "extra": { @@ -2444,19 +2441,9 @@ ], "support": { "issues": "https://github.com/ramsey/collection/issues", - "source": "https://github.com/ramsey/collection/tree/2.0.0" + "source": "https://github.com/ramsey/collection/tree/2.1.0" }, - "funding": [ - { - "url": "https://github.com/ramsey", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/ramsey/collection", - "type": "tidelift" - } - ], - "time": "2022-12-31T21:50:55+00:00" + "time": "2025-03-02T04:48:29+00:00" }, { "name": "ramsey/uuid", @@ -3919,16 +3906,16 @@ }, { "name": "utopia-php/framework", - "version": "0.33.17", + "version": "dev-fix-alias-params", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "73fac6fbce9f56282dba4e52a58cf836ec434644" + "reference": "1d31f755348f78004f870693b4f072e600da2e5a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/73fac6fbce9f56282dba4e52a58cf836ec434644", - "reference": "73fac6fbce9f56282dba4e52a58cf836ec434644", + "url": "https://api.github.com/repos/utopia-php/http/zipball/1d31f755348f78004f870693b4f072e600da2e5a", + "reference": "1d31f755348f78004f870693b4f072e600da2e5a", "shasum": "" }, "require": { @@ -3960,9 +3947,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.17" + "source": "https://github.com/utopia-php/http/tree/fix-alias-params" }, - "time": "2025-02-24T17:35:48+00:00" + "time": "2025-03-04T22:31:03+00:00" }, { "name": "utopia-php/image", @@ -8804,9 +8791,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/framework", + "version": "dev-fix-alias-params", + "alias": "0.33.99", + "alias_normalized": "0.33.99.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/framework": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 157654c486..7880df189e 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Compute; use Appwrite\Event\Build; use Appwrite\Extend\Exception; +use Appwrite\Query; use Utopia\CLI\Console; use Utopia\Database\Database; use Utopia\Database\Document; @@ -197,4 +198,38 @@ class Base extends Action return $deployment; } + + protected function listRules(Document $project, array $queries, Database $database, callable $callback): void + { + $limit = 100; + $cursor = null; + + do { + $queries = \array_merge([ + Query::limit($limit), + Query::equal("projectInternalId", [$project->getInternalId()]) + ], $queries); + + if ($cursor !== null) { + $queries[] = Query::cursorAfter($cursor); + } + + $results = $database->find('rules', $queries); + + $total = \count($results); + if ($total > 0) { + $cursor = $results[$total - 1]; + } + + if ($total < $limit) { + $cursor = null; + } + + foreach ($results as $document) { + if (is_callable($callback)) { + $callback($document); + } + } + } while (!\is_null($cursor)); + } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php similarity index 79% rename from src/Appwrite/Platform/Modules/Functions/Http/Deployments/Update.php rename to src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php index 9647a8bfa3..f45aa0a108 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -1,9 +1,11 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId') - ->desc('Update deployment') + ->setHttpPath('/v1/functions/:functionId/deployment') + ->httpAlias('/v1/functions/:functionId/deployments/:deploymentId') + ->desc('Update function\'s deployment') ->groups(['api', 'functions']) ->label('scope', 'functions.write') ->label('resourceType', RESOURCE_TYPE_FUNCTIONS) @@ -39,7 +42,7 @@ class Update extends Action ->label('audits.resource', 'function/{request.functionId}') ->label('sdk', new Method( namespace: 'functions', - name: 'updateDeployment', + name: 'updateFunctionDeployment', description: <<param('functionId', '', new UID(), 'Function ID.') ->param('deploymentId', '', new UID(), 'Deployment ID.') + ->inject('project') ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') @@ -60,7 +64,7 @@ class Update extends Action ->callback([$this, 'action']); } - public function action(string $functionId, string $deploymentId, Response $response, Database $dbForProject, Event $queueForEvents, Database $dbForPlatform) + public function action(string $functionId, string $deploymentId, Document $project, Response $response, Database $dbForProject, Event $queueForEvents, Database $dbForPlatform) { $function = $dbForProject->getDocument('functions', $functionId); $deployment = $dbForProject->getDocument('deployments', $deploymentId); @@ -95,6 +99,13 @@ class Update extends Action ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); Authorization::skip(fn () => $dbForPlatform->updateDocument('schedules', $schedule->getId(), $schedule)); + $this->listRules($project, [ + Query::equal("automation", ["function=" . $function->getId()]), + ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { + $rule = $rule->setAttribute('value', $deployment->getId()); + $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + }); + $queueForEvents ->setParam('functionId', $function->getId()) ->setParam('deploymentId', $deployment->getId()); diff --git a/src/Appwrite/Platform/Modules/Functions/Services/Http.php b/src/Appwrite/Platform/Modules/Functions/Services/Http.php index 5ae77c5d6b..837dac6619 100644 --- a/src/Appwrite/Platform/Modules/Functions/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Functions/Services/Http.php @@ -9,7 +9,6 @@ use Appwrite\Platform\Modules\Functions\Http\Deployments\Delete as DeleteDeploym 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\Template\Create as CreateTemplateDeployment; -use Appwrite\Platform\Modules\Functions\Http\Deployments\Update as UpdateDeployment; use Appwrite\Platform\Modules\Functions\Http\Deployments\Vcs\Create as CreateVcsDeployment; use Appwrite\Platform\Modules\Functions\Http\Deployments\XList as ListDeployments; use Appwrite\Platform\Modules\Functions\Http\Executions\Create as CreateExecution; @@ -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(UpdateDeployment::getName(), new UpdateDeployment()); + $this->addAction(UpdateFunctionDeployment::getName(), new UpdateFunctionDeployment()); $this->addAction(ListDeployments::getName(), new ListDeployments()); $this->addAction(DeleteDeployment::getName(), new DeleteDeployment()); $this->addAction(CreateTemplateDeployment::getName(), new CreateTemplateDeployment()); diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index aa24182e9a..53556f60ba 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1177,7 +1177,7 @@ class Builds extends Action } } - protected function listRules(Document $project, array $queries, Database $database, callable $callback = null): void + protected function listRules(Document $project, array $queries, Database $database, callable $callback): void { $limit = 100; $cursor = null; diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index b1d67fe26b..f4b6b73784 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -31,7 +31,6 @@ class Get extends Action $this ->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId/download') - ->httpAlias('/v1/sites/:functionId/deployments/:deploymentId/build/download', [ 'type' => 'output' ]) ->desc('Download deployment') ->groups(['api', 'sites']) ->label('scope', 'sites.read') diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php similarity index 77% rename from src/Appwrite/Platform/Modules/Sites/Http/Deployments/Update.php rename to src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php index acc6e30a62..fcb0532929 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -1,9 +1,11 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/sites/:siteId/deployments/:deploymentId') - ->desc('Update deployment') + ->setHttpPath('/v1/sites/:siteId/deployment') + ->desc('Update site\'s deployment') ->groups(['api', 'sites']) ->label('scope', 'sites.write') ->label('resourceType', RESOURCE_TYPE_SITES) @@ -37,7 +39,7 @@ class Update extends Action ->label('audits.resource', 'site/{request.siteId}') ->label('sdk', new Method( namespace: 'sites', - name: 'updateDeployment', + name: 'updateSiteDeployment', description: <<param('siteId', '', new UID(), 'Site ID.') ->param('deploymentId', '', new UID(), 'Deployment ID.') + ->inject('project') ->inject('response') ->inject('dbForProject') ->inject('queueForEvents') @@ -58,7 +61,7 @@ class Update extends Action ->callback([$this, 'action']); } - public function action(string $siteId, string $deploymentId, Response $response, Database $dbForProject, Event $queueForEvents, Database $dbForPlatform) + public function action(string $siteId, string $deploymentId, Document $project, Response $response, Database $dbForProject, Event $queueForEvents, Database $dbForPlatform) { $site = $dbForProject->getDocument('sites', $siteId); $deployment = $dbForProject->getDocument('deployments', $deploymentId); @@ -85,6 +88,13 @@ class Update extends Action 'deploymentId' => $deployment->getId(), ]))); + $this->listRules($project, [ + Query::equal("automation", ["site=" . $site->getId()]), + ], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) { + $rule = $rule->setAttribute('value', $deployment->getId()); + $dbForPlatform->updateDocument('rules', $rule->getId(), $rule); + }); + $queueForEvents ->setParam('siteId', $site->getId()) ->setParam('deploymentId', $deployment->getId()); diff --git a/src/Appwrite/Platform/Modules/Sites/Services/Http.php b/src/Appwrite/Platform/Modules/Sites/Services/Http.php index 7b322900d1..07dc2e5b8a 100644 --- a/src/Appwrite/Platform/Modules/Sites/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Sites/Services/Http.php @@ -9,7 +9,6 @@ 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\Template\Create as CreateTemplateDeployment; -use Appwrite\Platform\Modules\Sites\Http\Deployments\Update as UpdateDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Vcs\Create as CreateVcsDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\XList as ListDeployments; use Appwrite\Platform\Modules\Sites\Http\Frameworks\XList as ListFrameworks; @@ -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(UpdateDeployment::getName(), new UpdateDeployment()); + $this->addAction(UpdateSiteDeployment::getName(), new UpdateSiteDeployment()); $this->addAction(DeleteDeployment::getName(), new DeleteDeployment()); $this->addAction(DownloadDeployment::getName(), new DownloadDeployment()); $this->addAction(CreateBuild::getName(), new CreateBuild()); diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index f97245b0af..b55eea42ac 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -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; + } } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index f4cd9ca493..481f4b8263 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1989,4 +1989,61 @@ class FunctionsCustomServerTest extends Scope $this->cleanupFunction($functionId); } + + public function testUpdateDeploymentStatus(): void + { + + $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); + } } diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 6e597b31ec..08a87991b7 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -359,4 +359,16 @@ trait SitesBase return $response; } + + protected function updateSiteDeployment(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; + } } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 3e6132c845..89e05cfe2f 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -767,11 +767,7 @@ class SitesCustomServerTest extends Scope */ $dateValidator = new DatetimeValidator(); - $response = $this->client->call(Client::METHOD_PATCH, '/sites/' . $siteId . '/deployments/' . $deploymentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - + $response = $this->updateSiteDeployment($siteId, $deploymentId); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); $this->assertEquals(true, $dateValidator->isValid($response['body']['$createdAt'])); @@ -1747,4 +1743,59 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testUpdateDeploymentStatus(): void + { + $siteId = $this->setupSite([ + 'buildRuntime' => 'ssr-22', + 'framework' => 'other', + 'name' => 'Activate test Site', + 'siteId' => ID::unique(), + 'adapter' => 'static', + ]); + $this->assertNotEmpty($siteId); + + $domain = $this->setupSiteDomain($siteId); + $this->assertNotEmpty($domain); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $deploymentId1 = $this->setupDeployment($siteId, [ + 'code' => $this->packageSite('static'), + 'activate' => true + ]); + $this->assertNotEmpty($deploymentId1); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString('Hello Appwrite', $response['body']); + + $deploymentId2 = $this->setupDeployment($siteId, [ + 'code' => $this->packageSite('static-spa'), + 'activate' => true + ]); + $this->assertNotEmpty($deploymentId2); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString('Index page', $response['body']); + + $function = $this->getSite($siteId); + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals($deploymentId2, $function['body']['deploymentId']); + + $function = $this->updateSiteDeployment($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']); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString('Hello Appwrite', $response['body']); + + $this->cleanupSite($siteId); + } }