2022-06-30 12:00:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
2025-08-19 11:03:18 +00:00
|
|
|
namespace Tests\E2E\Services\GraphQL\TablesDB;
|
2022-06-30 12:00:00 +00:00
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
use Tests\E2E\Client;
|
2022-06-30 12:00:00 +00:00
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
|
use Tests\E2E\Scopes\SideClient;
|
2025-05-09 14:34:02 +00:00
|
|
|
use Tests\E2E\Services\GraphQL\Base;
|
2023-01-16 09:25:40 +00:00
|
|
|
use Utopia\Database\Helpers\ID;
|
|
|
|
|
use Utopia\Database\Helpers\Permission;
|
|
|
|
|
use Utopia\Database\Helpers\Role;
|
2025-06-13 08:34:23 +00:00
|
|
|
use Utopia\Database\Query;
|
2022-06-30 12:00:00 +00:00
|
|
|
|
2022-09-22 08:29:42 +00:00
|
|
|
class DatabaseClientTest extends Scope
|
2022-06-30 12:00:00 +00:00
|
|
|
{
|
|
|
|
|
use ProjectCustom;
|
|
|
|
|
use SideClient;
|
2022-09-22 08:29:42 +00:00
|
|
|
use Base;
|
2022-07-07 00:53:58 +00:00
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* Cached database data
|
|
|
|
|
*/
|
|
|
|
|
private static array $cachedDatabase = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cached table data (includes database)
|
|
|
|
|
*/
|
|
|
|
|
private static array $cachedTable = [];
|
|
|
|
|
|
|
|
|
|
/**
|
2026-02-09 01:20:42 +00:00
|
|
|
* Cached columns setup flag (keyed by project)
|
2026-02-05 23:01:31 +00:00
|
|
|
*/
|
2026-02-09 01:20:42 +00:00
|
|
|
private static array $columnsCreated = [];
|
2026-02-05 23:01:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cached row data (includes database, table, row)
|
|
|
|
|
*/
|
|
|
|
|
private static array $cachedRow = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cached bulk create data
|
|
|
|
|
*/
|
|
|
|
|
private static array $cachedBulkCreate = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cached bulk upsert data
|
|
|
|
|
*/
|
|
|
|
|
private static array $cachedBulkUpsert = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper method to set up a database
|
|
|
|
|
*/
|
|
|
|
|
protected function setupDatabase(): array
|
2022-07-07 00:53:58 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
if (!empty(self::$cachedDatabase)) {
|
|
|
|
|
return self::$cachedDatabase;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::TABLESDB_CREATE_DATABASE);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-09-22 01:53:41 +00:00
|
|
|
'databaseId' => ID::unique(),
|
2022-07-07 00:53:58 +00:00
|
|
|
'name' => 'Actors',
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$database = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
], $gqlPayload);
|
|
|
|
|
|
|
|
|
|
$this->assertIsArray($database['body']['data']);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $database['body']);
|
2025-08-20 14:20:05 +00:00
|
|
|
$database = $database['body']['data']['tablesDBCreate'];
|
2022-07-07 00:53:58 +00:00
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
self::$cachedDatabase = $database;
|
|
|
|
|
return self::$cachedDatabase;
|
2022-07-07 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* Helper method to set up a table (includes database setup)
|
|
|
|
|
*/
|
|
|
|
|
protected function setupTable(): array
|
2022-07-07 00:53:58 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
if (!empty(self::$cachedTable)) {
|
|
|
|
|
return self::$cachedTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$database = $this->setupDatabase();
|
|
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::CREATE_TABLE);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $database['_id'],
|
2026-02-09 01:20:42 +00:00
|
|
|
'tableId' => ID::unique(),
|
2022-07-07 00:53:58 +00:00
|
|
|
'name' => 'Actors',
|
2025-05-09 14:34:02 +00:00
|
|
|
'rowSecurity' => false,
|
2022-09-21 08:17:17 +00:00
|
|
|
'permissions' => [
|
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
|
Permission::create(Role::users()),
|
|
|
|
|
Permission::update(Role::users()),
|
|
|
|
|
Permission::delete(Role::users()),
|
|
|
|
|
],
|
2022-07-07 00:53:58 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$table = $this->client->call(Client::METHOD_POST, '/graphql', [
|
2022-07-07 00:53:58 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
], $gqlPayload);
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$this->assertIsArray($table['body']['data']);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $table['body']);
|
2025-08-20 14:20:05 +00:00
|
|
|
$table = $table['body']['data']['tablesDBCreateTable'];
|
2022-07-07 00:53:58 +00:00
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
self::$cachedTable = [
|
2025-05-09 14:34:02 +00:00
|
|
|
'table' => $table,
|
2022-07-07 00:53:58 +00:00
|
|
|
'database' => $database,
|
|
|
|
|
];
|
2026-02-05 23:01:31 +00:00
|
|
|
return self::$cachedTable;
|
2022-07-07 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* Helper method to set up columns (string and integer)
|
|
|
|
|
*/
|
|
|
|
|
protected function setupColumns(): array
|
2022-07-07 00:53:58 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
$data = $this->setupTable();
|
|
|
|
|
|
2026-02-09 01:20:42 +00:00
|
|
|
$cacheKey = $this->getProject()['$id'] ?? 'default';
|
|
|
|
|
if (!empty(self::$columnsCreated[$cacheKey])) {
|
2026-02-05 23:01:31 +00:00
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2026-02-05 23:01:31 +00:00
|
|
|
$headers = [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Create string column
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::CREATE_STRING_COLUMN);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 14:34:02 +00:00
|
|
|
'tableId' => $data['table']['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
'key' => 'name',
|
|
|
|
|
'size' => 256,
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
$column = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $gqlPayload);
|
2026-02-09 01:20:42 +00:00
|
|
|
// Handle 409 conflict - column may already exist from individual test
|
|
|
|
|
if (isset($column['body']['errors'])) {
|
|
|
|
|
$errorMessage = $column['body']['errors'][0]['message'] ?? '';
|
|
|
|
|
if (strpos($errorMessage, 'already exists') === false && strpos($errorMessage, 'Document with the requested ID already exists') === false) {
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $column['body']);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-07 00:53:58 +00:00
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
// Create integer column
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::CREATE_INTEGER_COLUMN);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 14:34:02 +00:00
|
|
|
'tableId' => $data['table']['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
'key' => 'age',
|
|
|
|
|
'min' => 18,
|
|
|
|
|
'max' => 150,
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
$column = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $gqlPayload);
|
2026-02-09 01:20:42 +00:00
|
|
|
// Handle 409 conflict - column may already exist from individual test
|
|
|
|
|
if (isset($column['body']['errors'])) {
|
|
|
|
|
$errorMessage = $column['body']['errors'][0]['message'] ?? '';
|
|
|
|
|
if (strpos($errorMessage, 'already exists') === false && strpos($errorMessage, 'Document with the requested ID already exists') === false) {
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $column['body']);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-07 00:53:58 +00:00
|
|
|
|
2026-02-09 01:20:42 +00:00
|
|
|
self::$columnsCreated[$cacheKey] = true;
|
2022-07-07 00:53:58 +00:00
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* Helper method to set up a row (includes database, table, and columns setup)
|
|
|
|
|
*/
|
|
|
|
|
protected function setupRow(): array
|
2022-07-07 00:53:58 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
if (!empty(self::$cachedRow)) {
|
|
|
|
|
return self::$cachedRow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = $this->setupColumns();
|
2026-02-09 01:20:42 +00:00
|
|
|
sleep(3);
|
2022-07-07 00:53:58 +00:00
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::CREATE_ROW);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 14:34:02 +00:00
|
|
|
'tableId' => $data['table']['_id'],
|
|
|
|
|
'rowId' => ID::unique(),
|
2022-07-07 00:53:58 +00:00
|
|
|
'data' => [
|
|
|
|
|
'name' => 'John Doe',
|
|
|
|
|
'age' => 35,
|
|
|
|
|
],
|
2022-09-21 08:17:17 +00:00
|
|
|
'permissions' => [
|
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
|
Permission::update(Role::any()),
|
|
|
|
|
Permission::delete(Role::any()),
|
|
|
|
|
],
|
2022-07-07 00:53:58 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$row = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
2022-07-07 00:53:58 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$this->assertArrayNotHasKey('errors', $row['body']);
|
|
|
|
|
$this->assertIsArray($row['body']['data']);
|
2022-07-07 00:53:58 +00:00
|
|
|
|
2025-08-20 14:20:05 +00:00
|
|
|
$row = $row['body']['data']['tablesDBCreateRow'];
|
2025-05-09 14:34:02 +00:00
|
|
|
$this->assertIsArray($row);
|
2022-07-07 00:53:58 +00:00
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
self::$cachedRow = [
|
2022-07-07 00:53:58 +00:00
|
|
|
'database' => $data['database'],
|
2025-05-09 14:34:02 +00:00
|
|
|
'table' => $data['table'],
|
|
|
|
|
'row' => $row,
|
2022-07-07 00:53:58 +00:00
|
|
|
];
|
2026-02-05 23:01:31 +00:00
|
|
|
return self::$cachedRow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper method to set up bulk create data
|
|
|
|
|
*/
|
|
|
|
|
protected function setupBulkCreate(): array
|
|
|
|
|
{
|
|
|
|
|
if (!empty(self::$cachedBulkCreate)) {
|
|
|
|
|
return self::$cachedBulkCreate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$project = $this->getProject();
|
|
|
|
|
$projectId = $project['$id'];
|
|
|
|
|
$headers = [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
'x-appwrite-key' => $project['apiKey'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Step 1: Create database
|
|
|
|
|
$query = $this->getQuery(self::TABLESDB_CREATE_DATABASE);
|
|
|
|
|
$payload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2026-02-09 01:20:42 +00:00
|
|
|
'databaseId' => ID::unique(),
|
2026-02-05 23:01:31 +00:00
|
|
|
'name' => 'Bulk',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
|
|
|
|
$databaseId = $res['body']['data']['tablesDBCreate']['_id'];
|
|
|
|
|
|
|
|
|
|
// Step 2: Create table
|
|
|
|
|
$query = $this->getQuery(self::CREATE_TABLE);
|
|
|
|
|
$payload['query'] = $query;
|
|
|
|
|
$payload['variables'] = [
|
|
|
|
|
'databaseId' => $databaseId,
|
2026-02-09 01:20:42 +00:00
|
|
|
'tableId' => ID::unique(),
|
2026-02-05 23:01:31 +00:00
|
|
|
'name' => 'Operations',
|
|
|
|
|
'rowSecurity' => false,
|
|
|
|
|
'permissions' => [
|
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
|
Permission::update(Role::any()),
|
|
|
|
|
Permission::delete(Role::any()),
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
|
|
|
|
$tableId = $res['body']['data']['tablesDBCreateTable']['_id'];
|
|
|
|
|
|
|
|
|
|
// Step 3: Create column
|
|
|
|
|
$query = $this->getQuery(self::CREATE_STRING_COLUMN);
|
|
|
|
|
$payload['query'] = $query;
|
|
|
|
|
$payload['variables'] = [
|
|
|
|
|
'databaseId' => $databaseId,
|
|
|
|
|
'tableId' => $tableId,
|
|
|
|
|
'key' => 'name',
|
|
|
|
|
'size' => 256,
|
|
|
|
|
'required' => true,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
|
|
// Step 4: Create rows
|
|
|
|
|
$query = $this->getQuery(self::CREATE_ROWS);
|
|
|
|
|
$rows = [];
|
|
|
|
|
for ($i = 1; $i <= 10; $i++) {
|
2026-02-09 01:20:42 +00:00
|
|
|
$rows[] = ['$id' => ID::unique(), 'name' => 'Row #' . $i];
|
2026-02-05 23:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$payload['query'] = $query;
|
|
|
|
|
$payload['variables'] = [
|
|
|
|
|
'databaseId' => $databaseId,
|
|
|
|
|
'tableId' => $tableId,
|
|
|
|
|
'rows' => $rows,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
|
|
|
|
$this->assertCount(10, $res['body']['data']['tablesDBCreateRows']['rows']);
|
|
|
|
|
|
|
|
|
|
self::$cachedBulkCreate = compact('databaseId', 'tableId', 'projectId');
|
|
|
|
|
return self::$cachedBulkCreate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper method to set up bulk upsert data (includes bulk create and bulk update)
|
|
|
|
|
*/
|
|
|
|
|
protected function setupBulkUpsert(): array
|
|
|
|
|
{
|
|
|
|
|
if (!empty(self::$cachedBulkUpsert)) {
|
|
|
|
|
return self::$cachedBulkUpsert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = $this->setupBulkCreate();
|
|
|
|
|
|
|
|
|
|
$userId = $this->getUser()['$id'];
|
|
|
|
|
$permissions = [
|
|
|
|
|
Permission::read(Role::user($userId)),
|
|
|
|
|
Permission::update(Role::user($userId)),
|
|
|
|
|
Permission::delete(Role::user($userId)),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$headers = [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $data['projectId'],
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Step 1: Bulk update rows
|
|
|
|
|
$query = $this->getQuery(self::UPDATE_ROWS);
|
|
|
|
|
$payload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
|
|
|
|
'data' => [
|
|
|
|
|
'name' => 'Rows Updated',
|
|
|
|
|
'$permissions' => $permissions,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
|
|
|
|
$this->assertCount(10, $res['body']['data']['tablesDBUpdateRows']['rows']);
|
|
|
|
|
|
2026-02-09 01:20:42 +00:00
|
|
|
// Step 2: Add two new rows via upsert
|
2026-02-05 23:01:31 +00:00
|
|
|
$query = $this->getQuery(self::UPSERT_ROWS);
|
|
|
|
|
$upsertPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
|
|
|
|
'rows' => [
|
|
|
|
|
[
|
2026-02-09 01:20:42 +00:00
|
|
|
'$id' => ID::unique(),
|
2026-02-05 23:01:31 +00:00
|
|
|
'name' => 'Row #1000',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'name' => 'Row #11',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $upsertPayload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $response['body']);
|
|
|
|
|
|
|
|
|
|
$rows = $response['body']['data']['tablesDBUpsertRows']['rows'];
|
|
|
|
|
$this->assertCount(2, $rows);
|
|
|
|
|
|
|
|
|
|
// Step 3: Upsert row with new permissions using `tablesUpsertRow`
|
2026-02-09 01:20:42 +00:00
|
|
|
$upsertRowId = ID::unique();
|
2026-02-05 23:01:31 +00:00
|
|
|
$query = $this->getQuery(self::UPSERT_ROW);
|
|
|
|
|
$payload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
2026-02-09 01:20:42 +00:00
|
|
|
'rowId' => $upsertRowId,
|
|
|
|
|
'data' => ['name' => 'Row Upserted'],
|
2026-02-05 23:01:31 +00:00
|
|
|
'permissions' => $permissions,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
|
|
|
|
|
|
|
|
|
self::$cachedBulkUpsert = $data;
|
|
|
|
|
return self::$cachedBulkUpsert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateDatabase(): void
|
|
|
|
|
{
|
|
|
|
|
$database = $this->setupDatabase();
|
|
|
|
|
$this->assertEquals('Actors', $database['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateTable(): void
|
|
|
|
|
{
|
|
|
|
|
$data = $this->setupTable();
|
|
|
|
|
$this->assertEquals('Actors', $data['table']['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateStringColumn(): void
|
|
|
|
|
{
|
|
|
|
|
$data = $this->setupTable();
|
|
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::CREATE_STRING_COLUMN);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
|
|
|
|
'tableId' => $data['table']['_id'],
|
|
|
|
|
'key' => 'name',
|
|
|
|
|
'size' => 256,
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$column = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
], $gqlPayload);
|
|
|
|
|
|
|
|
|
|
// Column may already exist from setupColumns, so we just check for valid response
|
|
|
|
|
$this->assertIsArray($column['body']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateIntegerColumn(): void
|
|
|
|
|
{
|
|
|
|
|
$data = $this->setupTable();
|
|
|
|
|
|
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
$query = $this->getQuery(self::CREATE_INTEGER_COLUMN);
|
|
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['database']['_id'],
|
|
|
|
|
'tableId' => $data['table']['_id'],
|
|
|
|
|
'key' => 'age',
|
|
|
|
|
'min' => 18,
|
|
|
|
|
'max' => 150,
|
|
|
|
|
'required' => true,
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$column = $this->client->call(Client::METHOD_POST, '/graphql', [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
], $gqlPayload);
|
|
|
|
|
|
|
|
|
|
// Column may already exist from setupColumns, so we just check for valid response
|
|
|
|
|
$this->assertIsArray($column['body']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateRow(): void
|
|
|
|
|
{
|
|
|
|
|
$data = $this->setupRow();
|
|
|
|
|
$this->assertIsArray($data['row']);
|
2022-07-07 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2026-02-05 23:01:31 +00:00
|
|
|
public function testGetRows(): void
|
2022-07-07 00:53:58 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
$data = $this->setupTable();
|
|
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::GET_ROWS);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 14:34:02 +00:00
|
|
|
'tableId' => $data['table']['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$rows = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
2022-07-07 00:53:58 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$this->assertArrayNotHasKey('errors', $rows['body']);
|
|
|
|
|
$this->assertIsArray($rows['body']['data']);
|
2025-08-20 14:20:05 +00:00
|
|
|
$this->assertIsArray($rows['body']['data']['tablesDBListRows']);
|
2022-07-07 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2026-02-05 23:01:31 +00:00
|
|
|
public function testGetDocument(): void
|
2022-07-07 00:53:58 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
$data = $this->setupRow();
|
|
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::GET_ROW);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 14:34:02 +00:00
|
|
|
'tableId' => $data['table']['_id'],
|
|
|
|
|
'rowId' => $data['row']['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$row = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
2022-07-07 00:53:58 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$this->assertArrayNotHasKey('errors', $row['body']);
|
|
|
|
|
$this->assertIsArray($row['body']['data']);
|
2025-08-20 14:20:05 +00:00
|
|
|
$this->assertIsArray($row['body']['data']['tablesDBGetRow']);
|
2022-07-07 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2026-02-05 23:01:31 +00:00
|
|
|
public function testUpdateRow(): void
|
2022-07-07 00:53:58 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
$data = $this->setupRow();
|
|
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::UPDATE_ROW);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 14:34:02 +00:00
|
|
|
'tableId' => $data['table']['_id'],
|
|
|
|
|
'rowId' => $data['row']['_id'],
|
2022-07-07 00:53:58 +00:00
|
|
|
'data' => [
|
2025-05-09 14:34:02 +00:00
|
|
|
'name' => 'New Row Name',
|
2022-07-07 00:53:58 +00:00
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$row = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
2022-07-07 00:53:58 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$this->assertArrayNotHasKey('errors', $row['body']);
|
|
|
|
|
$this->assertIsArray($row['body']['data']);
|
2025-08-20 14:20:05 +00:00
|
|
|
$row = $row['body']['data']['tablesDBUpdateRow'];
|
2025-05-09 14:34:02 +00:00
|
|
|
$this->assertIsArray($row);
|
2022-12-08 03:08:57 +00:00
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$this->assertStringContainsString('New Row Name', $row['data']);
|
2022-07-07 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2026-02-05 23:01:31 +00:00
|
|
|
public function testDeleteRow(): void
|
2022-07-07 00:53:58 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
// Need to create a fresh row for deletion since we can't delete the cached row
|
|
|
|
|
$data = $this->setupColumns();
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
2022-07-07 00:53:58 +00:00
|
|
|
$projectId = $this->getProject()['$id'];
|
2026-02-05 23:01:31 +00:00
|
|
|
|
|
|
|
|
// Create a new row specifically for deletion
|
|
|
|
|
$query = $this->getQuery(self::CREATE_ROW);
|
2022-07-07 00:53:58 +00:00
|
|
|
$gqlPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2022-12-08 03:08:57 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
2025-05-09 14:34:02 +00:00
|
|
|
'tableId' => $data['table']['_id'],
|
2026-02-05 23:01:31 +00:00
|
|
|
'rowId' => ID::unique(),
|
|
|
|
|
'data' => [
|
|
|
|
|
'name' => 'Row To Delete',
|
|
|
|
|
'age' => 25,
|
|
|
|
|
],
|
|
|
|
|
'permissions' => [
|
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
|
Permission::update(Role::any()),
|
|
|
|
|
Permission::delete(Role::any()),
|
|
|
|
|
],
|
2022-07-07 00:53:58 +00:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
|
2025-05-09 14:34:02 +00:00
|
|
|
$row = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
2022-07-07 00:53:58 +00:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
$this->assertArrayNotHasKey('errors', $row['body']);
|
|
|
|
|
$row = $row['body']['data']['tablesDBCreateRow'];
|
2025-06-13 08:34:23 +00:00
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
// Now delete the row
|
|
|
|
|
$query = $this->getQuery(self::DELETE_ROW);
|
|
|
|
|
$gqlPayload = [
|
2025-06-13 08:34:23 +00:00
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
2026-02-05 23:01:31 +00:00
|
|
|
'databaseId' => $data['database']['_id'],
|
|
|
|
|
'tableId' => $data['table']['_id'],
|
|
|
|
|
'rowId' => $row['_id'],
|
|
|
|
|
]
|
2025-06-13 08:34:23 +00:00
|
|
|
];
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
$result = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
|
], $this->getHeaders()), $gqlPayload);
|
2025-06-13 08:34:23 +00:00
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
$this->assertIsNotArray($result['body']);
|
|
|
|
|
$this->assertEquals(204, $result['headers']['status-code']);
|
|
|
|
|
}
|
2025-06-13 08:34:23 +00:00
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
public function testBulkCreate(): void
|
|
|
|
|
{
|
|
|
|
|
$data = $this->setupBulkCreate();
|
|
|
|
|
$this->assertNotEmpty($data['databaseId']);
|
|
|
|
|
$this->assertNotEmpty($data['tableId']);
|
|
|
|
|
$this->assertNotEmpty($data['projectId']);
|
2025-06-13 08:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
public function testBulkUpdate(): void
|
2025-06-13 08:34:23 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
$data = $this->setupBulkCreate();
|
|
|
|
|
|
2025-06-13 08:34:23 +00:00
|
|
|
$userId = $this->getUser()['$id'];
|
|
|
|
|
$permissions = [
|
|
|
|
|
Permission::read(Role::user($userId)),
|
|
|
|
|
Permission::update(Role::user($userId)),
|
|
|
|
|
Permission::delete(Role::user($userId)),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$headers = [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $data['projectId'],
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Step 1: Bulk update rows
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::UPDATE_ROWS);
|
2025-06-13 08:34:23 +00:00
|
|
|
$payload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
|
|
|
|
'data' => [
|
|
|
|
|
'name' => 'Rows Updated',
|
|
|
|
|
'$permissions' => $permissions,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
2026-02-05 23:01:31 +00:00
|
|
|
$this->assertGreaterThanOrEqual(1, count($res['body']['data']['tablesDBUpdateRows']['rows']));
|
2025-06-13 08:34:23 +00:00
|
|
|
|
|
|
|
|
// Step 2: Fetch and validate updated rows
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::GET_ROWS);
|
2025-06-13 08:34:23 +00:00
|
|
|
$payload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
|
|
|
|
'queries' => [Query::equal('name', ['Rows Updated'])->toString()],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertEquals(200, $res['headers']['status-code']);
|
|
|
|
|
|
2025-08-20 14:20:05 +00:00
|
|
|
$fetched = $res['body']['data']['tablesDBListRows'];
|
2026-02-05 23:01:31 +00:00
|
|
|
$this->assertGreaterThanOrEqual(1, $fetched['total']);
|
2025-06-13 08:34:23 +00:00
|
|
|
|
|
|
|
|
foreach ($fetched['rows'] as $row) {
|
|
|
|
|
$this->assertEquals($permissions, $row['_permissions']);
|
|
|
|
|
$this->assertEquals($data['tableId'], $row['_tableId']);
|
|
|
|
|
$this->assertEquals($data['databaseId'], $row['_databaseId']);
|
|
|
|
|
$this->assertEquals('Rows Updated', json_decode($row['data'], true)['name']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
public function testBulkUpsert(): void
|
2025-06-13 08:34:23 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
$data = $this->setupBulkCreate();
|
|
|
|
|
|
2025-06-13 08:34:23 +00:00
|
|
|
$userId = $this->getUser()['$id'];
|
|
|
|
|
$headers = [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $data['projectId'],
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$permissions = [
|
|
|
|
|
Permission::read(Role::user($userId)),
|
|
|
|
|
Permission::update(Role::user($userId)),
|
|
|
|
|
Permission::delete(Role::user($userId)),
|
|
|
|
|
];
|
|
|
|
|
|
2026-02-09 01:20:42 +00:00
|
|
|
// Step 1: Add two new rows via upsert
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::UPSERT_ROWS);
|
2025-06-13 08:34:23 +00:00
|
|
|
$upsertPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
|
|
|
|
'rows' => [
|
|
|
|
|
[
|
2026-02-09 01:20:42 +00:00
|
|
|
'$id' => ID::unique(),
|
2025-06-13 08:34:23 +00:00
|
|
|
'name' => 'Row #1000',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'name' => 'Row #11',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $upsertPayload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $response['body']);
|
|
|
|
|
|
2025-08-20 14:20:05 +00:00
|
|
|
$rows = $response['body']['data']['tablesDBUpsertRows']['rows'];
|
2025-06-13 08:34:23 +00:00
|
|
|
$this->assertCount(2, $rows);
|
|
|
|
|
|
|
|
|
|
$rowMap = [];
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
|
$decoded = json_decode($row['data'], true);
|
|
|
|
|
$rowMap[$decoded['name']] = $decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('Row #1000', $rowMap);
|
|
|
|
|
$this->assertArrayHasKey('Row #11', $rowMap);
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
// Step 2: Fetch all rows and confirm count
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::GET_ROWS);
|
2025-06-13 08:34:23 +00:00
|
|
|
$fetchPayload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $fetchPayload);
|
|
|
|
|
$this->assertEquals(200, $res['headers']['status-code']);
|
|
|
|
|
|
2025-08-20 14:20:05 +00:00
|
|
|
$fetched = $res['body']['data']['tablesDBListRows'];
|
2026-02-05 23:01:31 +00:00
|
|
|
$this->assertGreaterThanOrEqual(11, $fetched['total']);
|
2025-06-13 08:34:23 +00:00
|
|
|
|
|
|
|
|
// Step 3: Upsert row with new permissions using `tablesUpsertRow`
|
2026-02-09 01:20:42 +00:00
|
|
|
$upsertRowId = ID::unique();
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::UPSERT_ROW);
|
2025-06-13 08:34:23 +00:00
|
|
|
$payload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
2026-02-09 01:20:42 +00:00
|
|
|
'rowId' => $upsertRowId,
|
|
|
|
|
'data' => ['name' => 'Row Upserted'],
|
2025-06-13 08:34:23 +00:00
|
|
|
'permissions' => $permissions,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
|
|
|
|
|
2025-08-20 14:20:05 +00:00
|
|
|
$updated = $res['body']['data']['tablesDBUpsertRow'];
|
2026-02-09 01:20:42 +00:00
|
|
|
$this->assertEquals('Row Upserted', json_decode($updated['data'], true)['name']);
|
2025-06-13 08:34:23 +00:00
|
|
|
$this->assertEquals($data['databaseId'], $updated['_databaseId']);
|
|
|
|
|
$this->assertEquals($data['tableId'], $updated['_tableId']);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 23:01:31 +00:00
|
|
|
public function testBulkDelete(): void
|
2025-06-13 08:34:23 +00:00
|
|
|
{
|
2026-02-05 23:01:31 +00:00
|
|
|
$data = $this->setupBulkUpsert();
|
|
|
|
|
|
2025-06-13 08:34:23 +00:00
|
|
|
$headers = [
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $data['projectId'],
|
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Step 1: Perform bulk delete
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::DELETE_ROWS);
|
2025-06-13 08:34:23 +00:00
|
|
|
$payload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertArrayNotHasKey('errors', $res['body']);
|
|
|
|
|
|
2025-08-20 14:20:05 +00:00
|
|
|
$deleted = $res['body']['data']['tablesDBDeleteRows']['rows'];
|
2025-06-13 08:34:23 +00:00
|
|
|
$this->assertIsArray($deleted);
|
2026-02-05 23:01:31 +00:00
|
|
|
$this->assertGreaterThanOrEqual(1, count($deleted));
|
2025-06-13 08:34:23 +00:00
|
|
|
|
|
|
|
|
// Step 2: Confirm deletion via refetch
|
2025-08-19 11:03:18 +00:00
|
|
|
$query = $this->getQuery(self::GET_ROWS);
|
2025-06-13 08:34:23 +00:00
|
|
|
$payload = [
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => [
|
|
|
|
|
'databaseId' => $data['databaseId'],
|
|
|
|
|
'tableId' => $data['tableId'],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload);
|
|
|
|
|
$this->assertEquals(200, $res['headers']['status-code']);
|
2025-08-20 14:20:05 +00:00
|
|
|
$this->assertEquals(0, $res['body']['data']['tablesDBListRows']['total']);
|
2025-06-13 08:34:23 +00:00
|
|
|
}
|
2022-07-06 03:51:37 +00:00
|
|
|
}
|