From f4fb3e3c7551683241e62c6870575c7a079fd9e4 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:26:19 +0530 Subject: [PATCH 1/3] Default fallback to for templateBranch --- src/Appwrite/Utopia/Request/Filters/V18.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From e36c8786ea7d9525b68f6ab03a39600ec4048e65 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:50:19 +0530 Subject: [PATCH 2/3] Add test for response format --- .../Functions/FunctionsCustomServerTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 1e40a2a657..a931fa4a4a 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -88,6 +88,40 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(201, $variable2['headers']['status-code']); $this->assertEquals(201, $variable3['headers']['status-code']); + $response2 = $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', + ], $this->getHeaders()), [ + 'functionId' => ID::unique(), + 'name' => 'Test', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'events' => [ + 'buckets.*.create', + 'buckets.*.delete', + ], + 'schedule' => '0 0 1 1 *', + 'timeout' => 10, + ]); + + $this->assertEquals(201, $response2['headers']['status-code']); + $this->assertNotEmpty($response2['body']['$id']); + $this->assertEquals('Test', $response2['body']['name']); + $this->assertEquals('php-8.0', $response2['body']['runtime']); + $this->assertEquals(true, $dateValidator->isValid($response2['body']['$createdAt'])); + $this->assertEquals(true, $dateValidator->isValid($response2['body']['$updatedAt'])); + + $functionId2 = $response2['body']['$id']; + + $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId2, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], []); + + $this->assertEquals(204, $response['headers']['status-code']); + /** * Test for FAILURE */ From 0960a0cd3c0726c402a2e6d11c4461407f78bbeb Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:01:15 +0530 Subject: [PATCH 3/3] Update tests --- .../Functions/FunctionsCustomServerTest.php | 64 ++++++++----------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index a931fa4a4a..c3a36424d8 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -88,40 +88,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(201, $variable2['headers']['status-code']); $this->assertEquals(201, $variable3['headers']['status-code']); - $response2 = $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', - ], $this->getHeaders()), [ - 'functionId' => ID::unique(), - 'name' => 'Test', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - 'events' => [ - 'buckets.*.create', - 'buckets.*.delete', - ], - 'schedule' => '0 0 1 1 *', - 'timeout' => 10, - ]); - - $this->assertEquals(201, $response2['headers']['status-code']); - $this->assertNotEmpty($response2['body']['$id']); - $this->assertEquals('Test', $response2['body']['name']); - $this->assertEquals('php-8.0', $response2['body']['runtime']); - $this->assertEquals(true, $dateValidator->isValid($response2['body']['$createdAt'])); - $this->assertEquals(true, $dateValidator->isValid($response2['body']['$updatedAt'])); - - $functionId2 = $response2['body']['$id']; - - $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId2, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], []); - - $this->assertEquals(204, $response['headers']['status-code']); - /** * Test for FAILURE */ @@ -488,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; } @@ -2452,4 +2418,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']); + } }