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