From 66294445ce47a2a7010ff63dc1c75ae25f47fb17 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 29 Aug 2021 14:24:50 +0530 Subject: [PATCH] feat(tests): added tests for users usage --- app/controllers/api/storage.php | 2 ++ src/Appwrite/Utopia/Response/Model/UsageBuckets.php | 7 +++++++ tests/e2e/Services/Storage/StorageConsoleClientTest.php | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index a11d50b5e..ee6210d25 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -759,6 +759,7 @@ App::get('/v1/storage/:bucketId/usage') ]; $metrics = [ + "storage.buckets.$bucketId.files.count", "storage.buckets.$bucketId.files.create", "storage.buckets.$bucketId.files.read", "storage.buckets.$bucketId.files.update", @@ -787,6 +788,7 @@ App::get('/v1/storage/:bucketId/usage') $usage = new Document([ 'range' => $range, + 'files.count' => $stats["storage.buckets.$bucketId.files.count"], 'files.create' => $stats["storage.buckets.$bucketId.files.create"], 'files.read' => $stats["storage.buckets.$bucketId.files.read"], 'files.update' => $stats["storage.buckets.$bucketId.files.update"], diff --git a/src/Appwrite/Utopia/Response/Model/UsageBuckets.php b/src/Appwrite/Utopia/Response/Model/UsageBuckets.php index 11fb2e2f8..8c66ff47c 100644 --- a/src/Appwrite/Utopia/Response/Model/UsageBuckets.php +++ b/src/Appwrite/Utopia/Response/Model/UsageBuckets.php @@ -17,6 +17,13 @@ class UsageBuckets extends Model 'default' => '', 'example' => '30d', ]) + ->addRule('files.count', [ + 'type' => Response::MODEL_METRIC_LIST, + 'description' => 'Aggregated stats for total number of files in this bucket.', + 'default' => [], + 'example' => new stdClass, + 'array' => true + ]) ->addRule('files.create', [ 'type' => Response::MODEL_METRIC_LIST, 'description' => 'Aggregated stats for files created.', diff --git a/tests/e2e/Services/Storage/StorageConsoleClientTest.php b/tests/e2e/Services/Storage/StorageConsoleClientTest.php index 696066177..4ec1a6ce9 100644 --- a/tests/e2e/Services/Storage/StorageConsoleClientTest.php +++ b/tests/e2e/Services/Storage/StorageConsoleClientTest.php @@ -30,7 +30,6 @@ class StorageConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/storage/usage', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'] @@ -82,8 +81,9 @@ class StorageConsoleClientTest extends Scope ]); $this->assertEquals($response['headers']['status-code'], 200); - $this->assertEquals(count($response['body']), 5); + $this->assertEquals(count($response['body']), 6); $this->assertEquals($response['body']['range'], '24h'); + $this->assertIsArray($response['body']['files.count']); $this->assertIsArray($response['body']['files.create']); $this->assertIsArray($response['body']['files.read']); $this->assertIsArray($response['body']['files.update']);