2020-01-13 10:28:26 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Storage;
|
|
|
|
|
2021-08-29 20:19:25 +12:00
|
|
|
use Tests\E2E\Client;
|
2020-01-13 10:28:26 +13:00
|
|
|
use Tests\E2E\Scopes\Scope;
|
2021-08-29 20:19:25 +12:00
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\SideConsole;
|
2023-02-06 09:07:46 +13:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2020-01-13 10:28:26 +13:00
|
|
|
|
|
|
|
class StorageConsoleClientTest extends Scope
|
|
|
|
{
|
2021-08-29 20:19:25 +12:00
|
|
|
use SideConsole;
|
2020-01-13 10:28:26 +13:00
|
|
|
use StorageBase;
|
2021-08-29 20:19:25 +12:00
|
|
|
use ProjectCustom;
|
|
|
|
|
|
|
|
public function testGetStorageUsage()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->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);
|
2021-10-27 02:19:28 +13:00
|
|
|
|
2021-08-29 20:19:25 +12:00
|
|
|
/**
|
|
|
|
* 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'
|
|
|
|
]);
|
|
|
|
|
2023-11-27 09:57:57 +13:00
|
|
|
$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']);
|
2021-08-29 20:19:25 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetStorageBucketUsage()
|
|
|
|
{
|
2021-09-13 20:18:40 +12:00
|
|
|
//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()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'bucketId' => ID::unique(),
|
2021-09-13 20:18:40 +12:00
|
|
|
'name' => 'Test Bucket',
|
2021-10-17 20:12:59 +13:00
|
|
|
'permission' => 'file'
|
2021-09-13 20:18:40 +12:00
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
|
2021-08-29 20:19:25 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
2021-09-13 20:18:40 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/storage/' . $bucketId . '/usage', array_merge([
|
2021-08-29 20:19:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'range' => '32h'
|
|
|
|
]);
|
|
|
|
|
2023-11-27 09:57:57 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2021-08-29 20:19:25 +12:00
|
|
|
|
|
|
|
// TODO: Uncomment once we implement check for missing bucketId in the usage endpoint.
|
|
|
|
|
2021-09-10 20:50:15 +12:00
|
|
|
$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'
|
|
|
|
]);
|
2021-08-29 20:19:25 +12:00
|
|
|
|
2023-11-27 09:57:57 +13:00
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2021-08-29 20:19:25 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2021-09-13 20:18:40 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/storage/' . $bucketId . '/usage', array_merge([
|
2021-08-29 20:19:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'range' => '24h'
|
|
|
|
]);
|
|
|
|
|
2023-11-27 09:57:57 +13:00
|
|
|
$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']);
|
2021-08-29 20:19:25 +12:00
|
|
|
}
|
2021-10-27 02:19:28 +13:00
|
|
|
}
|