From df9f4ffb040cff4122de358a0bf72a2cee7ab675 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 29 Jul 2024 19:09:48 +0530 Subject: [PATCH] Add tests for filtering and pagination --- .../Functions/FunctionsCustomClientTest.php | 39 +++++++++++++++++++ .../Functions/FunctionsCustomServerTest.php | 14 ------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 4e501692fa..4be2d1d893 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -963,4 +963,43 @@ class FunctionsCustomClientTest extends Scope return []; } + + public function testGetFunctionTemplates() + { + $templates = $this->client->call(Client::METHOD_GET, '/functions/templates', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $templates['headers']['status-code']); + $this->assertGreaterThan(0, $templates['body']['total']); + $this->assertIsArray($templates['body']['templates']); + $this->assertArrayHasKey('runtimes', $templates['body']['templates'][0]); + + $templates = $this->client->call(Client::METHOD_GET, '/functions/templates', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'usecases' => ['starter', 'ai'], + 'runtimes' => ['bun-1.0', 'dart-2.16'] + ]); + + $this->assertEquals(200, $templates['headers']['status-code']); + $this->assertEquals(3, $templates['body']['total']); + $this->assertIsArray($templates['body']['templates']); + $this->assertArrayHasKey('runtimes', $templates['body']['templates'][0]); + + $templates = $this->client->call(Client::METHOD_GET, '/functions/templates', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 10, + 'offset' => 2, + ]); + + $this->assertEquals(200, $templates['headers']['status-code']); + $this->assertEquals(10, $templates['body']['total']); + $this->assertIsArray($templates['body']['templates']); + $this->assertArrayHasKey('runtimes', $templates['body']['templates'][0]); + } } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index bed86a1d72..c9f9e4443f 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -2097,18 +2097,4 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } - - public function testGetFunctionTemplates() - { - $templates = $this->client->call(Client::METHOD_GET, '/functions/templates', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], $this->getHeaders())); - - $this->assertEquals(200, $templates['headers']['status-code']); - $this->assertGreaterThan(0, $templates['body']['total']); - $this->assertIsArray($templates['body']['templates']); - $this->assertArrayHasKey('runtimes', $templates['body']['templates'][0]); - } }