1
0
Fork 0
mirror of synced 2024-07-02 05:00:33 +12:00
appwrite/tests/e2e/Services/Storage/StorageConsoleClientTest.php

106 lines
3.7 KiB
PHP
Raw Normal View History

2020-01-13 10:28:26 +13:00
<?php
namespace Tests\E2E\Services\Storage;
use Tests\E2E\Client;
2020-01-13 10:28:26 +13:00
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\SideConsole;
2020-01-13 10:28:26 +13:00
class StorageConsoleClientTest extends Scope
{
use SideConsole;
2020-01-13 10:28:26 +13:00
use StorageBase;
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
/**
* 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);
$this->assertEquals(12, count($response['body']));
$this->assertEquals($response['body']['range'], '24h');
2022-08-15 12:50:51 +12:00
$this->assertIsArray($response['body']['storage']);
2021-11-10 00:34:16 +13:00
$this->assertIsArray($response['body']['filesCount']);
}
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()), [
'bucketId' => 'unique()',
'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'];
/**
* Test for FAILURE
*/
2021-09-13 20:18:40 +12:00
$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($response['headers']['status-code'], 400);
// 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-09-10 20:50:15 +12:00
$this->assertEquals($response['headers']['status-code'], 404);
/**
* Test for SUCCESS
*/
2021-09-13 20:18:40 +12:00
$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($response['headers']['status-code'], 200);
2021-11-10 00:34:16 +13:00
$this->assertEquals(count($response['body']), 7);
$this->assertEquals($response['body']['range'], '24h');
2021-11-10 00:34:16 +13:00
$this->assertIsArray($response['body']['filesCount']);
$this->assertIsArray($response['body']['filesCreate']);
$this->assertIsArray($response['body']['filesRead']);
$this->assertIsArray($response['body']['filesUpdate']);
$this->assertIsArray($response['body']['filesDelete']);
$this->assertIsArray($response['body']['filesStorage']);
}
2021-10-27 02:19:28 +13:00
}