From ee4aff0ca4e2a23681e52070d2c84d663c0fe7b0 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Tue, 5 Jul 2022 23:13:48 +0000 Subject: [PATCH] Fix get collection usage alias --- app/controllers/api/databases.php | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 59 ++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 5ce5dea75c..a18058af5e 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2669,7 +2669,7 @@ App::get('/v1/databases/:databaseId/usage') }); App::get('/v1/databases/:databaseId/collections/:collectionId/usage') - ->alias('/v1/database/collections/:collectionId/documents', ['databaseId' => 'default']) + ->alias('/v1/database/:collectionId/usage', ['databaseId' => 'default']) ->desc('Get usage stats for a collection') ->groups(['api', 'database']) ->label('scope', 'collections.read') diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 747d725e6c..35f2b78770 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -922,6 +922,63 @@ trait DatabasesBase return ['documents' => $documents['body']['documents'], 'databaseId' => $databaseId]; } + public function testCreateCollectionAlias(): array + { + // Create default database + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => 'default', + 'name' => 'Default' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $this->assertEquals(201, $database['headers']['status-code']); + + /** + * Test for SUCCESS + */ + + $movies = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => 'unique()', + 'name' => 'Movies', + 'read' => [], + 'write' => [], + 'permission' => 'document', + ]); + + $this->assertEquals($movies['headers']['status-code'], 201); + $this->assertEquals($movies['body']['name'], 'Movies'); + + return ['moviesId' => $movies['body']['$id']]; + } + + /** + * @depends testCreateCollectionAlias + */ + public function testListDocumentsAlias(array $data): array + { + /** + * Test for SUCCESS + */ + + $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals($documents['headers']['status-code'], 200); + $this->assertEquals($documents['body']['total'], 0); + + return []; + } + /** * @depends testListDocuments */ @@ -2376,7 +2433,7 @@ trait DatabasesBase $document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $moviesId . '/documents/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ + ], $this->getHeaders()), [ 'read' => ['user:' . $this->getUser()['$id']], ]);