diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 62beca5ce3..a17c1bf468 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -553,12 +553,13 @@ App::get('/v1/account/sessions') ], contentType: ContentType::JSON, )) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('user') ->inject('locale') ->inject('store') ->inject('proofForToken') - ->action(function (Response $response, Document $user, Locale $locale, Store $store, ProofsToken $proofForToken) { + ->action(function (bool $includeTotal, Response $response, Document $user, Locale $locale, Store $store, ProofsToken $proofForToken) { $sessions = $user->getAttribute('sessions', []); @@ -576,7 +577,7 @@ App::get('/v1/account/sessions') $response->dynamic(new Document([ 'sessions' => $sessions, - 'total' => count($sessions), + 'total' => $includeTotal ? count($sessions) : 0, ]), Response::MODEL_SESSION_LIST); }); @@ -2879,12 +2880,13 @@ App::get('/v1/account/logs') contentType: ContentType::JSON, )) ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('user') ->inject('locale') ->inject('geodb') ->inject('dbForProject') - ->action(function (array $queries, Response $response, Document $user, Locale $locale, Reader $geodb, Database $dbForProject) { + ->action(function (array $queries, bool $includeTotal, Response $response, Document $user, Locale $locale, Reader $geodb, Database $dbForProject) { try { $queries = Query::parseQueries($queries); @@ -2929,7 +2931,7 @@ App::get('/v1/account/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByUser($user->getSequence(), $queries), + 'total' => $includeTotal ? $audit->countLogsByUser($user->getSequence(), $queries) : 0, 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 6f2ce1bbb4..0ad0f5ea1b 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -1054,11 +1054,12 @@ App::get('/v1/messaging/providers/:providerId/logs') )) ->param('providerId', '', new UID(), 'Provider ID.') ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->inject('locale') ->inject('geodb') - ->action(function (string $providerId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { + ->action(function (string $providerId, array $queries, bool $includeTotal, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { @@ -1126,7 +1127,7 @@ App::get('/v1/messaging/providers/:providerId/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByResource($resource, $queries), + 'total' => $includeTotal ? $audit->countLogsByResource($resource, $queries) : 0, 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); @@ -2362,11 +2363,12 @@ App::get('/v1/messaging/topics/:topicId/logs') )) ->param('topicId', '', new UID(), 'Topic ID.') ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->inject('locale') ->inject('geodb') - ->action(function (string $topicId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { + ->action(function (string $topicId, array $queries, bool $includeTotal, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $topic = $dbForProject->getDocument('topics', $topicId); if ($topic->isEmpty()) { @@ -2435,7 +2437,7 @@ App::get('/v1/messaging/topics/:topicId/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByResource($resource, $queries), + 'total' => $includeTotal ? $audit->countLogsByResource($resource, $queries) : 0, 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); @@ -2783,11 +2785,12 @@ App::get('/v1/messaging/subscribers/:subscriberId/logs') )) ->param('subscriberId', '', new UID(), 'Subscriber ID.') ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->inject('locale') ->inject('geodb') - ->action(function (string $subscriberId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { + ->action(function (string $subscriberId, array $queries, bool $includeTotal, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $subscriber = $dbForProject->getDocument('subscribers', $subscriberId); if ($subscriber->isEmpty()) { @@ -2856,7 +2859,7 @@ App::get('/v1/messaging/subscribers/:subscriberId/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByResource($resource, $queries), + 'total' => $includeTotal ? $audit->countLogsByResource($resource, $queries) : 0, 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); @@ -3582,11 +3585,12 @@ App::get('/v1/messaging/messages/:messageId/logs') )) ->param('messageId', '', new UID(), 'Message ID.') ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->inject('locale') ->inject('geodb') - ->action(function (string $messageId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { + ->action(function (string $messageId, array $queries, bool $includeTotal, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $message = $dbForProject->getDocument('messages', $messageId); if ($message->isEmpty()) { @@ -3655,7 +3659,7 @@ App::get('/v1/messaging/messages/:messageId/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByResource($resource, $queries), + 'total' => $includeTotal ? $audit->countLogsByResource($resource, $queries) : 0, 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index b4c6f28a1b..bed07235e8 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -1445,11 +1445,12 @@ App::get('/v1/teams/:teamId/logs') )) ->param('teamId', '', new UID(), 'Team ID.') ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->inject('locale') ->inject('geodb') - ->action(function (string $teamId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { + ->action(function (string $teamId, array $queries, bool $includeTotal, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $team = $dbForProject->getDocument('teams', $teamId); @@ -1518,7 +1519,7 @@ App::get('/v1/teams/:teamId/logs') } } $response->dynamic(new Document([ - 'total' => $audit->countLogsByResource($resource, $queries), + 'total' => $includeTotal ? $audit->countLogsByResource($resource, $queries) : 0, 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 72ba49d8d5..64ce5c0970 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -826,10 +826,11 @@ App::get('/v1/users/:userId/sessions') ] )) ->param('userId', '', new UID(), 'User ID.') + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->inject('locale') - ->action(function (string $userId, Response $response, Database $dbForProject, Locale $locale) { + ->action(function (string $userId, bool $includeTotal, Response $response, Database $dbForProject, Locale $locale) { $user = $dbForProject->getDocument('users', $userId); @@ -851,7 +852,7 @@ App::get('/v1/users/:userId/sessions') $response->dynamic(new Document([ 'sessions' => $sessions, - 'total' => count($sessions), + 'total' => $includeTotal ? count($sessions) : 0, ]), Response::MODEL_SESSION_LIST); }); @@ -875,9 +876,10 @@ App::get('/v1/users/:userId/memberships') ->param('userId', '', new UID(), 'User ID.') ->param('queries', [], new Memberships(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Memberships::ALLOWED_ATTRIBUTES), true) ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') - ->action(function (string $userId, array $queries, string $search, Response $response, Database $dbForProject) { + ->action(function (string $userId, array $queries, string $search, bool $includeTotal, Response $response, Database $dbForProject) { $user = $dbForProject->getDocument('users', $userId); @@ -911,7 +913,7 @@ App::get('/v1/users/:userId/memberships') $response->dynamic(new Document([ 'memberships' => $memberships, - 'total' => count($memberships), + 'total' => $includeTotal ? count($memberships) : 0, ]), Response::MODEL_MEMBERSHIP_LIST); }); @@ -934,11 +936,12 @@ App::get('/v1/users/:userId/logs') )) ->param('userId', '', new UID(), 'User ID.') ->param('queries', [], new Queries([new Limit(), new Offset()]), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->inject('dbForProject') ->inject('locale') ->inject('geodb') - ->action(function (string $userId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { + ->action(function (string $userId, array $queries, bool $includeTotal, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) { $user = $dbForProject->getDocument('users', $userId); @@ -1007,7 +1010,7 @@ App::get('/v1/users/:userId/logs') } $response->dynamic(new Document([ - 'total' => $audit->countLogsByUser($user->getSequence(), $queries), + 'total' => $includeTotal ? $audit->countLogsByUser($user->getSequence(), $queries) : 0, 'logs' => $output, ]), Response::MODEL_LOG_LIST); }); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php index 86e7f21362..c9c4dbc500 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php @@ -12,6 +12,7 @@ use Utopia\Database\Document; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\Validator\ArrayList; +use Utopia\Validator\Boolean; use Utopia\Validator\Range; use Utopia\Validator\WhiteList; @@ -52,11 +53,12 @@ class XList extends Base ->param('useCases', [], new ArrayList(new WhiteList(['dev-tools','starter','databases','ai','messaging','utilities']), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of use cases allowed for filtering function templates. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' use cases are allowed.', true) ->param('limit', 25, new Range(1, 5000), 'Limit the number of templates returned in the response. Default limit is 25, and maximum limit is 5000.', true) ->param('offset', 0, new Range(0, 5000), 'Offset the list of returned templates. Maximum offset is 5000.', true) + ->param('includeTotal', true, new Boolean(), 'When set to false, the total count returned will be 0 and will not be calculated.', true) ->inject('response') ->callback($this->action(...)); } - public function action(array $runtimes, array $usecases, int $limit, int $offset, Response $response) + public function action(array $runtimes, array $usecases, int $limit, int $offset, bool $includeTotal, Response $response) { $templates = Config::getParam('templates-function', []); @@ -76,7 +78,7 @@ class XList extends Base return $b['score'] <=> $a['score']; }); - $total = \count($templates); + $total = $includeTotal ? \count($templates) : 0; $templates = \array_slice($templates, $offset, $limit); $response->dynamic(new Document([ 'templates' => $templates, diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 0993f68a58..b4e9c218ed 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -236,6 +236,25 @@ class AccountCustomClientTest extends Scope $this->assertEquals($sessionId, $response['body']['sessions'][0]['$id']); $this->assertEmpty($response['body']['sessions'][0]['secret']); + /** + * Test for SUCCESS with includeTotal=false + */ + $sessionsWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ]), [ + 'includeTotal' => false + ]); + + $this->assertEquals($sessionsWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($sessionsWithIncludeTotalFalse['body']); + $this->assertIsArray($sessionsWithIncludeTotalFalse['body']['sessions']); + $this->assertIsInt($sessionsWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $sessionsWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($sessionsWithIncludeTotalFalse['body']['sessions'])); + $this->assertEquals('Windows', $response['body']['sessions'][0]['osName']); $this->assertEquals('WIN', $response['body']['sessions'][0]['osCode']); $this->assertEquals('10', $response['body']['sessions'][0]['osVersion']); diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 8827637427..84b00bc8e2 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -961,6 +961,24 @@ trait DatabasesBase $this->assertEquals(200, $attributes['headers']['status-code']); $this->assertEquals(12, $attributes['body']['total']); + /** + * Test for SUCCESS with includeTotal=false + */ + $attributesWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'includeTotal' => false + ]); + + $this->assertEquals($attributesWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($attributesWithIncludeTotalFalse['body']); + $this->assertIsArray($attributesWithIncludeTotalFalse['body']['attributes']); + $this->assertIsInt($attributesWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $attributesWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($attributesWithIncludeTotalFalse['body']['attributes'])); + $attributes = $attributes['body']['attributes']; $this->assertIsArray($attributes); $this->assertCount(12, $attributes); diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php index c1ce75c38d..04faea28a9 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php @@ -55,6 +55,23 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals($test1['body']['$id'], $databases['body']['databases'][0]['$id']); $this->assertEquals($test2['body']['$id'], $databases['body']['databases'][1]['$id']); + /** + * Test for SUCCESS with includeTotal=false + */ + $databasesWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/databases', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'includeTotal' => false + ]); + + $this->assertEquals($databasesWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($databasesWithIncludeTotalFalse['body']); + $this->assertIsArray($databasesWithIncludeTotalFalse['body']['databases']); + $this->assertIsInt($databasesWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $databasesWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($databasesWithIncludeTotalFalse['body']['databases'])); + $base = array_reverse($databases['body']['databases']); $databases = $this->client->call(Client::METHOD_GET, '/databases', array_merge([ @@ -395,6 +412,23 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals($test2['body']['$id'], $collections['body']['collections'][1]['$id']); $this->assertEquals($test1['body']['enabled'], $collections['body']['collections'][0]['enabled']); + /** + * Test for SUCCESS with includeTotal=false + */ + $collectionsWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'includeTotal' => false + ]); + + $this->assertEquals($collectionsWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($collectionsWithIncludeTotalFalse['body']); + $this->assertIsArray($collectionsWithIncludeTotalFalse['body']['collections']); + $this->assertIsInt($collectionsWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $collectionsWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($collectionsWithIncludeTotalFalse['body']['collections'])); + $base = array_reverse($collections['body']['collections']); $collections = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections', array_merge([ @@ -4548,6 +4582,23 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals(200, $documents['headers']['status-code']); $this->assertEquals(10, $documents['body']['total']); + /** + * Test for SUCCESS with includeTotal=false + */ + $documentsWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'includeTotal' => false + ]); + + $this->assertEquals($documentsWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($documentsWithIncludeTotalFalse['body']); + $this->assertIsArray($documentsWithIncludeTotalFalse['body']['documents']); + $this->assertIsInt($documentsWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $documentsWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($documentsWithIncludeTotalFalse['body']['documents'])); + $returnedDocuments = $response['body']['documents']; $refetchedDocuments = $documents['body']['documents']; diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php index 5e35fa065d..68e6cad286 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php @@ -55,6 +55,23 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals($test1['body']['$id'], $databases['body']['databases'][0]['$id']); $this->assertEquals($test2['body']['$id'], $databases['body']['databases'][1]['$id']); + /** + * Test for SUCCESS with includeTotal=false + */ + $databasesWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/tablesdb', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'includeTotal' => false + ]); + + $this->assertEquals($databasesWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($databasesWithIncludeTotalFalse['body']); + $this->assertIsArray($databasesWithIncludeTotalFalse['body']['databases']); + $this->assertIsInt($databasesWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $databasesWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($databasesWithIncludeTotalFalse['body']['databases'])); + $base = array_reverse($databases['body']['databases']); $databases = $this->client->call(Client::METHOD_GET, '/tablesdb', array_merge([ diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index c3c9fbfbab..21e0d38205 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -376,6 +376,23 @@ class FunctionsCustomClientTest extends Scope $this->assertGreaterThan(0, $templates['body']['total']); $this->assertIsArray($templates['body']['templates']); + /** + * Test for SUCCESS with includeTotal=false + */ + $templatesWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/functions/templates', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'includeTotal' => false + ]); + + $this->assertEquals($templatesWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($templatesWithIncludeTotalFalse['body']); + $this->assertIsArray($templatesWithIncludeTotalFalse['body']['templates']); + $this->assertIsInt($templatesWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $templatesWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($templatesWithIncludeTotalFalse['body']['templates'])); + foreach ($templates['body']['templates'] as $template) { $this->assertArrayHasKey('name', $template); $this->assertArrayHasKey('id', $template); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 0d63791151..53cff987d3 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -418,6 +418,18 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $deployments['headers']['status-code']); $this->assertEquals(1, $deployments['body']['total']); + /** + * Test for SUCCESS with includeTotal=false + */ + $deploymentsWithIncludeTotalFalse = $this->listDeployments($functionId, ['includeTotal' => false]); + + $this->assertEquals($deploymentsWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($deploymentsWithIncludeTotalFalse['body']); + $this->assertIsArray($deploymentsWithIncludeTotalFalse['body']['deployments']); + $this->assertIsInt($deploymentsWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $deploymentsWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($deploymentsWithIncludeTotalFalse['body']['deployments'])); + $lastDeployment = $deployments['body']['deployments'][0]; $this->assertNotEmpty($lastDeployment['$id']); @@ -1004,6 +1016,18 @@ class FunctionsCustomServerTest extends Scope $this->assertCount(1, $executions['body']['executions']); $this->assertEquals($data['deploymentId'], $executions['body']['executions'][0]['deploymentId']); + /** + * Test for SUCCESS with includeTotal=false + */ + $executionsWithIncludeTotalFalse = $this->listExecutions($data['functionId'], ['includeTotal' => false]); + + $this->assertEquals($executionsWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($executionsWithIncludeTotalFalse['body']); + $this->assertIsArray($executionsWithIncludeTotalFalse['body']['executions']); + $this->assertIsInt($executionsWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $executionsWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($executionsWithIncludeTotalFalse['body']['executions'])); + $executions = $this->listExecutions($data['functionId'], [ 'queries' => [ Query::equal('deploymentId', [$data['deploymentId']])->toString(), diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index dc5ddb9d70..456d458414 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -633,6 +633,24 @@ trait MessagingBase $this->assertEquals(1, $response['body']['total']); } + /** + * Test for SUCCESS with includeTotal=false + */ + $subscribersWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $data['topicId'] . '/subscribers', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'includeTotal' => false + ]); + + $this->assertEquals($subscribersWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($subscribersWithIncludeTotalFalse['body']); + $this->assertIsArray($subscribersWithIncludeTotalFalse['body']['subscribers']); + $this->assertIsInt($subscribersWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $subscribersWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($subscribersWithIncludeTotalFalse['body']['subscribers'])); + return $data; } diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 2b2c884283..943283d185 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -379,6 +379,23 @@ trait StorageBase $this->assertGreaterThan(0, $files['body']['total']); $this->assertGreaterThan(0, count($files['body']['files'])); + /** + * Test for SUCCESS with includeTotal=false + */ + $filesWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'includeTotal' => false + ]); + + $this->assertEquals($filesWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($filesWithIncludeTotalFalse['body']); + $this->assertIsArray($filesWithIncludeTotalFalse['body']['files']); + $this->assertIsInt($filesWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $filesWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($filesWithIncludeTotalFalse['body']['files'])); + $files = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], diff --git a/tests/e2e/Services/Teams/TeamsBase.php b/tests/e2e/Services/Teams/TeamsBase.php index fccfded1e1..4320ef8c6b 100644 --- a/tests/e2e/Services/Teams/TeamsBase.php +++ b/tests/e2e/Services/Teams/TeamsBase.php @@ -322,6 +322,23 @@ trait TeamsBase $this->assertEquals(400, $response['headers']['status-code']); + /** + * Test for SUCCESS with includeTotal=false + */ + $teamsWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'includeTotal' => false + ]); + + $this->assertEquals($teamsWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($teamsWithIncludeTotalFalse['body']); + $this->assertIsArray($teamsWithIncludeTotalFalse['body']['teams']); + $this->assertIsInt($teamsWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $teamsWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($teamsWithIncludeTotalFalse['body']['teams'])); + return []; } diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 2cf1e4c65d..bce411906d 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -798,6 +798,23 @@ trait UsersBase $this->assertIsInt($users['body']['total']); $this->assertGreaterThan(0, $users['body']['total']); + /** + * Test for SUCCESS with includeTotal=false + */ + $usersWithIncludeTotalFalse = $this->client->call(Client::METHOD_GET, '/users', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'includeTotal' => false + ]); + + $this->assertEquals($usersWithIncludeTotalFalse['headers']['status-code'], 200); + $this->assertIsArray($usersWithIncludeTotalFalse['body']); + $this->assertIsArray($usersWithIncludeTotalFalse['body']['users']); + $this->assertIsInt($usersWithIncludeTotalFalse['body']['total']); + $this->assertEquals(0, $usersWithIncludeTotalFalse['body']['total']); + $this->assertGreaterThan(0, count($usersWithIncludeTotalFalse['body']['users'])); + /** * Test for FAILURE */