From 4cfd977bd7ddb9344840308e44891e996c51eb1d Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Thu, 4 Jan 2024 00:06:50 +0000 Subject: [PATCH] Add support for querying topic total --- .../Database/Validator/Queries/Topics.php | 1 + .../e2e/Services/Messaging/MessagingBase.php | 37 ++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Topics.php b/src/Appwrite/Utopia/Database/Validator/Queries/Topics.php index 120b3edc3f..27c818d319 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Topics.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Topics.php @@ -7,6 +7,7 @@ class Topics extends Base public const ALLOWED_ATTRIBUTES = [ 'name', 'description', + 'total' ]; /** diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 690e503e77..1feaf15385 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -5,6 +5,7 @@ namespace Tests\E2E\Services\Messaging; use Tests\E2E\Client; use Utopia\App; use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; use Utopia\DSN\DSN; trait MessagingBase @@ -161,11 +162,11 @@ trait MessagingBase 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], ], [ - 'name' => 'Mailgun2', - 'apiKey' => 'my-apikey', - 'domain' => 'my-domain', - 'isEuRegion' => true, - 'enabled' => false, + 'name' => 'Mailgun2', + 'apiKey' => 'my-apikey', + 'domain' => 'my-domain', + 'isEuRegion' => true, + 'enabled' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('Mailgun2', $response['body']['name']); @@ -272,6 +273,32 @@ trait MessagingBase $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, \count($response['body']['topics'])); + $response = $this->client->call(Client::METHOD_GET, '/messaging/topics', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'queries' => [ + 'equal("total", [0])' + ], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, \count($response['body']['topics'])); + + $response = $this->client->call(Client::METHOD_GET, '/messaging/topics', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'queries' => [ + 'greaterThan("total", 0)' + ], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(0, \count($response['body']['topics'])); + return $topicId; }