2020-01-13 21:46:09 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Database;
|
|
|
|
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\SideServer;
|
2020-12-05 18:31:59 +13:00
|
|
|
use Tests\E2E\Client;
|
2021-10-05 23:30:33 +13:00
|
|
|
use Utopia\Database\Database;
|
2020-01-13 21:46:09 +13:00
|
|
|
|
|
|
|
class DatabaseCustomServerTest extends Scope
|
|
|
|
{
|
2020-12-05 18:34:58 +13:00
|
|
|
use DatabaseBase;
|
2020-01-13 21:46:09 +13:00
|
|
|
use ProjectCustom;
|
|
|
|
use SideServer;
|
2020-12-05 18:31:59 +13:00
|
|
|
|
2021-08-10 02:54:10 +12:00
|
|
|
public function testListCollections()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$test1 = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
|
|
|
'name' => 'Test 1',
|
|
|
|
'collectionId' => 'first',
|
|
|
|
'read' => ['role:all'],
|
|
|
|
'write' => ['role:all'],
|
2021-08-23 02:06:59 +12:00
|
|
|
'permission' => 'document'
|
2021-08-10 02:54:10 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$test2 = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
|
|
|
'name' => 'Test 2',
|
|
|
|
'collectionId' => 'second',
|
|
|
|
'read' => ['role:all'],
|
|
|
|
'write' => ['role:all'],
|
2021-08-23 02:06:59 +12:00
|
|
|
'permission' => 'document'
|
2021-08-10 02:54:10 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(2, $collections['body']['total']);
|
2021-08-10 02:54:10 +12:00
|
|
|
$this->assertEquals($test1['body']['$id'], $collections['body']['collections'][0]['$id']);
|
|
|
|
$this->assertEquals($test2['body']['$id'], $collections['body']['collections'][1]['$id']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Order
|
|
|
|
*/
|
|
|
|
$base = array_reverse($collections['body']['collections']);
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'orderType' => 'DESC'
|
|
|
|
]);
|
|
|
|
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(2, $collections['body']['total']);
|
2021-08-10 02:54:10 +12:00
|
|
|
$this->assertEquals($base[0]['$id'], $collections['body']['collections'][0]['$id']);
|
|
|
|
$this->assertEquals($base[1]['$id'], $collections['body']['collections'][1]['$id']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for After
|
|
|
|
*/
|
|
|
|
$base = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2021-10-05 23:30:33 +13:00
|
|
|
'cursor' => $base['body']['collections'][0]['$id']
|
2021-08-10 02:54:10 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertCount(1, $collections['body']['collections']);
|
|
|
|
$this->assertEquals($base['body']['collections'][1]['$id'], $collections['body']['collections'][0]['$id']);
|
|
|
|
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2021-10-05 23:30:33 +13:00
|
|
|
'cursor' => $base['body']['collections'][1]['$id']
|
2021-08-10 02:54:10 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertCount(0, $collections['body']['collections']);
|
|
|
|
$this->assertEmpty($collections['body']['collections']);
|
2021-10-05 23:30:33 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Before
|
|
|
|
*/
|
|
|
|
$base = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'cursor' => $base['body']['collections'][1]['$id'],
|
|
|
|
'cursorDirection' => Database::CURSOR_BEFORE
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertCount(1, $collections['body']['collections']);
|
|
|
|
$this->assertEquals($base['body']['collections'][0]['$id'], $collections['body']['collections'][0]['$id']);
|
|
|
|
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'cursor' => $base['body']['collections'][0]['$id'],
|
|
|
|
'cursorDirection' => Database::CURSOR_BEFORE
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertCount(0, $collections['body']['collections']);
|
|
|
|
$this->assertEmpty($collections['body']['collections']);
|
|
|
|
|
2022-01-19 22:04:57 +13:00
|
|
|
/**
|
|
|
|
* Test for Search
|
|
|
|
*/
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'search' => 'first'
|
|
|
|
]);
|
|
|
|
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(1, $collections['body']['total']);
|
2022-01-19 22:04:57 +13:00
|
|
|
$this->assertEquals('first', $collections['body']['collections'][0]['$id']);
|
|
|
|
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'search' => 'Test'
|
|
|
|
]);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(2, $collections['body']['total']);
|
2022-01-19 22:04:57 +13:00
|
|
|
$this->assertEquals('Test 1', $collections['body']['collections'][0]['name']);
|
|
|
|
$this->assertEquals('Test 2', $collections['body']['collections'][1]['name']);
|
|
|
|
|
|
|
|
$collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'search' => 'Nonexistent'
|
|
|
|
]);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(0, $collections['body']['total']);
|
2022-01-19 22:04:57 +13:00
|
|
|
|
2021-10-05 23:30:33 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'cursor' => 'unknown',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 400);
|
2022-01-13 08:51:13 +13:00
|
|
|
|
|
|
|
// This collection already exists
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
|
|
|
'name' => 'Test 1',
|
|
|
|
'collectionId' => 'first',
|
|
|
|
'read' => ['role:all'],
|
|
|
|
'write' => ['role:all'],
|
|
|
|
'permission' => 'document'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 409);
|
2021-08-10 02:54:10 +12:00
|
|
|
}
|
|
|
|
|
2021-08-09 11:56:31 +12:00
|
|
|
public function testDeleteAttribute(): array
|
2020-12-05 18:31:59 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Create collection
|
|
|
|
$actors = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-07-19 21:26:00 +12:00
|
|
|
'collectionId' => 'unique()',
|
2021-06-16 02:24:51 +12:00
|
|
|
'name' => 'Actors',
|
2021-06-18 03:15:14 +12:00
|
|
|
'read' => ['role:all'],
|
|
|
|
'write' => ['role:all'],
|
2021-08-23 02:06:59 +12:00
|
|
|
'permission' => 'document'
|
2020-12-05 18:31:59 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($actors['headers']['status-code'], 201);
|
|
|
|
$this->assertEquals($actors['body']['name'], 'Actors');
|
2021-06-12 06:07:05 +12:00
|
|
|
|
2021-07-22 03:05:18 +12:00
|
|
|
$firstName = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/attributes/string', array_merge([
|
2021-06-12 06:07:05 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'firstName',
|
2021-06-12 06:07:05 +12:00
|
|
|
'size' => 256,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
2021-07-22 03:05:18 +12:00
|
|
|
$lastName = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/attributes/string', array_merge([
|
2021-06-12 06:07:05 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'lastName',
|
2021-06-12 06:07:05 +12:00
|
|
|
'size' => 256,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
2021-08-09 10:08:10 +12:00
|
|
|
$unneeded = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/attributes/string', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'unneeded',
|
2021-08-09 10:08:10 +12:00
|
|
|
'size' => 256,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Wait for database worker to finish creating attributes
|
2021-08-23 16:06:53 +12:00
|
|
|
sleep(2);
|
2021-08-09 10:08:10 +12:00
|
|
|
|
2021-11-24 06:39:01 +13:00
|
|
|
// Creating document to ensure cache is purged on schema change
|
|
|
|
$document = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/documents', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
|
|
|
'documentId' => 'unique()',
|
|
|
|
'data' => [
|
|
|
|
'firstName' => 'lorem',
|
|
|
|
'lastName' => 'ipsum',
|
|
|
|
'unneeded' => 'dolor'
|
|
|
|
],
|
|
|
|
'read' => ['role:all'],
|
|
|
|
'write' => ['role:all'],
|
|
|
|
]);
|
|
|
|
|
2021-08-09 10:08:10 +12:00
|
|
|
$index = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/indexes', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'key_lastName',
|
2021-08-09 10:08:10 +12:00
|
|
|
'type' => 'key',
|
|
|
|
'attributes' => [
|
|
|
|
'lastName',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Wait for database worker to finish creating index
|
2021-08-23 16:06:53 +12:00
|
|
|
sleep(2);
|
2021-08-09 10:08:10 +12:00
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $actors['body']['$id'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
2022-05-24 02:54:50 +12:00
|
|
|
]), []);
|
2021-08-09 10:08:10 +12:00
|
|
|
|
2021-08-23 02:06:59 +12:00
|
|
|
$unneededId = $unneeded['body']['key'];
|
2021-08-09 10:08:10 +12:00
|
|
|
|
2021-08-23 16:06:53 +12:00
|
|
|
$this->assertEquals($collection['headers']['status-code'], 200);
|
2021-08-09 10:08:10 +12:00
|
|
|
$this->assertIsArray($collection['body']['attributes']);
|
|
|
|
$this->assertCount(3, $collection['body']['attributes']);
|
2021-08-23 02:06:59 +12:00
|
|
|
$this->assertEquals($collection['body']['attributes'][0]['key'], $firstName['body']['key']);
|
|
|
|
$this->assertEquals($collection['body']['attributes'][1]['key'], $lastName['body']['key']);
|
|
|
|
$this->assertEquals($collection['body']['attributes'][2]['key'], $unneeded['body']['key']);
|
2021-08-09 10:08:10 +12:00
|
|
|
$this->assertCount(1, $collection['body']['indexes']);
|
2021-08-23 04:36:26 +12:00
|
|
|
$this->assertEquals($collection['body']['indexes'][0]['key'], $index['body']['key']);
|
2021-08-09 10:08:10 +12:00
|
|
|
|
|
|
|
// Delete attribute
|
2021-08-23 16:06:53 +12:00
|
|
|
$attribute = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $actors ['body']['$id'] . '/attributes/' . $unneededId, array_merge([
|
2021-08-09 10:08:10 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
2021-08-23 16:06:53 +12:00
|
|
|
$this->assertEquals($attribute['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
sleep(2);
|
2021-06-19 05:09:07 +12:00
|
|
|
|
2021-11-24 06:39:01 +13:00
|
|
|
// Check document to ensure cache is purged on schema change
|
|
|
|
$document = $this->client->call(Client::METHOD_GET, '/database/collections/' . $actors['body']['$id'] . '/documents/' . $document['body']['$id'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertNotContains($unneededId, $document['body']);
|
|
|
|
|
2021-06-12 06:07:05 +12:00
|
|
|
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $actors['body']['$id'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
2022-05-24 02:54:50 +12:00
|
|
|
]), []);
|
2020-12-05 18:31:59 +13:00
|
|
|
|
2021-08-23 16:06:53 +12:00
|
|
|
$this->assertEquals($collection['headers']['status-code'], 200);
|
2021-06-19 05:09:07 +12:00
|
|
|
$this->assertIsArray($collection['body']['attributes']);
|
|
|
|
$this->assertCount(2, $collection['body']['attributes']);
|
2021-08-23 04:36:26 +12:00
|
|
|
$this->assertEquals($collection['body']['attributes'][0]['key'], $firstName['body']['key']);
|
|
|
|
$this->assertEquals($collection['body']['attributes'][1]['key'], $lastName['body']['key']);
|
2021-06-19 05:09:07 +12:00
|
|
|
|
2021-08-09 10:08:10 +12:00
|
|
|
return [
|
|
|
|
'collectionId' => $actors['body']['$id'],
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => $index['body']['key'],
|
2021-08-09 10:08:10 +12:00
|
|
|
];
|
|
|
|
}
|
2021-08-23 16:06:53 +12:00
|
|
|
|
2021-08-09 10:08:10 +12:00
|
|
|
/**
|
|
|
|
* @depends testDeleteAttribute
|
|
|
|
*/
|
2021-08-09 11:56:31 +12:00
|
|
|
public function testDeleteIndex($data): array
|
|
|
|
{
|
2022-05-24 02:54:50 +12:00
|
|
|
$index = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $data['collectionId'] . '/indexes/' . $data['key'], array_merge([
|
2021-08-09 11:56:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
2021-08-23 16:06:53 +12:00
|
|
|
$this->assertEquals($index['headers']['status-code'], 204);
|
|
|
|
|
2021-08-09 11:56:31 +12:00
|
|
|
// Wait for database worker to finish deleting index
|
2021-08-23 16:06:53 +12:00
|
|
|
sleep(2);
|
2021-08-09 11:56:31 +12:00
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['collectionId'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
2021-08-23 16:06:53 +12:00
|
|
|
]), []);
|
2021-08-09 11:56:31 +12:00
|
|
|
|
|
|
|
$this->assertCount(0, $collection['body']['indexes']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testDeleteIndex
|
|
|
|
*/
|
2021-09-03 09:38:46 +12:00
|
|
|
public function testDeleteIndexOnDeleteAttribute($data)
|
|
|
|
{
|
|
|
|
$attribute1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['collectionId'] . '/attributes/string', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'attribute1',
|
2021-09-03 09:38:46 +12:00
|
|
|
'size' => 16,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$attribute2 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['collectionId'] . '/attributes/string', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'attribute2',
|
2021-09-03 09:38:46 +12:00
|
|
|
'size' => 16,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $attribute1['headers']['status-code']);
|
|
|
|
$this->assertEquals(201, $attribute2['headers']['status-code']);
|
|
|
|
$this->assertEquals('attribute1', $attribute1['body']['key']);
|
|
|
|
$this->assertEquals('attribute2', $attribute2['body']['key']);
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
$index1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['collectionId'] . '/indexes', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'index1',
|
2021-09-03 09:38:46 +12:00
|
|
|
'type' => 'key',
|
|
|
|
'attributes' => ['attribute1', 'attribute2'],
|
|
|
|
'orders' => ['ASC', 'ASC'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$index2 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['collectionId'] . '/indexes', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'index2',
|
2021-09-03 09:38:46 +12:00
|
|
|
'type' => 'key',
|
|
|
|
'attributes' => ['attribute2'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $index1['headers']['status-code']);
|
|
|
|
$this->assertEquals(201, $index2['headers']['status-code']);
|
|
|
|
$this->assertEquals('index1', $index1['body']['key']);
|
|
|
|
$this->assertEquals('index2', $index2['body']['key']);
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
|
2021-09-21 13:23:41 +12:00
|
|
|
// Expected behavior: deleting attribute2 will cause index2 to be dropped, and index1 rebuilt with a single key
|
2022-05-24 02:54:50 +12:00
|
|
|
$deleted = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $data['collectionId'] . '/attributes/' . $attribute2['body']['key'], array_merge([
|
2021-09-03 09:38:46 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($deleted['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
// wait for database worker to complete
|
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['collectionId'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $collection['headers']['status-code']);
|
|
|
|
$this->assertIsArray($collection['body']['indexes']);
|
|
|
|
$this->assertCount(1, $collection['body']['indexes']);
|
|
|
|
$this->assertEquals($index1['body']['key'], $collection['body']['indexes'][0]['key']);
|
|
|
|
$this->assertIsArray($collection['body']['indexes'][0]['attributes']);
|
|
|
|
$this->assertCount(1, $collection['body']['indexes'][0]['attributes']);
|
|
|
|
$this->assertEquals($attribute1['body']['key'], $collection['body']['indexes'][0]['attributes'][0]);
|
|
|
|
|
|
|
|
// Delete attribute
|
|
|
|
$deleted = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $data['collectionId'] . '/attributes/' . $attribute1['body']['key'], array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($deleted['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2021-09-28 12:38:03 +13:00
|
|
|
public function testCleanupDuplicateIndexOnDeleteAttribute()
|
2021-09-21 13:23:41 +12:00
|
|
|
{
|
2021-09-28 12:38:03 +13:00
|
|
|
$collection = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
|
|
|
'collectionId' => 'unique()',
|
|
|
|
'name' => 'TestCleanupDuplicateIndexOnDeleteAttribute',
|
|
|
|
'read' => ['role:all'],
|
|
|
|
'write' => ['role:all'],
|
|
|
|
'permission' => 'document',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $collection['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($collection['body']['$id']);
|
|
|
|
|
|
|
|
$collectionId = $collection['body']['$id'];
|
|
|
|
|
|
|
|
$attribute1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/string', array_merge([
|
2021-09-21 13:23:41 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'attribute1',
|
2021-09-21 13:23:41 +12:00
|
|
|
'size' => 16,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
2021-09-28 12:38:03 +13:00
|
|
|
$attribute2 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/string', array_merge([
|
2021-09-21 13:23:41 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'attribute2',
|
2021-09-21 13:23:41 +12:00
|
|
|
'size' => 16,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $attribute1['headers']['status-code']);
|
|
|
|
$this->assertEquals(201, $attribute2['headers']['status-code']);
|
|
|
|
$this->assertEquals('attribute1', $attribute1['body']['key']);
|
|
|
|
$this->assertEquals('attribute2', $attribute2['body']['key']);
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
|
2021-09-28 12:38:03 +13:00
|
|
|
$index1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/indexes', array_merge([
|
2021-09-21 13:23:41 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'index1',
|
2021-09-21 13:23:41 +12:00
|
|
|
'type' => 'key',
|
|
|
|
'attributes' => ['attribute1', 'attribute2'],
|
|
|
|
'orders' => ['ASC', 'ASC'],
|
|
|
|
]);
|
|
|
|
|
2021-09-28 12:38:03 +13:00
|
|
|
$index2 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/indexes', array_merge([
|
2021-09-21 13:23:41 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'index2',
|
2021-09-21 13:23:41 +12:00
|
|
|
'type' => 'key',
|
|
|
|
'attributes' => ['attribute2'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $index1['headers']['status-code']);
|
|
|
|
$this->assertEquals(201, $index2['headers']['status-code']);
|
|
|
|
$this->assertEquals('index1', $index1['body']['key']);
|
|
|
|
$this->assertEquals('index2', $index2['body']['key']);
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
// Expected behavior: deleting attribute1 would cause index1 to be a duplicate of index2 and automatically removed
|
2022-05-24 02:54:50 +12:00
|
|
|
$deleted = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $collectionId . '/attributes/' . $attribute1['body']['key'], array_merge([
|
2021-09-21 13:23:41 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($deleted['headers']['status-code'], 204);
|
|
|
|
|
|
|
|
// wait for database worker to complete
|
|
|
|
sleep(2);
|
|
|
|
|
2021-09-28 12:38:03 +13:00
|
|
|
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $collectionId, array_merge([
|
2021-09-21 13:23:41 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $collection['headers']['status-code']);
|
|
|
|
$this->assertIsArray($collection['body']['indexes']);
|
|
|
|
$this->assertCount(1, $collection['body']['indexes']);
|
|
|
|
$this->assertEquals($index2['body']['key'], $collection['body']['indexes'][0]['key']);
|
|
|
|
$this->assertIsArray($collection['body']['indexes'][0]['attributes']);
|
|
|
|
$this->assertCount(1, $collection['body']['indexes'][0]['attributes']);
|
|
|
|
$this->assertEquals($attribute2['body']['key'], $collection['body']['indexes'][0]['attributes'][0]);
|
|
|
|
|
|
|
|
// Delete attribute
|
2021-09-28 12:38:03 +13:00
|
|
|
$deleted = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $collectionId . '/attributes/' . $attribute2['body']['key'], array_merge([
|
2021-09-21 13:23:41 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($deleted['headers']['status-code'], 204);
|
|
|
|
}
|
|
|
|
|
2021-09-03 09:38:46 +12:00
|
|
|
/**
|
|
|
|
* @depends testDeleteIndexOnDeleteAttribute
|
|
|
|
*/
|
2021-08-09 10:08:10 +12:00
|
|
|
public function testDeleteCollection($data)
|
|
|
|
{
|
|
|
|
$collectionId = $data['collectionId'];
|
|
|
|
|
2020-12-05 18:31:59 +13:00
|
|
|
// Add Documents to the collection
|
2021-08-09 10:08:10 +12:00
|
|
|
$document1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/documents', array_merge([
|
2020-12-05 18:31:59 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2021-07-19 21:26:00 +12:00
|
|
|
'documentId' => 'unique()',
|
2020-12-05 18:31:59 +13:00
|
|
|
'data' => [
|
|
|
|
'firstName' => 'Tom',
|
|
|
|
'lastName' => 'Holland',
|
|
|
|
],
|
2022-05-24 02:54:50 +12:00
|
|
|
'read' => ['user:' . $this->getUser()['$id']],
|
|
|
|
'write' => ['user:' . $this->getUser()['$id']],
|
2020-12-05 18:31:59 +13:00
|
|
|
]);
|
|
|
|
|
2021-08-09 10:08:10 +12:00
|
|
|
$document2 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/documents', array_merge([
|
2020-12-05 18:31:59 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2021-07-19 21:26:00 +12:00
|
|
|
'documentId' => 'unique()',
|
2020-12-05 18:31:59 +13:00
|
|
|
'data' => [
|
|
|
|
'firstName' => 'Samuel',
|
|
|
|
'lastName' => 'Jackson',
|
|
|
|
],
|
2022-05-24 02:54:50 +12:00
|
|
|
'read' => ['user:' . $this->getUser()['$id']],
|
|
|
|
'write' => ['user:' . $this->getUser()['$id']],
|
2020-12-05 18:31:59 +13:00
|
|
|
]);
|
2021-06-12 06:07:05 +12:00
|
|
|
|
2020-12-05 18:31:59 +13:00
|
|
|
$this->assertEquals($document1['headers']['status-code'], 201);
|
2021-06-12 06:07:05 +12:00
|
|
|
$this->assertIsArray($document1['body']['$read']);
|
|
|
|
$this->assertIsArray($document1['body']['$write']);
|
|
|
|
$this->assertCount(1, $document1['body']['$read']);
|
|
|
|
$this->assertCount(1, $document1['body']['$write']);
|
2020-12-05 18:31:59 +13:00
|
|
|
$this->assertEquals($document1['body']['firstName'], 'Tom');
|
|
|
|
$this->assertEquals($document1['body']['lastName'], 'Holland');
|
|
|
|
|
|
|
|
$this->assertEquals($document2['headers']['status-code'], 201);
|
2021-06-12 06:07:05 +12:00
|
|
|
$this->assertIsArray($document2['body']['$read']);
|
|
|
|
$this->assertIsArray($document2['body']['$write']);
|
|
|
|
$this->assertCount(1, $document2['body']['$read']);
|
|
|
|
$this->assertCount(1, $document2['body']['$write']);
|
2020-12-05 18:31:59 +13:00
|
|
|
$this->assertEquals($document2['body']['firstName'], 'Samuel');
|
|
|
|
$this->assertEquals($document2['body']['lastName'], 'Jackson');
|
|
|
|
|
|
|
|
// Delete the actors collection
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $collectionId, array_merge([
|
2020-12-05 18:31:59 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 204);
|
2022-05-24 02:54:50 +12:00
|
|
|
$this->assertEquals($response['body'], "");
|
2020-12-05 18:31:59 +13:00
|
|
|
|
|
|
|
// Try to get the collection and check if it has been deleted
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/database/collections/' . $collectionId, array_merge([
|
2020-12-05 18:31:59 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id']
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 404);
|
|
|
|
}
|
2021-07-30 11:36:46 +12:00
|
|
|
|
2021-10-27 08:15:46 +13:00
|
|
|
// Adds several minutes to test to replicate coverage in Utopia\Database unit tests
|
|
|
|
// and messes with subsequent tests as DatabaseV1 queue gets overwhelmed
|
|
|
|
// TODO@kodumbeats either fix or remove testAttributeCountLimit
|
|
|
|
// Options to fix:
|
|
|
|
// - Enable attribute creation in batches
|
|
|
|
// - Use additional database workers
|
|
|
|
// - Wait for worker to complete before moving onto next test
|
|
|
|
// - Remove since this is unit tested in Utopia\Database
|
|
|
|
//
|
|
|
|
// public function testAttributeCountLimit()
|
|
|
|
// {
|
|
|
|
// $collection = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
// 'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
// ]), [
|
|
|
|
// 'collectionId' => 'unique()',
|
|
|
|
// 'name' => 'attributeCountLimit',
|
|
|
|
// 'read' => ['role:all'],
|
|
|
|
// 'write' => ['role:all'],
|
|
|
|
// 'permission' => 'document',
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// $collectionId = $collection['body']['$id'];
|
|
|
|
|
|
|
|
// // load the collection up to the limit
|
|
|
|
// for ($i=0; $i < 1012; $i++) {
|
|
|
|
// $attribute = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/integer', array_merge([
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
// 'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
// ]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
// 'key' => "attribute{$i}",
|
2021-10-27 08:15:46 +13:00
|
|
|
// 'required' => false,
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// $this->assertEquals(201, $attribute['headers']['status-code']);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// sleep(30);
|
|
|
|
|
|
|
|
// $tooMany = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/integer', array_merge([
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
// 'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
// ]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
// 'key' => "tooMany",
|
2021-10-27 08:15:46 +13:00
|
|
|
// 'required' => false,
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// $this->assertEquals(400, $tooMany['headers']['status-code']);
|
|
|
|
// $this->assertEquals('Attribute limit exceeded', $tooMany['body']['message']);
|
|
|
|
// }
|
2021-08-05 09:05:09 +12:00
|
|
|
|
2021-09-01 04:35:03 +12:00
|
|
|
public function testAttributeRowWidthLimit()
|
|
|
|
{
|
|
|
|
$collection = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
|
|
|
'collectionId' => 'attributeRowWidthLimit',
|
|
|
|
'name' => 'attributeRowWidthLimit',
|
|
|
|
'read' => ['role:all'],
|
|
|
|
'write' => ['role:all'],
|
|
|
|
'permission' => 'document',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($collection['headers']['status-code'], 201);
|
|
|
|
$this->assertEquals($collection['body']['name'], 'attributeRowWidthLimit');
|
|
|
|
|
|
|
|
$collectionId = $collection['body']['$id'];
|
|
|
|
|
|
|
|
// Add wide string attributes to approach row width limit
|
2022-05-24 02:54:50 +12:00
|
|
|
for ($i = 0; $i < 15; $i++) {
|
2021-09-01 04:35:03 +12:00
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/string', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => "attribute{$i}",
|
2021-09-01 04:35:03 +12:00
|
|
|
'size' => 1024,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($attribute['headers']['status-code'], 201);
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(5);
|
|
|
|
|
|
|
|
$tooWide = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/string', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'tooWide',
|
2021-09-01 04:35:03 +12:00
|
|
|
'size' => 1024,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
2021-09-02 02:36:01 +12:00
|
|
|
$this->assertEquals(400, $tooWide['headers']['status-code']);
|
|
|
|
$this->assertEquals('Attribute limit exceeded', $tooWide['body']['message']);
|
2021-09-01 04:35:03 +12:00
|
|
|
}
|
|
|
|
|
2021-07-30 11:36:46 +12:00
|
|
|
public function testIndexLimitException()
|
|
|
|
{
|
|
|
|
$collection = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-08-12 05:25:22 +12:00
|
|
|
'collectionId' => 'testLimitException',
|
2021-07-30 11:36:46 +12:00
|
|
|
'name' => 'testLimitException',
|
|
|
|
'read' => ['role:all'],
|
|
|
|
'write' => ['role:all'],
|
2021-08-25 11:35:43 +12:00
|
|
|
'permission' => 'document',
|
2021-07-30 11:36:46 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($collection['headers']['status-code'], 201);
|
|
|
|
$this->assertEquals($collection['body']['name'], 'testLimitException');
|
|
|
|
|
|
|
|
$collectionId = $collection['body']['$id'];
|
|
|
|
|
|
|
|
// add unique attributes for indexing
|
2022-05-24 02:54:50 +12:00
|
|
|
for ($i = 0; $i < 64; $i++) {
|
2021-07-30 11:36:46 +12:00
|
|
|
// $this->assertEquals(true, static::getDatabase()->createAttribute('indexLimit', "test{$i}", Database::VAR_STRING, 16, true));
|
2021-08-12 05:25:22 +12:00
|
|
|
$attribute = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/string', array_merge([
|
2021-07-30 11:36:46 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => "attribute{$i}",
|
2021-07-30 11:36:46 +12:00
|
|
|
'size' => 64,
|
|
|
|
'required' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($attribute['headers']['status-code'], 201);
|
|
|
|
}
|
|
|
|
|
2021-10-27 08:15:46 +13:00
|
|
|
sleep(20);
|
2021-07-31 06:40:37 +12:00
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $collectionId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($collection['headers']['status-code'], 200);
|
|
|
|
$this->assertEquals($collection['body']['name'], 'testLimitException');
|
|
|
|
$this->assertIsArray($collection['body']['attributes']);
|
|
|
|
$this->assertIsArray($collection['body']['indexes']);
|
2021-08-12 05:25:22 +12:00
|
|
|
$this->assertCount(64, $collection['body']['attributes']);
|
|
|
|
$this->assertCount(0, $collection['body']['indexes']);
|
2021-07-30 11:36:46 +12:00
|
|
|
|
2021-10-26 13:14:12 +13:00
|
|
|
foreach ($collection['body']['attributes'] as $attribute) {
|
2021-10-27 08:15:46 +13:00
|
|
|
$this->assertEquals('available', $attribute['status'], 'attribute: ' . $attribute['key']);
|
2021-10-26 13:14:12 +13:00
|
|
|
}
|
|
|
|
|
2022-06-15 19:47:46 +12:00
|
|
|
// Test indexLimit = 64
|
|
|
|
// MariaDB, MySQL, and MongoDB create 5 indexes per new collection
|
2021-07-30 11:36:46 +12:00
|
|
|
// Add up to the limit, then check if the next index throws IndexLimitException
|
2022-06-15 05:15:22 +12:00
|
|
|
for ($i = 0; $i < 59; $i++) {
|
2021-07-30 11:36:46 +12:00
|
|
|
// $this->assertEquals(true, static::getDatabase()->createIndex('indexLimit', "index{$i}", Database::INDEX_KEY, ["test{$i}"], [16]));
|
|
|
|
$index = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/indexes', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => "key_attribute{$i}",
|
2021-07-31 06:40:37 +12:00
|
|
|
'type' => 'key',
|
2021-07-30 11:36:46 +12:00
|
|
|
'attributes' => ["attribute{$i}"],
|
|
|
|
]);
|
2021-07-31 06:40:37 +12:00
|
|
|
|
|
|
|
$this->assertEquals(201, $index['headers']['status-code']);
|
2021-08-25 11:35:43 +12:00
|
|
|
$this->assertEquals("key_attribute{$i}", $index['body']['key']);
|
2021-07-30 11:36:46 +12:00
|
|
|
}
|
|
|
|
|
2021-08-25 11:35:43 +12:00
|
|
|
sleep(5);
|
2021-07-30 11:36:46 +12:00
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $collectionId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
2021-07-31 06:40:37 +12:00
|
|
|
$this->assertEquals($collection['headers']['status-code'], 200);
|
|
|
|
$this->assertEquals($collection['body']['name'], 'testLimitException');
|
|
|
|
$this->assertIsArray($collection['body']['attributes']);
|
|
|
|
$this->assertIsArray($collection['body']['indexes']);
|
|
|
|
$this->assertCount(64, $collection['body']['attributes']);
|
2022-06-15 05:15:22 +12:00
|
|
|
$this->assertCount(59, $collection['body']['indexes']);
|
2021-07-31 06:40:37 +12:00
|
|
|
|
2021-07-30 11:36:46 +12:00
|
|
|
$tooMany = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/indexes', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2021-12-17 04:04:30 +13:00
|
|
|
'key' => 'tooMany',
|
2021-07-31 06:40:37 +12:00
|
|
|
'type' => 'key',
|
2021-08-25 11:35:43 +12:00
|
|
|
'attributes' => ['attribute61'],
|
2021-07-30 11:36:46 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $tooMany['headers']['status-code']);
|
2021-08-25 11:35:43 +12:00
|
|
|
$this->assertEquals('Index limit exceeded', $tooMany['body']['message']);
|
2021-09-03 04:46:05 +12:00
|
|
|
|
|
|
|
$collection = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $collectionId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(204, $collection['headers']['status-code']);
|
2021-07-30 11:36:46 +12:00
|
|
|
}
|
2022-05-24 02:54:50 +12:00
|
|
|
}
|