diff --git a/src/Appwrite/Utopia/Request/Filters/V18.php b/src/Appwrite/Utopia/Request/Filters/V18.php index 8564dad47b..20241e34a7 100644 --- a/src/Appwrite/Utopia/Request/Filters/V18.php +++ b/src/Appwrite/Utopia/Request/Filters/V18.php @@ -14,7 +14,7 @@ class V18 extends Filter unset($content['otp']); break; case 'functions.create': - $content['templateVersion'] = $content['templateBranch']; + $content['templateVersion'] = $content['templateBranch'] ?? ""; unset($content['templateBranch']); break; } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index b4d120d604..925bda5281 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -454,8 +454,8 @@ class FunctionsCustomServerTest extends Scope $entrypoint = null; $rootDirectory = null; $commands = null; - foreach($template['body']['runtimes'] as $runtime) { - if($runtime["name"] !== $runtimeName) { + foreach ($template['body']['runtimes'] as $runtime) { + if ($runtime["name"] !== $runtimeName) { continue; } @@ -2419,4 +2419,30 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } + + public function testCreateFunctionWithResponseFormatHeader() + { + $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-response-format' => '1.5.0', // add response format header + ], $this->getHeaders()), [ + 'functionId' => ID::unique(), + 'name' => 'Test', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'timeout' => 15, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + // Cleanup : Delete function + $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $response['body']['$id'], [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], []); + + $this->assertEquals(204, $response['headers']['status-code']); + } }