From 7b60a36eead964d880eda4283f79534b22a3e7ab Mon Sep 17 00:00:00 2001 From: gepd Date: Mon, 20 Jun 2022 13:49:34 -0400 Subject: [PATCH] added test to update permissions with empty payload --- tests/e2e/Services/Database/DatabaseBase.php | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/e2e/Services/Database/DatabaseBase.php b/tests/e2e/Services/Database/DatabaseBase.php index f59e5ad56..0ea07f70b 100644 --- a/tests/e2e/Services/Database/DatabaseBase.php +++ b/tests/e2e/Services/Database/DatabaseBase.php @@ -2160,6 +2160,66 @@ trait DatabaseBase $this->assertEquals(409, $duplicate['headers']['status-code']); + return $data; + } + + /** + * @depends testCreateIndexes + */ + public function testUpdatePermissionsWithEmptyPayload(array $data): array + { + $document1 = $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', + 'releaseYear' => 1944, + 'actors' => [ + 'Chris Evans', + 'Samuel Jackson', + ] + ], + 'read' => ['user:' . $this->getUser()['$id']], + 'write' => ['user:' . $this->getUser()['$id']], + ]); + + $id = $document['body']['$id']; + + $document2 = $this->client->call(Client::METHOD_PATCH, '/database/collections/' . $data['moviesId'] . '/documents/'.$id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'read' => [], + 'write' => [], + ]); + + $this->assertEquals($document1['headers']['status-code'], 201); + $this->assertEquals($document1['body']['title'], 'Captain America'); + $this->assertEquals($document1['body']['releaseYear'], 1944); + $this->assertIsArray($document1['body']['$read']); + $this->assertIsArray($document1['body']['$write']); + $this->assertCount(1, $document1['body']['$read']); + $this->assertCount(1, $document1['body']['$write']); + $this->assertCount(2, $document1['body']['actors']); + $this->assertEquals($document1['body']['actors'][0], 'Chris Evans'); + $this->assertEquals($document1['body']['actors'][1], 'Samuel Jackson'); + + if ($this->getSide() == 'client') { + $this->assertEquals($document2['headers']['status-code'], 401); + } + + if ($this->getSide() == 'server') { + $this->assertEquals($document2['headers']['status-code'], 200); + $this->assertEquals($document2['body']['title'], 'Captain America'); + $this->assertEquals($document2['body']['releaseYear'], 1944); + $this->assertCount(0, $document2['body']['$read']); + $this->assertCount(0, $document2['body']['$write']); + $this->assertEquals([], $document2['body']['$read']); + $this->assertEquals([], $document2['body']['$write']); + } + return $data; } }