diff --git a/src/Appwrite/Utopia/Request/Filters/V19.php b/src/Appwrite/Utopia/Request/Filters/V19.php index 041c126a69..31296b2eb2 100644 --- a/src/Appwrite/Utopia/Request/Filters/V19.php +++ b/src/Appwrite/Utopia/Request/Filters/V19.php @@ -9,16 +9,17 @@ class V19 extends Filter // Convert 1.6 params to 1.7 public function parse(array $content, string $model): array { - /* - Uncomment with first request filter; current is just a copy of V18 switch ($model) { case 'functions.create': - $content['something'] = $content['somethingElse'] ?? ""; - unset($content['something']); + unset($content['templateRepository']); + unset($content['templateOwner']); + unset($content['templateRootDirectory']); + unset($content['templateVersion']); + break; + case 'functions.listExecutions': + unset($content['search']); break; } - */ - return $content; } } diff --git a/src/Appwrite/Utopia/Response/Filters/V19.php b/src/Appwrite/Utopia/Response/Filters/V19.php index 2987c5a7e4..8ab430e569 100644 --- a/src/Appwrite/Utopia/Response/Filters/V19.php +++ b/src/Appwrite/Utopia/Response/Filters/V19.php @@ -15,6 +15,15 @@ class V19 extends Filter $parsedResponse = match($model) { Response::MODEL_FUNCTION => $this->parseFunction($content), Response::MODEL_FUNCTION_LIST => $this->handleList($content, 'functions', fn ($item) => $this->parseFunction($item)), + Response::MODEL_DEPLOYMENT => $this->parseDeployment($content), + Response::MODEL_PROXY_RULE => $this->parseProxyRule($content), + Response::MODEL_MIGRATION => $this->parseMigration($content), + Response::MODEL_PROJECT => $this->parseProject($content), + Response::MODEL_PROVIDER_REPOSITORY => $this->parseProviderRepository($content), + Response::MODEL_TEMPLATE_VARIABLE => $this->parseTemplateVariable($content), + Response::MODEL_USAGE_FUNCTION => $this->parseUsageFunction($content), + Response::MODEL_USAGE_FUNCTIONS => $this->parseUsageFunctions($content), + Response::MODEL_VARIABLE => $this->parseVariable($content), default => $parsedResponse, }; @@ -25,6 +34,86 @@ class V19 extends Filter { $content['deployment'] = $content['deploymentId'] ?? ''; unset($content['deploymentId']); + unset($content['deploymentCreatedAt']); + unset($content['latestDeploymentId']); + unset($content['latestDeploymentCreatedAt']); + unset($content['latestDeploymentStatus']); + return $content; + } + + protected function parseDeployment(array $content) + { + $content['size'] = $content['sourceSize'] ?? ''; + $content['buildTime'] = $content['buildDuration'] ?? ''; + unset($content['sourceSize']); + unset($content['buildDuration']); + unset($content['totalSize']); + unset($content['screenshotLight']); + unset($content['screenshotDark']); + return $content; + } + + protected function parseProxyRule(array $content) + { + $content['resourceType'] = $content['deploymentResourceType'] ?? ''; + $content['resourceId'] = $content['deploymentResourceId'] ?? ''; + unset($content['deploymentResourceType']); + unset($content['deploymentResourceId']); + unset($content['type']); + unset($content['trigger']); + unset($content['triggerData']); + unset($content['redirectStatusCode']); + unset($content['deploymentId']); + unset($content['deploymentVcsProviderBranch']); + return $content; + } + + protected function parseMigration(array $content) + { + unset($content['resourceId']); + return $content; + } + + protected function parseProject(array $content) + { + unset($content['devKeys']); + return $content; + } + + protected function parseProviderRepository(array $content) + { + unset($content['runtime']); + return $content; + } + + protected function parseTemplateVariable(array $content) + { + unset($content['secret']); + return $content; + } + + protected function parseUsageFunction(array $content) + { + unset($content['buildsSuccessTotal']); + unset($content['buildsFailedTotal']); + unset($content['buildsTimeAverage']); + unset($content['buildsSuccess']); + unset($content['buildsFailed']); + return $content; + } + + protected function parseUsageFunctions(array $content) + { + unset($content['buildsSuccessTotal']); + unset($content['buildsFailedTotal']); + unset($content['buildsSuccess']); + unset($content['buildsFailed']); + return $content; + } + + protected function parseVariable(array $content) + { + unset($content['secret']); return $content; } } diff --git a/tests/unit/Utopia/Request/Filters/V19Test.php b/tests/unit/Utopia/Request/Filters/V19Test.php new file mode 100644 index 0000000000..418951705e --- /dev/null +++ b/tests/unit/Utopia/Request/Filters/V19Test.php @@ -0,0 +1,85 @@ +filter = new V19(); + } + + public function tearDown(): void + { + } + + public function functionsCreateProvider() + { + return [ + 'remove template fields' => [ + [ + 'name' => 'test-function', + 'runtime' => 'node-18.0', + 'templateRepository' => 'github.com/appwrite/templates', + 'templateOwner' => 'appwrite', + 'templateRootDirectory' => 'functions/node', + 'templateVersion' => '1.0.0' + ], + [ + 'name' => 'test-function', + 'runtime' => 'node-18.0' + ] + ] + ]; + } + + public function functionsListExecutionsProvider() + { + return [ + 'remove search field' => [ + [ + 'functionId' => 'test-function', + 'search' => 'test query', + 'limit' => 10 + ], + [ + 'functionId' => 'test-function', + 'limit' => 10 + ] + ] + ]; + } + + /** + * @dataProvider functionsCreateProvider + */ + public function testFunctionsCreate(array $content, array $expected): void + { + $model = 'functions.create'; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider functionsListExecutionsProvider + */ + public function testFunctionsListExecutions(array $content, array $expected): void + { + $model = 'functions.listExecutions'; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } +} diff --git a/tests/unit/Utopia/Response/Filters/V19Test.php b/tests/unit/Utopia/Response/Filters/V19Test.php new file mode 100644 index 0000000000..7d413bdd37 --- /dev/null +++ b/tests/unit/Utopia/Response/Filters/V19Test.php @@ -0,0 +1,447 @@ +filter = new V19(); + } + + public function tearDown(): void + { + } + + public function functionProvider(): array + { + return [ + 'change deploymentId to deployment' => [ + [ + 'deploymentId' => 'deployment123', + ], + [ + 'deployment' => 'deployment123', + ] + ], + 'handle empty deploymentId' => [ + [ + 'name' => 'test-function', + ], + [ + 'deployment' => '', + 'name' => 'test-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 function functionListProvider(): array + { + return [ + 'convert list of functions' => [ + [ + 'total' => 2, + 'functions' => [ + [ + 'deploymentId' => 'deployment123', + 'name' => 'function-1', + ], + [ + 'deploymentId' => 'deployment456', + 'name' => 'function-2', + ], + ], + ], + [ + 'total' => 2, + 'functions' => [ + [ + 'deployment' => 'deployment123', + 'name' => 'function-1', + ], + [ + 'deployment' => 'deployment456', + 'name' => 'function-2', + ], + ], + ] + ], + 'handle empty function list' => [ + [ + 'total' => 0, + 'functions' => [], + ], + [ + 'total' => 0, + 'functions' => [], + ] + ], + ]; + } + + /** + * @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 function deploymentProvider(): array + { + return [ + 'rename sourceSize to size and buildDuration to buildTime' => [ + [ + 'sourceSize' => 1024, + 'buildDuration' => 60, + 'id' => 'deployment123', + ], + [ + 'size' => 1024, + 'buildTime' => 60, + 'id' => 'deployment123', + ] + ], + 'handle missing sourceSize and buildDuration' => [ + [ + 'id' => 'deployment123', + ], + [ + 'size' => '', + 'buildTime' => '', + 'id' => 'deployment123', + ] + ], + ]; + } + + /** + * @dataProvider deploymentProvider + */ + public function testDeployment(array $content, array $expected): void + { + $model = Response::MODEL_DEPLOYMENT; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public function proxyRuleProvider(): array + { + return [ + 'rename deployment resource fields' => [ + [ + 'deploymentResourceType' => 'function', + 'deploymentResourceId' => 'func123', + 'domain' => 'example.com', + ], + [ + 'resourceType' => 'function', + 'resourceId' => 'func123', + 'domain' => 'example.com', + ] + ], + 'handle missing deployment resource fields' => [ + [ + 'domain' => 'example.com', + ], + [ + 'resourceType' => '', + 'resourceId' => '', + 'domain' => 'example.com', + ] + ], + ]; + } + + /** + * @dataProvider proxyRuleProvider + */ + public function testProxyRule(array $content, array $expected): void + { + $model = Response::MODEL_PROXY_RULE; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public function migrationProvider(): array + { + return [ + 'remove resourceId field' => [ + [ + 'resourceId' => 'resource123', + 'status' => 'completed', + ], + [ + 'status' => 'completed', + ] + ], + 'handle content without resourceId' => [ + [ + 'status' => 'completed', + ], + [ + 'status' => 'completed', + ] + ], + ]; + } + + /** + * @dataProvider migrationProvider + */ + public function testMigration(array $content, array $expected): void + { + $model = Response::MODEL_MIGRATION; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public function projectProvider(): array + { + return [ + 'remove devKeys field' => [ + [ + 'devKeys' => ['key1', 'key2'], + 'name' => 'test-project', + ], + [ + 'name' => 'test-project', + ] + ], + 'handle content without devKeys' => [ + [ + 'name' => 'test-project', + ], + [ + 'name' => 'test-project', + ] + ], + ]; + } + + /** + * @dataProvider projectProvider + */ + public function testProject(array $content, array $expected): void + { + $model = Response::MODEL_PROJECT; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public function providerRepositoryProvider(): array + { + return [ + 'remove runtime field' => [ + [ + 'runtime' => 'nodejs', + 'name' => 'test-repo', + ], + [ + 'name' => 'test-repo', + ] + ], + 'handle content without runtime' => [ + [ + 'name' => 'test-repo', + ], + [ + 'name' => 'test-repo', + ] + ], + ]; + } + + /** + * @dataProvider providerRepositoryProvider + */ + public function testProviderRepository(array $content, array $expected): void + { + $model = Response::MODEL_PROVIDER_REPOSITORY; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public function templateVariableProvider(): array + { + return [ + 'remove secret field' => [ + [ + 'secret' => 'secret-value', + 'name' => 'test-variable', + ], + [ + 'name' => 'test-variable', + ] + ], + 'handle content without secret' => [ + [ + 'name' => 'test-variable', + ], + [ + 'name' => 'test-variable', + ] + ], + ]; + } + + /** + * @dataProvider templateVariableProvider + */ + public function testTemplateVariable(array $content, array $expected): void + { + $model = Response::MODEL_TEMPLATE_VARIABLE; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public function usageFunctionProvider(): array + { + return [ + 'remove build-related fields' => [ + [ + 'buildsSuccessTotal' => 10, + 'buildsFailedTotal' => 2, + 'buildsTimeAverage' => 30, + 'buildsSuccess' => 5, + 'buildsFailed' => 1, + 'executions' => 100, + ], + [ + 'executions' => 100, + ] + ], + 'handle content without build fields' => [ + [ + 'executions' => 100, + ], + [ + 'executions' => 100, + ] + ], + ]; + } + + /** + * @dataProvider usageFunctionProvider + */ + public function testUsageFunction(array $content, array $expected): void + { + $model = Response::MODEL_USAGE_FUNCTION; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public function usageFunctionsProvider(): array + { + return [ + 'remove build-related fields' => [ + [ + 'buildsSuccessTotal' => 20, + 'buildsFailedTotal' => 4, + 'buildsSuccess' => 10, + 'buildsFailed' => 2, + 'executions' => 200, + ], + [ + 'executions' => 200, + ] + ], + 'handle content without build fields' => [ + [ + 'executions' => 200, + ], + [ + 'executions' => 200, + ] + ], + ]; + } + + /** + * @dataProvider usageFunctionsProvider + */ + public function testUsageFunctions(array $content, array $expected): void + { + $model = Response::MODEL_USAGE_FUNCTIONS; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } + + public function variableProvider(): array + { + return [ + 'remove secret field' => [ + [ + 'secret' => 'secret-value', + 'name' => 'test-variable', + ], + [ + 'name' => 'test-variable', + ] + ], + 'handle content without secret' => [ + [ + 'name' => 'test-variable', + ], + [ + 'name' => 'test-variable', + ] + ], + ]; + } + + /** + * @dataProvider variableProvider + */ + public function testVariable(array $content, array $expected): void + { + $model = Response::MODEL_VARIABLE; + + $result = $this->filter->parse($content, $model); + + $this->assertEquals($expected, $result); + } +}