From 1291c8c8ecf3e0b0de6b7f3c2398ab39ac154697 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 13 Dec 2021 14:23:12 +0100 Subject: [PATCH] tests(database): add enable/disable tests --- tests/e2e/Services/Database/DatabaseBase.php | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/e2e/Services/Database/DatabaseBase.php b/tests/e2e/Services/Database/DatabaseBase.php index 2f852d0f5e..df87fa702b 100644 --- a/tests/e2e/Services/Database/DatabaseBase.php +++ b/tests/e2e/Services/Database/DatabaseBase.php @@ -30,6 +30,70 @@ trait DatabaseBase return ['moviesId' => $movies['body']['$id']]; } + /** + * @depends testCreateCollection + */ + public function testDisableCollection(array $data): void + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_PUT, '/database/collections/' . $data['moviesId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'name' => 'Movies', + 'enabled' => false, + 'permission' => 'document', + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertFalse($response['body']['enabled']); + + if ($this->getSide() === 'client') { + $responseCreateDocument = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => 'unique()', + 'data' => [ + 'title' => 'Captain America', + ], + 'read' => ['user:'.$this->getUser()['$id']], + 'write' => ['user:'.$this->getUser()['$id']], + ]); + + $responseListDocument = $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())); + + $responseGetDocument = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents/someID', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals($responseCreateDocument['headers']['status-code'], 404); + $this->assertEquals($responseListDocument['headers']['status-code'], 404); + $this->assertEquals($responseGetDocument['headers']['status-code'], 404); + } + + $response = $this->client->call(Client::METHOD_PUT, '/database/collections/' . $data['moviesId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'name' => 'Movies', + 'enabled' => true, + 'permission' => 'document', + ]); + + $this->assertEquals($response['headers']['status-code'], 200); + $this->assertTrue($response['body']['enabled']); + } + + /** * @depends testCreateCollection */