fix: pending tests.

This commit is contained in:
Darshan
2025-06-13 10:26:05 +05:30
parent 5f8c811f15
commit 44870b9810
5 changed files with 159 additions and 157 deletions
+4 -2
View File
@@ -145,7 +145,8 @@ jobs:
Account,
Avatars,
Console,
Databases,
Databases/Collections,
Databases/Tables,
Functions,
FunctionsSchedule,
GraphQL,
@@ -213,7 +214,8 @@ jobs:
Account,
Avatars,
Console,
Databases,
Databases/Collections,
Databases/Tables,
Functions,
FunctionsSchedule,
GraphQL,
@@ -1437,7 +1437,7 @@ trait DatabasesBase
], [
'key' => 'lengthTestIndex',
'type' => 'key',
'attributes' => ['title','description'],
'columns' => ['title','description'],
'lengths' => [128,200]
]);
$this->assertEquals(202, $create['headers']['status-code']);
@@ -1461,7 +1461,7 @@ trait DatabasesBase
], [
'key' => 'lengthOverrideTestIndex',
'type' => 'key',
'attributes' => ['actors'],
'columns' => ['actors'],
'lengths' => [120]
]);
$this->assertEquals(202, $create['headers']['status-code']);
@@ -1481,7 +1481,7 @@ trait DatabasesBase
], [
'key' => 'lengthCountExceededIndex',
'type' => 'key',
'attributes' => ['title'],
'columns' => ['title'],
'lengths' => [128, 128]
]);
$this->assertEquals(400, $create['headers']['status-code']);
@@ -1494,7 +1494,7 @@ trait DatabasesBase
], [
'key' => 'lengthTooLargeIndex',
'type' => 'key',
'attributes' => ['title','description','tagline','actors'],
'columns' => ['title','description','tagline','actors'],
'lengths' => [256,256,256,20]
]);
@@ -1508,7 +1508,7 @@ trait DatabasesBase
], [
'key' => 'negativeLengthIndex',
'type' => 'key',
'attributes' => ['title'],
'columns' => ['title'],
'lengths' => [-1]
]);
$this->assertEquals(400, $create['headers']['status-code']);
@@ -1679,12 +1679,6 @@ trait DatabasesBase
$this->assertEquals(400, $row4['headers']['status-code']);
// Delete document 4 with incomplete path
$this->assertEquals(404, $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()))['headers']['status-code']);
return $data;
}
@@ -1695,7 +1689,7 @@ trait DatabasesBase
{
$databaseId = $data['databaseId'];
$rowId = ID::unique();
$document = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$row = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -1710,16 +1704,16 @@ trait DatabasesBase
],
]);
$this->assertEquals(200, $document['headers']['status-code']);
$this->assertCount(3, $document['body']['$permissions']);
$document = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$this->assertEquals(200, $row['headers']['status-code']);
$this->assertCount(3, $row['body']['$permissions']);
$row = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals('Thor: Ragnarok', $document['body']['title']);
$this->assertEquals('Thor: Ragnarok', $row['body']['title']);
$document = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$row = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -1734,18 +1728,18 @@ trait DatabasesBase
],
]);
$this->assertEquals(200, $document['headers']['status-code']);
$this->assertEquals('Thor: Love and Thunder', $document['body']['title']);
$this->assertEquals(200, $row['headers']['status-code']);
$this->assertEquals('Thor: Love and Thunder', $row['body']['title']);
$document = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$row = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals('Thor: Love and Thunder', $document['body']['title']);
$this->assertEquals('Thor: Love and Thunder', $row['body']['title']);
// removing permission to read and delete
$document = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$row = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -1758,30 +1752,30 @@ trait DatabasesBase
],
]);
// shouldn't be able to read as no read permission
$document = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$row = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
switch ($this->getSide()) {
case 'client':
$this->assertEquals(404, $document['headers']['status-code']);
$this->assertEquals(404, $row['headers']['status-code']);
break;
case 'server':
$this->assertEquals(200, $document['headers']['status-code']);
$this->assertEquals(200, $row['headers']['status-code']);
break;
}
// shouldn't be able to delete as no delete permission
$document = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$row = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
// simulating for the client
// the document should not be allowed to be deleted as needed downward
// the row should not be allowed to be deleted as needed downward
if ($this->getSide() === 'client') {
$this->assertEquals(401, $document['headers']['status-code']);
$this->assertEquals(401, $row['headers']['status-code']);
}
// giving the delete permission
$document = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$row = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -1795,11 +1789,12 @@ trait DatabasesBase
Permission::delete(Role::users())
],
]);
$document = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
$row = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(204, $document['headers']['status-code']);
$this->assertEquals(204, $row['headers']['status-code']);
// relationship behaviour
$person = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
@@ -1815,7 +1810,7 @@ trait DatabasesBase
Permission::delete(Role::users()),
Permission::create(Role::users()),
],
'documentSecurity' => true,
'rowSecurity' => true,
]);
$this->assertEquals(201, $person['headers']['status-code']);
@@ -1833,7 +1828,7 @@ trait DatabasesBase
Permission::create(Role::users()),
Permission::delete(Role::users()),
],
'documentSecurity' => true,
'rowSecurity' => true,
]);
$this->assertEquals(201, $library['headers']['status-code']);
@@ -1855,7 +1850,7 @@ trait DatabasesBase
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'relatedtableId' => 'library-upsert',
'relatedTableId' => 'library-upsert',
'type' => Database::RELATION_ONE_TO_ONE,
'key' => 'library',
'twoWay' => true,
@@ -1903,7 +1898,7 @@ trait DatabasesBase
]);
$this->assertEquals('Library 1', $person1['body']['library']['libraryName']);
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $person['body']['$id'] . '/documents', array_merge([
$rows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $person['body']['$id'] . '/rows', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -1913,8 +1908,8 @@ trait DatabasesBase
],
]);
$this->assertEquals(1, $documents['body']['total']);
$this->assertEquals('Library 1', $documents['body']['documents'][0]['library']['libraryName']);
$this->assertEquals(1, $rows['body']['total']);
$this->assertEquals('Library 1', $rows['body']['rows'][0]['library']['libraryName']);
$person1 = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $person['body']['$id'] . '/rows/'.$rowId, array_merge([
@@ -1941,7 +1936,7 @@ trait DatabasesBase
// data should get updated
$this->assertEquals('Library 2', $person1['body']['library']['libraryName']);
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $person['body']['$id'] . '/documents', array_merge([
$rows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $person['body']['$id'] . '/rows', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -1951,9 +1946,8 @@ trait DatabasesBase
],
]);
$this->assertEquals(1, $documents['body']['total']);
$this->assertEquals('Library 2', $documents['body']['documents'][0]['library']['libraryName']);
$this->assertEquals(1, $rows['body']['total']);
$this->assertEquals('Library 2', $rows['body']['rows'][0]['library']['libraryName']);
// data should get added
$person1 = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $person['body']['$id'] . '/rows/'.ID::unique(), array_merge([
@@ -1979,7 +1973,8 @@ trait DatabasesBase
]);
$this->assertEquals('Library 2', $person1['body']['library']['libraryName']);
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $person['body']['$id'] . '/documents', array_merge([
$rows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $person['body']['$id'] . '/rows', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -1987,7 +1982,8 @@ trait DatabasesBase
Query::select(['fullName', 'library.*'])->toString()
],
]);
$this->assertEquals(2, $documents['body']['total']);
$this->assertEquals(2, $rows['body']['total']);
}
/**
@@ -2044,6 +2040,7 @@ trait DatabasesBase
'default' => null,
'required' => false,
]);
// creating a dummy doc with null description
$row1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows', array_merge([
'content-type' => 'application/json',
@@ -2242,7 +2239,7 @@ trait DatabasesBase
$this->assertCount(1, $rows['body']['rows']);
/**
* Test after with unknown document.
* Test after with unknown row.
*/
$rows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows', array_merge([
'content-type' => 'application/json',
@@ -3066,6 +3063,7 @@ trait DatabasesBase
$this->assertEquals('Minimum value must be lesser than maximum value', $invalidRange['body']['message']);
$this->assertEquals('Cannot set default value for array columns', $defaultArray['body']['message']);
$this->assertEquals(400, $datetimeDefault['headers']['status-code']);
// wait for worker to add attributes
sleep(3);
@@ -3073,7 +3071,7 @@ trait DatabasesBase
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]), []);
]));
$this->assertCount(10, $table['body']['columns']);
@@ -3387,6 +3385,8 @@ trait DatabasesBase
$this->assertEquals(400, $tooHigh['headers']['status-code']);
$this->assertEquals(400, $tooLow['headers']['status-code']);
$this->assertEquals(400, $badTime['headers']['status-code']);
// TODO: @itznotabug - database library needs to throw error based on context!
$this->assertEquals('Invalid document structure: Attribute "email" has invalid format. Value must be a valid email address', $badEmail['body']['message']);
$this->assertEquals('Invalid document structure: Attribute "enum" has invalid format. Value must be one of (yes, no, maybe)', $badEnum['body']['message']);
$this->assertEquals('Invalid document structure: Attribute "ip" has invalid format. Value must be a valid IP address', $badIp['body']['message']);
@@ -3457,7 +3457,7 @@ trait DatabasesBase
$this->assertEquals($row['body']['releaseYear'], 1945);
// This differs from the old permissions model because we don't inherit
// existing document permissions on update, unless none were supplied,
// existing row permissions on update, unless none were supplied,
// so that specific types can be removed if wanted.
$this->assertCount(2, $row['body']['$permissions']);
$this->assertEquals([
@@ -3500,7 +3500,7 @@ trait DatabasesBase
$this->assertCount(0, $row['body']['$permissions']);
$this->assertEquals([], $row['body']['$permissions']);
// Check client side can no longer read the document.
// Check client side can no longer read the row.
$row = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $id, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -3644,7 +3644,7 @@ trait DatabasesBase
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
// Current user has read permission on the collection so can get any document
// Current user has read permission on the table so can get any row
$this->assertEquals(3, $rowsUser1['body']['total']);
$this->assertCount(3, $rowsUser1['body']['rows']);
@@ -3653,7 +3653,7 @@ trait DatabasesBase
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
// Current user has read permission on the collection so can get any document
// Current user has read permission on the table so can get any row
$this->assertEquals(200, $row3GetWithCollectionRead['headers']['status-code']);
$email = uniqid() . 'user@localhost.test';
@@ -3686,7 +3686,7 @@ trait DatabasesBase
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session2,
]);
// Current user has no collection permissions but has read permission for this document
// Current user has no table permissions but has read permission for this row
$this->assertEquals(200, $row3GetWithDocumentRead['headers']['status-code']);
$row2GetFailure = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $tableId . '/rows/' . $row2['body']['$id'], [
@@ -3696,7 +3696,7 @@ trait DatabasesBase
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session2,
]);
// Current user has no collection or document permissions for this document
// Current user has no table or row permissions for this row
$this->assertEquals(404, $row2GetFailure['headers']['status-code']);
$rowsUser2 = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $tableId . '/rows', [
@@ -3706,7 +3706,7 @@ trait DatabasesBase
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session2,
]);
// Current user has no collection permissions but has read permission for one document
// Current user has no table permissions but has read permission for one row
$this->assertEquals(1, $rowsUser2['body']['total']);
$this->assertCount(1, $rowsUser2['body']['rows']);
}
@@ -3832,7 +3832,7 @@ trait DatabasesBase
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
// Current user has read permission on the collection so can get any document
// Current user has read permission on the table so can get any row
$this->assertEquals(3, $rowsUser1['body']['total']);
$this->assertCount(3, $rowsUser1['body']['rows']);
@@ -3841,7 +3841,7 @@ trait DatabasesBase
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
// Current user has read permission on the collection so can get any document
// Current user has read permission on the table so can get any row
$this->assertEquals(200, $row3GetWithCollectionRead['headers']['status-code']);
$email = uniqid() . 'user2@localhost.test';
@@ -3874,7 +3874,7 @@ trait DatabasesBase
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session2,
]);
// other2 has no collection permissions and document permissions are disabled
// other2 has no table permissions and row permissions are disabled
$this->assertEquals(404, $row3GetWithDocumentRead['headers']['status-code']);
$rowsUser2 = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $tableId . '/rows', [
@@ -3884,11 +3884,11 @@ trait DatabasesBase
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session2,
]);
// other2 has no collection permissions and document permissions are disabled
// other2 has no table permissions and row permissions are disabled
$this->assertEquals(401, $rowsUser2['headers']['status-code']);
// Enable document permissions
$table = $this->client->call(CLient::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $tableId, [
// Enable row permissions
$this->client->call(CLient::METHOD_PUT, '/databases/' . $databaseId . '/tables/' . $tableId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
@@ -3904,7 +3904,7 @@ trait DatabasesBase
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session2,
]);
// Current user has no collection permissions read access to one document
// Current user has no table permissions read access to one row
$this->assertEquals(1, $rowsUser2['body']['total']);
$this->assertCount(1, $rowsUser2['body']['rows']);
}
@@ -3952,7 +3952,7 @@ trait DatabasesBase
$this->assertEquals(409, $duplicate['headers']['status-code']);
// Test for exception when updating document to conflict
// Test for exception when updating row to conflict
$row = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -3975,7 +3975,7 @@ trait DatabasesBase
$this->assertEquals(201, $row['headers']['status-code']);
// Test for exception when updating document to conflict
// Test for exception when updating row to conflict
$duplicate = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $row['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -4078,7 +4078,7 @@ trait DatabasesBase
$databaseId = $database['body']['$id'];
// Create collection
// Create table
$movies = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -4116,7 +4116,7 @@ trait DatabasesBase
// wait for database worker to create attributes
sleep(2);
// add document
// add row
$row = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $moviesId . '/rows', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -4171,7 +4171,7 @@ trait DatabasesBase
$this->assertContains(Permission::delete(Role::user($this->getUser()['$id'])), $row['body']['$permissions']);
}
// remove collection
// remove table
$this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $moviesId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -4624,7 +4624,7 @@ trait DatabasesBase
{
$databaseId = $data['databaseId'];
// Create album collection
// Create album table
$albums = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -4650,7 +4650,7 @@ trait DatabasesBase
'required' => true,
]);
// Create artist collection
// Create artist table
$artists = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -4768,7 +4768,7 @@ trait DatabasesBase
{
$databaseId = $data['databaseId'];
// Create sports collection
// Create sports table
$sports = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -4794,7 +4794,7 @@ trait DatabasesBase
'required' => true,
]);
// Create player collection
// Create player table
$players = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -5326,20 +5326,20 @@ trait DatabasesBase
]);
$databaseId = $database['body']['$id'];
$collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
$table = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'tableId' => ID::unique(),
'name' => 'CounterCollection',
'documentSecurity' => true,
'rowSecurity' => true,
'permissions' => [
Permission::create(Role::user($this->getUser()['$id'])),
Permission::read(Role::user($this->getUser()['$id'])),
],
]);
$tableId = $collection['body']['$id'];
$tableId = $table['body']['$id'];
// Add integer attribute
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $tableId . '/columns/integer', array_merge([
@@ -5353,7 +5353,7 @@ trait DatabasesBase
\sleep(3);
// Create document with initial count = 5
// Create row with initial count = 5
$doc = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -5430,21 +5430,21 @@ trait DatabasesBase
$databaseId = $database['body']['$id'];
$collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
$table = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'tableId' => ID::unique(),
'name' => 'CounterCollection',
'documentSecurity' => true,
'rowSecurity' => true,
'permissions' => [
Permission::create(Role::user($this->getUser()['$id'])),
Permission::read(Role::user($this->getUser()['$id'])),
],
]);
$tableId = $collection['body']['$id'];
$tableId = $table['body']['$id'];
// Add integer attribute
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $tableId . '/columns/integer', array_merge([
@@ -5458,8 +5458,8 @@ trait DatabasesBase
\sleep(2);
// Create document with initial count = 10
$doc = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $tableId . '/documents', array_merge([
// Create row with initial count = 10
$doc = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $tableId . '/rows', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
@@ -17,7 +17,7 @@ class DatabasesPermissionsGuestTest extends Scope
use SideClient;
use DatabasesPermissionsScope;
public function createCollection(): array
public function createTable(): array
{
$database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([
'content-type' => 'application/json',
@@ -25,10 +25,10 @@ class DatabasesPermissionsGuestTest extends Scope
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'databaseId' => ID::unique(),
'name' => 'InvalidDocumentDatabase',
'name' => 'InvalidRowDatabase',
]);
$this->assertEquals(201, $database['headers']['status-code']);
$this->assertEquals('InvalidDocumentDatabase', $database['body']['name']);
$this->assertEquals('InvalidRowDatabase', $database['body']['name']);
$databaseId = $database['body']['$id'];
$publicMovies = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', $this->getServerHeader(), [
@@ -48,15 +48,15 @@ class DatabasesPermissionsGuestTest extends Scope
'rowSecurity' => true,
]);
$publicCollection = ['id' => $publicMovies['body']['$id']];
$privateCollection = ['id' => $privateMovies['body']['$id']];
$publicTable = ['id' => $publicMovies['body']['$id']];
$privateTable = ['id' => $privateMovies['body']['$id']];
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $publicCollection['id'] . '/columns/string', $this->getServerHeader(), [
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $publicTable['id'] . '/columns/string', $this->getServerHeader(), [
'key' => 'title',
'size' => 256,
'required' => true,
]);
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $privateCollection['id'] . '/columns/string', $this->getServerHeader(), [
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $privateTable['id'] . '/columns/string', $this->getServerHeader(), [
'key' => 'title',
'size' => 256,
'required' => true,
@@ -66,8 +66,8 @@ class DatabasesPermissionsGuestTest extends Scope
return [
'databaseId' => $databaseId,
'publicCollectionId' => $publicCollection['id'],
'privateCollectionId' => $privateCollection['id'],
'publicTableId' => $publicTable['id'],
'privateTableId' => $privateTable['id'],
];
}
@@ -86,21 +86,21 @@ class DatabasesPermissionsGuestTest extends Scope
/**
* @dataProvider permissionsProvider
*/
public function testReadDocuments($permissions)
public function testReadRows($permissions)
{
$data = $this->createCollection();
$publicCollectionId = $data['publicCollectionId'];
$privateCollectionId = $data['privateCollectionId'];
$data = $this->createTable();
$publicTableId = $data['publicTableId'];
$privateTableId = $data['privateTableId'];
$databaseId = $data['databaseId'];
$publicResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $publicCollectionId . '/rows', $this->getServerHeader(), [
$publicResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $publicTableId . '/rows', $this->getServerHeader(), [
'rowId' => ID::unique(),
'data' => [
'title' => 'Lorem',
],
'permissions' => $permissions,
]);
$privateResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $privateCollectionId . '/rows', $this->getServerHeader(), [
$privateResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $privateTableId . '/rows', $this->getServerHeader(), [
'rowId' => ID::unique(),
'data' => [
'title' => 'Lorem',
@@ -114,23 +114,23 @@ class DatabasesPermissionsGuestTest extends Scope
$roles = Authorization::getRoles();
Authorization::cleanRoles();
$publicDocuments = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $publicCollectionId . '/rows', [
$publicRows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $publicTableId . '/rows', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]);
$privateDocuments = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $privateCollectionId . '/rows', [
$privateRows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $privateTableId . '/rows', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]);
$this->assertEquals(1, $publicDocuments['body']['total']);
$this->assertEquals($permissions, $publicDocuments['body']['rows'][0]['$permissions']);
$this->assertEquals(1, $publicRows['body']['total']);
$this->assertEquals($permissions, $publicRows['body']['rows'][0]['$permissions']);
if (\in_array(Permission::read(Role::any()), $permissions)) {
$this->assertEquals(1, $privateDocuments['body']['total']);
$this->assertEquals($permissions, $privateDocuments['body']['rows'][0]['$permissions']);
$this->assertEquals(1, $privateRows['body']['total']);
$this->assertEquals($permissions, $privateRows['body']['rows'][0]['$permissions']);
} else {
$this->assertEquals(0, $privateDocuments['body']['total']);
$this->assertEquals(0, $privateRows['body']['total']);
}
foreach ($roles as $role) {
@@ -138,17 +138,17 @@ class DatabasesPermissionsGuestTest extends Scope
}
}
public function testWriteDocument()
public function testWriteRow()
{
$data = $this->createCollection();
$publicCollectionId = $data['publicCollectionId'];
$privateCollectionId = $data['privateCollectionId'];
$data = $this->createTable();
$publicTableId = $data['publicTableId'];
$privateTableId = $data['privateTableId'];
$databaseId = $data['databaseId'];
$roles = Authorization::getRoles();
Authorization::cleanRoles();
$publicResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $publicCollectionId . '/rows', [
$publicResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $publicTableId . '/rows', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], [
@@ -158,10 +158,10 @@ class DatabasesPermissionsGuestTest extends Scope
]
]);
$publicDocumentId = $publicResponse['body']['$id'];
$publicRowId = $publicResponse['body']['$id'];
$this->assertEquals(201, $publicResponse['headers']['status-code']);
$privateResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $privateCollectionId . '/rows', [
$privateResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $privateTableId . '/rows', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], [
@@ -173,8 +173,8 @@ class DatabasesPermissionsGuestTest extends Scope
$this->assertEquals(401, $privateResponse['headers']['status-code']);
// Create a document in private collection with API key so we can test that update and delete are also not allowed
$privateResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $privateCollectionId . '/rows', $this->getServerHeader(), [
// Create a row in private collection with API key so we can test that update and delete are also not allowed
$privateResponse = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables/' . $privateTableId . '/rows', $this->getServerHeader(), [
'rowId' => ID::unique(),
'data' => [
'title' => 'Lorem',
@@ -182,9 +182,9 @@ class DatabasesPermissionsGuestTest extends Scope
]);
$this->assertEquals(201, $privateResponse['headers']['status-code']);
$privateDocumentId = $privateResponse['body']['$id'];
$privateRowId = $privateResponse['body']['$id'];
$publicDocument = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/tables/' . $publicCollectionId . '/rows/' . $publicDocumentId, [
$publicRow = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/tables/' . $publicTableId . '/rows/' . $publicRowId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], [
@@ -193,10 +193,10 @@ class DatabasesPermissionsGuestTest extends Scope
],
]);
$this->assertEquals(200, $publicDocument['headers']['status-code']);
$this->assertEquals('Thor: Ragnarok', $publicDocument['body']['title']);
$this->assertEquals(200, $publicRow['headers']['status-code']);
$this->assertEquals('Thor: Ragnarok', $publicRow['body']['title']);
$privateDocument = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/tables/' . $privateCollectionId . '/rows/' . $privateDocumentId, [
$privateRow = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/tables/' . $privateTableId . '/rows/' . $privateRowId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], [
@@ -205,28 +205,28 @@ class DatabasesPermissionsGuestTest extends Scope
],
]);
$this->assertEquals(401, $privateDocument['headers']['status-code']);
$this->assertEquals(401, $privateRow['headers']['status-code']);
$publicDocument = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $publicCollectionId . '/rows/' . $publicDocumentId, [
$publicRow = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $publicTableId . '/rows/' . $publicRowId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]);
$this->assertEquals(204, $publicDocument['headers']['status-code']);
$this->assertEquals(204, $publicRow['headers']['status-code']);
$privateDocument = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $privateCollectionId . '/rows/' . $privateDocumentId, [
$privateRow = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/tables/' . $privateTableId . '/rows/' . $privateRowId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]);
$this->assertEquals(401, $privateDocument['headers']['status-code']);
$this->assertEquals(401, $privateRow['headers']['status-code']);
foreach ($roles as $role) {
Authorization::setRole($role);
}
}
public function testWriteDocumentWithPermissions()
public function testWriteRowWithPermissions()
{
$database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([
'content-type' => 'application/json',
@@ -168,7 +168,7 @@ class DatabasesPermissionsMemberTest extends Scope
$doconly = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/tables', $this->getServerHeader(), [
'tableId' => ID::unique(),
'name' => 'Document Only Movies',
'name' => 'Row Only Movies',
'permissions' => [],
'rowSecurity' => true,
]);
@@ -196,7 +196,7 @@ class DatabasesPermissionsMemberTest extends Scope
* @dataProvider permissionsProvider
* @depends testSetupDatabase
*/
public function testReadDocuments($permissions, $anyCount, $usersCount, $docOnlyCount, $data)
public function testReadRows($permissions, $anyCount, $usersCount, $docOnlyCount, $data)
{
$users = $data['users'];
$tables = $data['tables'];
@@ -230,7 +230,7 @@ class DatabasesPermissionsMemberTest extends Scope
$this->assertEquals(201, $response['headers']['status-code']);
/**
* Check "any" permission collection
* Check "any" permission table
*/
$rows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $tables['public'] . '/rows', [
'origin' => 'http://localhost',
@@ -243,7 +243,7 @@ class DatabasesPermissionsMemberTest extends Scope
$this->assertEquals($anyCount, $rows['body']['total']);
/**
* Check "users" permission collection
* Check "users" permission table
*/
$rows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $tables['private'] . '/rows', [
'origin' => 'http://localhost',
@@ -256,7 +256,7 @@ class DatabasesPermissionsMemberTest extends Scope
$this->assertEquals($usersCount, $rows['body']['total']);
/**
* Check "user:user1" document only permission collection
* Check "user:user1" row only permission table
*/
$rows = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/tables/' . $tables['doconly'] . '/rows', [
'origin' => 'http://localhost',
@@ -36,7 +36,7 @@ class DatabasesPermissionsTeamTest extends Scope
];
}
public function createCollections($teams)
public function createTables($teams)
{
$db = $this->client->call(Client::METHOD_POST, '/databases', $this->getServerHeader(), [
'databaseId' => $this->databaseId,
@@ -45,8 +45,8 @@ class DatabasesPermissionsTeamTest extends Scope
$this->assertEquals(201, $db['headers']['status-code']);
$table1 = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables', $this->getServerHeader(), [
'tableId' => ID::custom('collection1'),
'name' => 'Collection 1',
'tableId' => ID::custom('table1'),
'name' => 'Table 1',
'permissions' => [
Permission::read(Role::team($teams['team1']['$id'])),
Permission::create(Role::team($teams['team1']['$id'], 'admin')),
@@ -55,17 +55,17 @@ class DatabasesPermissionsTeamTest extends Scope
],
]);
$this->collections['collection1'] = $table1['body']['$id'];
$this->tables['table1'] = $table1['body']['$id'];
$this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $this->collections['collection1'] . '/columns/string', $this->getServerHeader(), [
$this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $this->tables['table1'] . '/columns/string', $this->getServerHeader(), [
'key' => 'title',
'size' => 256,
'required' => true,
]);
$table2 = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables', $this->getServerHeader(), [
'tableId' => ID::custom('collection2'),
'name' => 'Collection 2',
'tableId' => ID::custom('table2'),
'name' => 'Table 2',
'permissions' => [
Permission::read(Role::team($teams['team2']['$id'])),
Permission::create(Role::team($teams['team2']['$id'], 'owner')),
@@ -74,9 +74,9 @@ class DatabasesPermissionsTeamTest extends Scope
]
]);
$this->collections['collection2'] = $table2['body']['$id'];
$this->tables['table2'] = $table2['body']['$id'];
$this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $this->collections['collection2'] . '/columns/string', $this->getServerHeader(), [
$this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $this->tables['table2'] . '/columns/string', $this->getServerHeader(), [
'key' => 'title',
'size' => 256,
'required' => true,
@@ -84,22 +84,22 @@ class DatabasesPermissionsTeamTest extends Scope
sleep(2);
return $this->collections;
return $this->tables;
}
/*
* $success = can $user read from $table
* [$user, $table, $success]
*/
public function readDocumentsProvider(): array
public function readRowsProvider(): array
{
return [
['user1', 'collection1', true],
['user2', 'collection1', false],
['user3', 'collection1', true],
['user1', 'collection2', false],
['user2', 'collection2', true],
['user3', 'collection2', true],
['user1', 'table1', true],
['user2', 'table1', false],
['user3', 'table1', true],
['user1', 'table2', false],
['user2', 'table2', true],
['user3', 'table2', true],
];
}
@@ -107,15 +107,15 @@ class DatabasesPermissionsTeamTest extends Scope
* $success = can $user write to $table
* [$user, $table, $success]
*/
public function writeDocumentsProvider(): array
public function writeRowsProvider(): array
{
return [
['user1', 'collection1', true],
['user2', 'collection1', false],
['user3', 'collection1', false],
['user1', 'collection2', false],
['user2', 'collection2', true],
['user3', 'collection2', false],
['user1', 'table1', true],
['user2', 'table1', false],
['user3', 'table1', false],
['user1', 'table2', false],
['user2', 'table2', true],
['user3', 'table2', false],
];
}
@@ -138,9 +138,9 @@ class DatabasesPermissionsTeamTest extends Scope
$this->addToTeam('user3', 'team1');
$this->addToTeam('user3', 'team2');
$this->createCollections($this->teams);
$this->createTables($this->teams);
$response = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $this->collections['collection1'] . '/rows', $this->getServerHeader(), [
$response = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $this->tables['table1'] . '/rows', $this->getServerHeader(), [
'rowId' => ID::unique(),
'data' => [
'title' => 'Lorem',
@@ -148,7 +148,7 @@ class DatabasesPermissionsTeamTest extends Scope
]);
$this->assertEquals(201, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $this->collections['collection2'] . '/rows', $this->getServerHeader(), [
$response = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $this->tables['table2'] . '/rows', $this->getServerHeader(), [
'rowId' => ID::unique(),
'data' => [
'title' => 'Ipsum',
@@ -162,9 +162,9 @@ class DatabasesPermissionsTeamTest extends Scope
/**
* Data provider params are passed before test dependencies
* @depends testSetupDatabase
* @dataProvider readDocumentsProvider
* @dataProvider readRowsProvider
*/
public function testReadDocuments($user, $table, $success, $users)
public function testReadRows($user, $table, $success, $users)
{
$rows = $this->client->call(Client::METHOD_GET, '/databases/' . $this->databaseId . '/tables/' . $table . '/rows', [
'origin' => 'http://localhost',
@@ -182,9 +182,9 @@ class DatabasesPermissionsTeamTest extends Scope
/**
* @depends testSetupDatabase
* @dataProvider writeDocumentsProvider
* @dataProvider writeRowsProvider
*/
public function testWriteDocuments($user, $table, $success, $users)
public function testWriteRows($user, $table, $success, $users)
{
$rows = $this->client->call(Client::METHOD_POST, '/databases/' . $this->databaseId . '/tables/' . $table . '/rows', [
'origin' => 'http://localhost',