From b621ec2e8bdf5f7bda51da1e63e4708dd3ff1f9d Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:50:30 +0530 Subject: [PATCH 1/5] test for response and request filters --- .../Functions/FunctionsCustomServerTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index dccbf2e544..4dabec67f0 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2685,6 +2685,27 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); + // get function with 1.5.0 response format + $function = $this->client->call(Client::METHOD_GET, '/functions/' . $response['body']['$id'], 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())); + + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertArrayNotHasKey('scopes', $function['body']); + $this->assertArrayNotHasKey('specification', $function['body']); + + // get function without response format header + $function = $this->client->call(Client::METHOD_GET, '/functions/' . $response['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $function['headers']['status-code']); + $this->assertArrayHasKey('scopes', $function['body']); + $this->assertArrayHasKey('specification', $function['body']); + // Cleanup : Delete function $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $response['body']['$id'], [ 'content-type' => 'application/json', From 5f97aafe4604e535cf437115d82f9db000acbdf8 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:38:30 +0530 Subject: [PATCH 2/5] More asserts --- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 4dabec67f0..f101524aaf 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2669,8 +2669,9 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } - public function testCreateFunctionWithResponseFormatHeader() + public function testResponseFilters() { + // create function with 1.5.0 response format $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -2684,8 +2685,10 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals(201, $response['headers']['status-code']); + $this->assertArrayNotHasKey('scopes', $response['body']); + $this->assertArrayNotHasKey('specification', $response['body']); - // get function with 1.5.0 response format + // get function with 1.5.0 response format header $function = $this->client->call(Client::METHOD_GET, '/functions/' . $response['body']['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], From fdf73f8a7ae7129f5a82a235bcf18f5e337d9e23 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 25 Sep 2024 23:36:00 +0530 Subject: [PATCH 3/5] Add test for request filters --- .../Functions/FunctionsCustomServerTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index f101524aaf..d4adc1119f 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2719,6 +2719,55 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } + public function testRequestFilters() + { + // create function + $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'functionId' => ID::unique(), + 'name' => 'Test', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'timeout' => 15, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + // create another function + $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'functionId' => ID::unique(), + 'name' => 'Test2', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'timeout' => 15, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + // list functions using request filters + $response = $this->client->call( + Client::METHOD_GET, + '/functions', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-response-format' => '1.4.0', // Set response format for 1.4 syntax + ], $this->getHeaders()), + [ + 'queries' => [ 'equal("name", ["Test2"])' ] + ] + ); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertCount(1, $response['body']['functions']); + $this->assertEquals('Test2', $response['body']['functions'][0]['name']); + } + public function testFunctionLogging() { // Preparations: Create Function From ef6ed675b3051bd0b49e0d643860499598c100ab Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:26:31 +0530 Subject: [PATCH 4/5] Fix request response filter tests --- .../Functions/FunctionsCustomServerTest.php | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 571f528805..976553059b 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1791,6 +1791,7 @@ class FunctionsCustomServerTest extends Scope public function testResponseFilters() { + // create function with 1.5.0 response format $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1803,27 +1804,6 @@ class FunctionsCustomServerTest extends Scope 'timeout' => 15, ]); - $this->assertEquals(201, $response['headers']['status-code']); - - $functionId = $function['body']['$id'] ?? ''; - - $this->cleanupFunction($functionId); - } - - public function testRequestFilters() - { - // create function with 1.5.0 response format header - $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'functionId' => ID::unique(), - 'name' => 'Test', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - 'timeout' => 15, - ]); - $this->assertEquals(201, $response['headers']['status-code']); $this->assertArrayNotHasKey('scopes', $response['body']); $this->assertArrayNotHasKey('specification', $response['body']); @@ -1849,6 +1829,27 @@ class FunctionsCustomServerTest extends Scope $this->assertArrayHasKey('scopes', $function['body']); $this->assertArrayHasKey('specification', $function['body']); + $functionId = $function['body']['$id'] ?? ''; + $this->cleanupFunction($functionId); + } + + public function testRequestFilters() + { + // create function + $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'functionId' => ID::unique(), + 'name' => 'Test', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'timeout' => 15, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $function1Id = $response['body']['$id']; + // create another function $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ 'content-type' => 'application/json', @@ -1862,6 +1863,7 @@ class FunctionsCustomServerTest extends Scope ]); $this->assertEquals(201, $response['headers']['status-code']); + $function2Id = $response['body']['$id']; // list functions using request filters $response = $this->client->call( @@ -1880,6 +1882,9 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertCount(1, $response['body']['functions']); $this->assertEquals('Test2', $response['body']['functions'][0]['name']); + + $this->cleanupFunction($function1Id); + $this->cleanupFunction($function2Id); } public function testFunctionLogging() From 34527efc79add92c10faf0f9f5eec9d1494e90a1 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:07:01 +0530 Subject: [PATCH 5/5] Use helper functions --- .../Functions/FunctionsCustomServerTest.php | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 976553059b..59a3041a3f 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1819,11 +1819,7 @@ class FunctionsCustomServerTest extends Scope $this->assertArrayNotHasKey('scopes', $function['body']); $this->assertArrayNotHasKey('specification', $function['body']); - // get function without response format header - $function = $this->client->call(Client::METHOD_GET, '/functions/' . $response['body']['$id'], array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders())); + $function = $this->getFunction($function['body']['$id']); $this->assertEquals(200, $function['headers']['status-code']); $this->assertArrayHasKey('scopes', $function['body']); @@ -1835,36 +1831,24 @@ class FunctionsCustomServerTest extends Scope public function testRequestFilters() { - // create function - $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ + $function1Id = $this->setupFunction([ 'functionId' => ID::unique(), 'name' => 'Test', 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'timeout' => 15, + 'execute' => ['any'] ]); - $this->assertEquals(201, $response['headers']['status-code']); - $function1Id = $response['body']['$id']; - - // create another function - $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ + $function2Id = $this->setupFunction([ 'functionId' => ID::unique(), 'name' => 'Test2', 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'timeout' => 15, + 'execute' => ['any'] ]); - $this->assertEquals(201, $response['headers']['status-code']); - $function2Id = $response['body']['$id']; - // list functions using request filters $response = $this->client->call( Client::METHOD_GET,