diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index a00e40b03a..64e53f6799 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -777,7 +777,6 @@ return [ 'filters' => [], ], [ - // At the moment, always empty (no runtime supports it yet) 'array' => false, '$id' => ID::custom('startCommand'), 'type' => Database::VAR_STRING, diff --git a/src/Appwrite/Utopia/Response/Filters/V21.php b/src/Appwrite/Utopia/Response/Filters/V21.php index c825b3df56..aff2536456 100644 --- a/src/Appwrite/Utopia/Response/Filters/V21.php +++ b/src/Appwrite/Utopia/Response/Filters/V21.php @@ -32,6 +32,7 @@ class V21 extends Filter protected function parseSite(array $content): array { $content = $this->parseSpecs($content); + unset($content['startCommand']); return $content; } @@ -46,6 +47,7 @@ class V21 extends Filter $content['specification'] = $content['buildSpecification'] ?? null; unset($content['buildSpecification']); unset($content['runtimeSpecification']); + unset($content['deploymentRetention']); return $content; } } diff --git a/tests/unit/Utopia/Response/Filters/V21Test.php b/tests/unit/Utopia/Response/Filters/V21Test.php new file mode 100644 index 0000000000..0e5bfb9c55 --- /dev/null +++ b/tests/unit/Utopia/Response/Filters/V21Test.php @@ -0,0 +1,190 @@ +filter = new V21(); + } + + public function tearDown(): void + { + } + + public static function functionProvider(): array + { + return [ + 'convert buildSpecification to specification and remove new fields' => [ + [ + 'buildSpecification' => 's-1vcpu-512mb', + 'runtimeSpecification' => 's-1vcpu-512mb', + 'deploymentRetention' => 7, + 'name' => 'my-function', + ], + [ + 'specification' => 's-1vcpu-512mb', + 'name' => 'my-function', + ] + ], + 'handle missing buildSpecification' => [ + [ + 'deploymentRetention' => 0, + 'name' => 'my-function', + ], + [ + 'specification' => null, + 'name' => 'my-function', + ] + ], + ]; + } + + #[DataProvider('functionProvider')] + public function testFunction(array $content, array $expected): void + { + $model = Response::MODEL_FUNCTION; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public static function functionListProvider(): array + { + return [ + 'convert list of functions' => [ + [ + 'total' => 2, + 'functions' => [ + [ + 'buildSpecification' => 's-1vcpu-512mb', + 'runtimeSpecification' => 's-1vcpu-512mb', + 'deploymentRetention' => 7, + 'name' => 'function-1', + ], + [ + 'buildSpecification' => 's-2vcpu-1gb', + 'runtimeSpecification' => 's-1vcpu-512mb', + 'deploymentRetention' => 0, + 'name' => 'function-2', + ], + ], + ], + [ + 'total' => 2, + 'functions' => [ + [ + 'specification' => 's-1vcpu-512mb', + 'name' => 'function-1', + ], + [ + 'specification' => 's-2vcpu-1gb', + 'name' => 'function-2', + ], + ], + ] + ], + ]; + } + + #[DataProvider('functionListProvider')] + public function testFunctionList(array $content, array $expected): void + { + $model = Response::MODEL_FUNCTION_LIST; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public static function siteProvider(): array + { + return [ + 'convert buildSpecification to specification and remove new fields' => [ + [ + 'buildSpecification' => 's-1vcpu-512mb', + 'runtimeSpecification' => 's-1vcpu-512mb', + 'deploymentRetention' => 7, + 'startCommand' => 'node custom-server.js', + 'name' => 'my-site', + ], + [ + 'specification' => 's-1vcpu-512mb', + 'name' => 'my-site', + ] + ], + 'handle missing buildSpecification' => [ + [ + 'deploymentRetention' => 0, + 'startCommand' => '', + 'name' => 'my-site', + ], + [ + 'specification' => null, + 'name' => 'my-site', + ] + ], + ]; + } + + #[DataProvider('siteProvider')] + public function testSite(array $content, array $expected): void + { + $model = Response::MODEL_SITE; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public static function siteListProvider(): array + { + return [ + 'convert list of sites' => [ + [ + 'total' => 1, + 'sites' => [ + [ + 'buildSpecification' => 's-1vcpu-512mb', + 'runtimeSpecification' => 's-1vcpu-512mb', + 'deploymentRetention' => 7, + 'startCommand' => 'node custom-server.js', + 'name' => 'site-1', + ], + ], + ], + [ + 'total' => 1, + 'sites' => [ + [ + 'specification' => 's-1vcpu-512mb', + 'name' => 'site-1', + ], + ], + ] + ], + ]; + } + + #[DataProvider('siteListProvider')] + public function testSiteList(array $content, array $expected): void + { + $model = Response::MODEL_SITE_LIST; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } +}