From f7be5cd7b1a5b30111590cfde532766ccbe3cea7 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 9 Aug 2021 16:54:10 +0200 Subject: [PATCH] tests(database): after pagination tests --- tests/e2e/Services/Database/DatabaseBase.php | 10 +-- .../Database/DatabaseCustomServerTest.php | 80 +++++++++++++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/tests/e2e/Services/Database/DatabaseBase.php b/tests/e2e/Services/Database/DatabaseBase.php index aa246706f1..6ea9a885e0 100644 --- a/tests/e2e/Services/Database/DatabaseBase.php +++ b/tests/e2e/Services/Database/DatabaseBase.php @@ -316,7 +316,7 @@ trait DatabaseBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'orderAfter' => $base['body']['documents'][0]['$id'] + 'after' => $base['body']['documents'][0]['$id'] ]); $this->assertEquals($base['body']['documents'][1]['$id'], $documents['body']['documents'][0]['$id']); @@ -327,7 +327,7 @@ trait DatabaseBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'orderAfter' => $base['body']['documents'][2]['$id'] + 'after' => $base['body']['documents'][2]['$id'] ]); $this->assertEmpty($documents['body']['documents']); @@ -354,7 +354,7 @@ trait DatabaseBase ], $this->getHeaders()), [ 'orderAttributes' => ['releaseYear'], 'orderTypes' => ['ASC'], - 'orderAfter' => $base['body']['documents'][1]['$id'] + 'after' => $base['body']['documents'][1]['$id'] ]); $this->assertEquals($base['body']['documents'][2]['$id'], $documents['body']['documents'][0]['$id']); @@ -382,7 +382,7 @@ trait DatabaseBase ], $this->getHeaders()), [ 'orderAttributes' => ['releaseYear'], 'orderTypes' => ['DESC'], - 'orderAfter' => $base['body']['documents'][1]['$id'] + 'after' => $base['body']['documents'][1]['$id'] ]); $this->assertEquals($base['body']['documents'][2]['$id'], $documents['body']['documents'][0]['$id']); @@ -395,7 +395,7 @@ trait DatabaseBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'orderAfter' => 'unknown' + 'after' => 'unknown' ]); $this->assertEquals($documents['headers']['status-code'], 400); diff --git a/tests/e2e/Services/Database/DatabaseCustomServerTest.php b/tests/e2e/Services/Database/DatabaseCustomServerTest.php index dea3b588c7..68cc4ee44e 100644 --- a/tests/e2e/Services/Database/DatabaseCustomServerTest.php +++ b/tests/e2e/Services/Database/DatabaseCustomServerTest.php @@ -13,6 +13,86 @@ class DatabaseCustomServerTest extends Scope use ProjectCustom; use SideServer; + 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'], + ]); + + $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'], + ]); + + $collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(2, $collections['body']['sum']); + $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' + ]); + + $this->assertEquals(2, $collections['body']['sum']); + $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()), [ + 'after' => $base['body']['collections'][0]['$id'] + ]); + + $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()), [ + 'after' => $base['body']['collections'][1]['$id'] + ]); + + $this->assertCount(0, $collections['body']['collections']); + $this->assertEmpty($collections['body']['collections']); + } + public function testDeleteCollection() { /**