From 276b1de2b018d4ea9cb4e512ddfc556ac796f40c Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 26 Mar 2023 16:27:07 +0300 Subject: [PATCH 1/2] Disable 2 way for ManyToOne relation test --- .../e2e/Services/Databases/DatabasesBase.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index eb26bc883a..7b3a2fb892 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -3468,7 +3468,6 @@ trait DatabasesBase 'key' => 'artist', 'twoWayKey' => 'albums', ]); - $this->assertEquals(202, $response['headers']['status-code']); $this->assertEquals('artist', $response['body']['key']); $this->assertEquals('relationship', $response['body']['type']); @@ -3535,6 +3534,27 @@ trait DatabasesBase $this->assertEquals('Album 1', $artist['body']['albums'][0]['name']); $this->assertEquals($permissions, $artist['body']['albums'][0]['$permissions']); + // Update disable 2 way + $relation = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $albums['body']['$id'] . '/attributes/artist/relationship', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'twoWay' => false, + ]); + + + $this->assertEquals(202, $response['headers']['status-code']); + $artist = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $artists['body']['$id'] . '/documents/' . $album['body']['artist']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $artist['headers']['status-code']); + $this->assertEquals('Artist 1', $artist['body']['name']); + $this->assertEquals($permissions, $artist['body']['$permissions']); + $this->assertArrayNotHasKey("albums", $artist['body']); + return [ 'databaseId' => $databaseId, 'albumsCollection' => $albums['body']['$id'], From 0ef6f32a1052a28499ac904e6c0d3ae7ac0a617c Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 26 Mar 2023 19:39:26 +0300 Subject: [PATCH 2/2] Extract $options on get attributes list --- app/controllers/api/databases.php | 7 +++++++ tests/e2e/Services/Databases/DatabasesBase.php | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 0ceebe5c78..993abc0dc9 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1604,6 +1604,13 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') $attributes = $collection->getAttribute('attributes'); + foreach ($attributes as &$attribute) { + $options = $attribute->getAttribute('options', []); + foreach ($options as $key => $option) { + $attribute->setAttribute($key, $option); + } + } + $response->dynamic(new Document([ 'total' => \count($attributes), 'attributes' => $attributes diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 7b3a2fb892..c439628460 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -3171,6 +3171,21 @@ trait DatabasesBase $this->assertEquals('relationship', $relation['body']['type']); $this->assertEquals('processing', $relation['body']['status']); + $attributes = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/attributes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + + $this->assertEquals(200, $attributes['headers']['status-code']); + $this->assertEquals(2, $attributes['body']['total']); + $attributes = $attributes['body']['attributes']; + $this->assertEquals('library', $attributes[1]['relatedCollection']); + $this->assertEquals('oneToOne', $attributes[1]['relationType']); + $this->assertEquals(false, $attributes[1]['twoWay']); + $this->assertEquals('person', $attributes[1]['twoWayKey']); + $this->assertEquals(Database::RELATION_MUTATE_CASCADE, $attributes[1]['onDelete']); + $attribute = $this->client->call(Client::METHOD_GET, "/databases/{$databaseId}/collections/{$person['body']['$id']}/attributes/library", array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'],