2021-08-29 19:50:52 +12:00
|
|
|
<?php
|
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
namespace Tests\E2E\Services\Databases;
|
2021-08-29 19:50:52 +12:00
|
|
|
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
use Tests\E2E\Scopes\SideConsole;
|
2022-08-14 22:33:36 +12:00
|
|
|
use Utopia\Database\ID;
|
|
|
|
use Utopia\Database\Permission;
|
|
|
|
use Utopia\Database\Role;
|
2021-08-29 19:50:52 +12:00
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
class DatabasesConsoleClientTest extends Scope
|
2021-08-29 19:50:52 +12:00
|
|
|
{
|
|
|
|
use ProjectCustom;
|
|
|
|
use SideConsole;
|
|
|
|
|
2021-10-27 02:19:28 +13:00
|
|
|
public function testCreateCollection(): array
|
2021-08-29 19:50:52 +12:00
|
|
|
{
|
2022-06-22 22:51:49 +12:00
|
|
|
$database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'databaseId' => ID::unique(),
|
2022-06-22 22:51:49 +12:00
|
|
|
'name' => 'invalidDocumentDatabase',
|
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $database['headers']['status-code']);
|
|
|
|
$this->assertEquals('invalidDocumentDatabase', $database['body']['name']);
|
|
|
|
|
|
|
|
$databaseId = $database['body']['$id'];
|
2021-08-29 19:50:52 +12:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-06-22 22:51:49 +12:00
|
|
|
$movies = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
2021-08-29 19:50:52 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'collectionId' => ID::unique(),
|
2021-08-29 19:50:52 +12:00
|
|
|
'name' => 'Movies',
|
2022-08-03 16:17:49 +12:00
|
|
|
'permissions' => [
|
2022-08-14 17:21:11 +12:00
|
|
|
Permission::read(Role::any()),
|
|
|
|
Permission::create(Role::any()),
|
|
|
|
Permission::update(Role::any()),
|
|
|
|
Permission::delete(Role::any()),
|
2022-08-03 16:17:49 +12:00
|
|
|
],
|
|
|
|
'documentSecurity' => true,
|
2021-08-29 19:50:52 +12:00
|
|
|
]);
|
|
|
|
|
2022-08-08 23:00:03 +12:00
|
|
|
$this->assertEquals(201, $movies['headers']['status-code']);
|
2021-08-29 19:50:52 +12:00
|
|
|
$this->assertEquals($movies['body']['name'], 'Movies');
|
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
return ['moviesId' => $movies['body']['$id'], 'databaseId' => $databaseId];
|
2021-08-29 19:50:52 +12:00
|
|
|
}
|
2021-10-27 02:19:28 +13:00
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateCollection
|
|
|
|
*/
|
2022-12-26 22:11:13 +13:00
|
|
|
public function testGetDatabaseUsage(array $data)
|
|
|
|
{
|
|
|
|
$databaseId = $data['databaseId'];
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/usage', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'range' => '32h'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/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(count($response['body']), 3);
|
|
|
|
$this->assertEquals($response['body']['range'], '24h');
|
|
|
|
$this->assertIsArray($response['body']['documentsCount']);
|
|
|
|
$this->assertIsArray($response['body']['collectionsCount']);
|
|
|
|
}
|
2021-08-29 19:50:52 +12:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateCollection
|
|
|
|
*/
|
|
|
|
public function testGetCollectionUsage(array $data)
|
|
|
|
{
|
2022-06-22 22:51:49 +12:00
|
|
|
$databaseId = $data['databaseId'];
|
2021-08-29 19:50:52 +12:00
|
|
|
/**
|
2021-08-29 19:59:08 +12:00
|
|
|
* Test for FAILURE
|
2021-08-29 19:50:52 +12:00
|
|
|
*/
|
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/usage', array_merge([
|
2021-08-29 19:59:08 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'range' => '32h'
|
|
|
|
]);
|
|
|
|
|
2022-08-08 23:00:03 +12:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2021-08-29 19:59:08 +12:00
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/randomCollectionId/usage', array_merge([
|
2021-08-29 19:59:08 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'range' => '24h'
|
|
|
|
]);
|
|
|
|
|
2022-08-08 23:00:03 +12:00
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2021-08-29 19:59:08 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-06-22 22:51:49 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/usage', array_merge([
|
2021-08-29 19:50:52 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'range' => '24h'
|
|
|
|
]);
|
2022-08-08 23:00:03 +12:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-12-26 22:11:13 +13:00
|
|
|
$this->assertEquals(count($response['body']), 2);
|
2021-08-29 19:50:52 +12:00
|
|
|
$this->assertEquals($response['body']['range'], '24h');
|
2021-10-27 02:19:28 +13:00
|
|
|
$this->assertIsArray($response['body']['documentsCount']);
|
2021-08-29 19:50:52 +12:00
|
|
|
}
|
2021-11-15 22:49:11 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateCollection
|
|
|
|
*/
|
|
|
|
public function testGetCollectionLogs(array $data)
|
|
|
|
{
|
2022-06-22 22:51:49 +12:00
|
|
|
$databaseId = $data['databaseId'];
|
2021-11-15 22:49:11 +13:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-06-22 22:51:49 +12:00
|
|
|
$logs = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/logs', array_merge([
|
2021-11-15 22:49:11 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
2022-08-08 23:00:03 +12:00
|
|
|
$this->assertEquals(200, $logs['headers']['status-code']);
|
2021-11-15 22:49:11 +13:00
|
|
|
$this->assertIsArray($logs['body']['logs']);
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertIsNumeric($logs['body']['total']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
$logs = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/logs', array_merge([
|
2021-11-15 22:49:11 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 1
|
|
|
|
]);
|
|
|
|
|
2022-08-08 23:00:03 +12:00
|
|
|
$this->assertEquals(200, $logs['headers']['status-code']);
|
2021-11-15 22:49:11 +13:00
|
|
|
$this->assertIsArray($logs['body']['logs']);
|
|
|
|
$this->assertLessThanOrEqual(1, count($logs['body']['logs']));
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertIsNumeric($logs['body']['total']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
$logs = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/logs', array_merge([
|
2021-11-15 22:49:11 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'offset' => 1
|
|
|
|
]);
|
|
|
|
|
2022-08-08 23:00:03 +12:00
|
|
|
$this->assertEquals(200, $logs['headers']['status-code']);
|
2021-11-15 22:49:11 +13:00
|
|
|
$this->assertIsArray($logs['body']['logs']);
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertIsNumeric($logs['body']['total']);
|
2021-11-15 22:49:11 +13:00
|
|
|
|
2022-06-22 22:51:49 +12:00
|
|
|
$logs = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/logs', array_merge([
|
2021-11-15 22:49:11 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'offset' => 1,
|
|
|
|
'limit' => 1
|
|
|
|
]);
|
|
|
|
|
2022-08-08 23:00:03 +12:00
|
|
|
$this->assertEquals(200, $logs['headers']['status-code']);
|
2021-11-15 22:49:11 +13:00
|
|
|
$this->assertIsArray($logs['body']['logs']);
|
|
|
|
$this->assertLessThanOrEqual(1, count($logs['body']['logs']));
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertIsNumeric($logs['body']['total']);
|
2021-11-15 22:49:11 +13:00
|
|
|
}
|
2021-10-27 02:19:28 +13:00
|
|
|
}
|