1
0
Fork 0
mirror of synced 2024-07-04 06:00:53 +12:00
appwrite/tests/e2e/Services/Storage/StorageConsoleClientTest.php

104 lines
3.6 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);
/**
* 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(count($response['body']), 3);
$this->assertEquals($response['body']['range'], '24h');
$this->assertIsArray($response['body']['storage']);
$this->assertIsArray($response['body']['files']);
}
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);
$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']);
$this->assertIsArray($response['body']['files.delete']);
}
2020-01-13 10:28:26 +13:00
}