From 69c37a72be436ac8324acbc0b941f4b79be13d23 Mon Sep 17 00:00:00 2001 From: wess Date: Fri, 4 Nov 2022 10:23:08 -0400 Subject: [PATCH] Comment out HTTPTest cause torsten told me to Updates some tests with sleep to ensure workers have created things, like attributes Updated init.php to use new mongo driver/mongo adapter setup --- app/controllers/api/databases.php | 5 +- app/init.php | 2 +- composer.json | 2 +- composer.lock | 70 +++++++++---------- tests/e2e/General/HTTPTest.php | 62 ++++++++-------- .../Databases/DatabasesCustomClientTest.php | 15 ++-- 6 files changed, 83 insertions(+), 73 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 19264454e0..10c584a2c3 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1884,6 +1884,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $collection = Authorization::skip(fn() => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); + if ($collection->isEmpty() || !$collection->getAttribute('enabled')) { if (!($mode === APP_MODE_ADMIN && Auth::isPrivilegedUser(Authorization::getRoles()))) { throw new Exception(Exception::COLLECTION_NOT_FOUND); @@ -1939,8 +1940,10 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') $data['$id'] = $documentId == 'unique()' ? ID::unique() : $documentId; $data['$permissions'] = $permissions; + $newDocument = new Document($data); + try { - $document = $dbForProject->createDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), new Document($data)); + $document = $dbForProject->createDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $newDocument); $document->setAttribute('$collectionId', $collectionId); $document->setAttribute('$databaseId', $databaseId); } catch (StructureException $exception) { diff --git a/app/init.php b/app/init.php index 2c9702ca59..24db401214 100644 --- a/app/init.php +++ b/app/init.php @@ -601,7 +601,7 @@ $register->set('db', function () { $dbPass = App::getEnv('_APP_DB_PASS', ''); $dbScheme = App::getEnv('_APP_DB_SCHEMA', ''); - $client = new Client($dbScheme, $dbHost, (int) $dbPort, $dbUser, $dbPass, true); + $client = new Client($dbScheme, $dbHost, (int) $dbPort, $dbUser, $dbPass, false); return $client; }); diff --git a/composer.json b/composer.json index 8b0a470334..753fd3e128 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "utopia-php/cache": "0.6.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-fix-mongo-appwrite as 0.26.999999", + "utopia-php/database": "dev-fix-mongo-appwrite as 0.26.2", "utopia-php/locale": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", diff --git a/composer.lock b/composer.lock index dcbf10f252..ad0001d821 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "94abe11dd4177346e2c480ca252690b8", + "content-hash": "c7871be5d12277fd22cc251835f1ea37", "packages": [ { "name": "adhocore/jwt", @@ -1671,12 +1671,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace" + "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/cfa0ae98841b9e461207c13ab093d76b0fa7bace", - "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", + "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", "shasum": "" }, "require": { @@ -1686,7 +1686,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -1731,7 +1731,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-php80/tree/main" }, "funding": [ { @@ -1747,7 +1747,7 @@ "type": "tidelift" } ], - "time": "2022-05-10T07:21:04+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "utopia-php/abuse", @@ -2068,26 +2068,26 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "f1cafa7015fbbc1bb62cab6adbb26d49ae692b1c" + "reference": "6833774180988cc3e48b148b031144b3d5c4bb25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/f1cafa7015fbbc1bb62cab6adbb26d49ae692b1c", - "reference": "f1cafa7015fbbc1bb62cab6adbb26d49ae692b1c", + "url": "https://api.github.com/repos/utopia-php/database/zipball/6833774180988cc3e48b148b031144b3d5c4bb25", + "reference": "6833774180988cc3e48b148b031144b3d5c4bb25", "shasum": "" }, "require": { - "ext-pdo": "*", - "ext-redis": "*", - "mongodb/mongodb": "1.8.0", "php": ">=8.0", "utopia-php/cache": "0.6.*", "utopia-php/framework": "0.*.*", "utopia-php/mongo": "dev-release" }, "require-dev": { + "ext-mongodb": "*", + "ext-pdo": "*", + "ext-redis": "*", "fakerphp/faker": "^1.14", - "laravel/pint": "1.2.*", + "mongodb/mongodb": "1.8.0", "phpunit/phpunit": "^9.4", "swoole/ide-helper": "4.8.0", "utopia-php/cli": "^0.11.0", @@ -2115,7 +2115,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/fix-mongo-appwrite" }, - "time": "2022-11-02T18:24:07+00:00" + "time": "2022-11-03T17:45:28+00:00" }, { "name": "utopia-php/domains", @@ -2395,7 +2395,7 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/mongo.git", - "reference": "e2704f0a58f33cd845eb8aefd1cabc104525e313" + "reference": "06647ce7fc014803581c591efec7c9c1c3af904f" }, "require": { "ext-mongodb": "*", @@ -2455,7 +2455,7 @@ "upf", "utopia" ], - "time": "2022-11-02T17:29:09+00:00" + "time": "2022-11-03T22:53:37+00:00" }, { "name": "utopia-php/orchestration", @@ -3626,12 +3626,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "a358c9d818d521da01361c5ada06ff8031288aaa" + "reference": "019a384e54a12d8bfca736f88c2f4478b432e71d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/a358c9d818d521da01361c5ada06ff8031288aaa", - "reference": "a358c9d818d521da01361c5ada06ff8031288aaa", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/019a384e54a12d8bfca736f88c2f4478b432e71d", + "reference": "019a384e54a12d8bfca736f88c2f4478b432e71d", "shasum": "" }, "require": { @@ -3695,7 +3695,7 @@ "type": "github" } ], - "time": "2022-11-01T06:33:37+00:00" + "time": "2022-11-03T07:46:09+00:00" }, { "name": "phpunit/php-file-iterator", @@ -5111,12 +5111,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4" + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", - "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", "shasum": "" }, "require": { @@ -5132,7 +5132,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -5170,7 +5170,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/main" }, "funding": [ { @@ -5186,7 +5186,7 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -5194,12 +5194,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e" + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e", - "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", "shasum": "" }, "require": { @@ -5215,7 +5215,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.26-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -5254,7 +5254,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.26.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/main" }, "funding": [ { @@ -5270,7 +5270,7 @@ "type": "tidelift" } ], - "time": "2022-05-24T11:49:31+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "textalk/websocket", @@ -5453,8 +5453,8 @@ { "package": "utopia-php/database", "version": "dev-fix-mongo-appwrite", - "alias": "0.26.999999", - "alias_normalized": "0.26.999999.0" + "alias": "0.26.2", + "alias_normalized": "0.26.2.0" } ], "minimum-stability": "dev", diff --git a/tests/e2e/General/HTTPTest.php b/tests/e2e/General/HTTPTest.php index 06ceada976..18fb009bea 100644 --- a/tests/e2e/General/HTTPTest.php +++ b/tests/e2e/General/HTTPTest.php @@ -152,43 +152,43 @@ class HTTPTest extends Scope // unlink(realpath(__DIR__ . '/../../resources/swagger2.json')); // } - public function testSpecOpenAPI3() - { - $response = $this->client->call(Client::METHOD_GET, '/specs/open-api3?platform=console', [ - 'content-type' => 'application/json', - ], []); + // public function testSpecOpenAPI3() + // { + // $response = $this->client->call(Client::METHOD_GET, '/specs/open-api3?platform=console', [ + // 'content-type' => 'application/json', + // ], []); - $directory = __DIR__ . '/../../../app/config/specs/'; + // $directory = __DIR__ . '/../../../app/config/specs/'; - $files = scandir($directory); - $client = new Client(); - $client->setEndpoint('https://validator.swagger.io'); + // $files = scandir($directory); + // $client = new Client(); + // $client->setEndpoint('https://validator.swagger.io'); - foreach ($files as $file) { - if (in_array($file, ['.', '..'])) { - continue; - } + // foreach ($files as $file) { + // if (in_array($file, ['.', '..'])) { + // continue; + // } - if ( - (strpos($file, 'latest') === false) && - (strpos($file, '0.12.x') === false) && - (strpos($file, '0.13.x') === false) - ) { - continue; - } + // if ( + // (strpos($file, 'latest') === false) && + // (strpos($file, '0.12.x') === false) && + // (strpos($file, '0.13.x') === false) + // ) { + // continue; + // } - /** - * Test for SUCCESS - */ - $response = $client->call(Client::METHOD_POST, '/validator/debug', [ - 'content-type' => 'application/json', - ], json_decode(file_get_contents($directory . $file), true)); + // /** + // * Test for SUCCESS + // */ + // $response = $client->call(Client::METHOD_POST, '/validator/debug', [ + // 'content-type' => 'application/json', + // ], json_decode(file_get_contents($directory . $file), true)); - $response['body'] = json_decode($response['body'], true); - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertTrue(empty($response['body'])); - } - } + // $response['body'] = json_decode($response['body'], true); + // $this->assertEquals(200, $response['headers']['status-code']); + // $this->assertTrue(empty($response['body'])); + // } + // } public function testVersions() { diff --git a/tests/e2e/Services/Databases/DatabasesCustomClientTest.php b/tests/e2e/Services/Databases/DatabasesCustomClientTest.php index 21cddcf55d..bacddd1481 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomClientTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomClientTest.php @@ -31,6 +31,8 @@ class DatabasesCustomClientTest extends Scope 'name' => 'Test Database' ]); + sleep(1); + $databaseId = $database['body']['$id']; // Collection aliases write to create, update, delete @@ -40,13 +42,14 @@ class DatabasesCustomClientTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'collectionId' => ID::unique(), - 'name' => 'Movies', + 'name' => 'movies', 'documentSecurity' => true, 'permissions' => [ Permission::write(Role::user($this->getUser()['$id'])), ], ]); + $moviesId = $movies['body']['$id']; $this->assertContains(Permission::create(Role::user($this->getUser()['$id'])), $movies['body']['$permissions']); @@ -78,10 +81,12 @@ class DatabasesCustomClientTest extends Scope Permission::write(Role::user($this->getUser()['$id'])), ] ]); + + sleep(1); - var_dump("\n###############################\n"); - var_dump($document1); - var_dump("\n###############################\n"); + // var_dump("\n###################\n"); + // var_dump($document1['body']); + // var_dump("\n###################\n"); $this->assertNotContains(Permission::create(Role::user($this->getUser()['$id'])), $document1['body']['$permissions']); $this->assertContains(Permission::update(Role::user($this->getUser()['$id'])), $document1['body']['$permissions']); @@ -105,6 +110,8 @@ class DatabasesCustomClientTest extends Scope ] ]); + sleep(1); + $this->assertEquals(400, $document2['headers']['status-code']); }