client->call(Client::METHOD_GET, '/storage/usage', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'] ], $this->getHeaders()), [ 'range' => '32h' ]); $this->assertEquals($response['headers']['status-code'], 400); /** * Test for SUCCESS */ $response = $this->client->call(Client::METHOD_GET, '/storage/usage', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'] ], $this->getHeaders()), [ 'range' => '24h' ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(7, count($response['body'])); $this->assertEquals('24h', $response['body']['range']); $this->assertIsNumeric($response['body']['bucketsTotal']); $this->assertIsNumeric($response['body']['filesTotal']); $this->assertIsNumeric($response['body']['filesStorageTotal']); $this->assertIsArray($response['body']['buckets']); $this->assertIsArray($response['body']['files']); $this->assertIsArray($response['body']['storage']); } public function testGetStorageBucketUsage() { //create bucket $bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'bucketId' => ID::unique(), 'name' => 'Test Bucket', 'permission' => 'file' ]); $this->assertEquals(201, $bucket['headers']['status-code']); $bucketId = $bucket['body']['$id']; /** * Test for FAILURE */ $response = $this->client->call(Client::METHOD_GET, '/storage/' . $bucketId . '/usage', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'] ], $this->getHeaders()), [ 'range' => '32h' ]); $this->assertEquals(400, $response['headers']['status-code']); // TODO: Uncomment once we implement check for missing bucketId in the usage endpoint. $response = $this->client->call(Client::METHOD_GET, '/storage/randomBucketId/usage', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'] ], $this->getHeaders()), [ 'range' => '24h' ]); $this->assertEquals(404, $response['headers']['status-code']); /** * Test for SUCCESS */ $response = $this->client->call(Client::METHOD_GET, '/storage/' . $bucketId . '/usage', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'] ], $this->getHeaders()), [ 'range' => '24h' ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(5, count($response['body'])); $this->assertEquals('24h', $response['body']['range']); $this->assertIsNumeric($response['body']['filesTotal']); $this->assertIsNumeric($response['body']['filesStorageTotal']); $this->assertIsArray($response['body']['files']); $this->assertIsArray($response['body']['storage']); } }