From b43b52f85b3591aae8d0ea5142b61e79a7a2610e Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 16 Feb 2022 17:26:05 +0100 Subject: [PATCH] fix: add team membership search --- app/config/collections.php | 18 +++++++++ tests/e2e/Services/Teams/TeamsBaseClient.php | 42 ++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index 4f222c71d2..ea79cf3e9f 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1532,6 +1532,17 @@ $collections = [ 'array' => false, 'filters' => ['encrypt'], ], + [ + '$id' => 'search', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16384, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], ], 'indexes' => [ [ @@ -1555,6 +1566,13 @@ $collections = [ 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => '_key_search', + 'type' => Database::INDEX_FULLTEXT, + 'attributes' => ['search'], + 'lengths' => [], + 'orders' => [], + ], ], ], diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index e03ce89a9c..f7d059d03c 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -28,6 +28,48 @@ trait TeamsBaseClient $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); + $membershipId = $response['body']['memberships'][0]['$id']; + + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'search' => $this->getUser()['$id'] + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['sum']); + $this->assertNotEmpty($response['body']['memberships'][0]); + $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); + $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); + $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); + + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'search' => $membershipId + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['sum']); + $this->assertNotEmpty($response['body']['memberships'][0]); + $this->assertEquals($this->getUser()['name'], $response['body']['memberships'][0]['name']); + $this->assertEquals($this->getUser()['email'], $response['body']['memberships'][0]['email']); + $this->assertEquals('owner', $response['body']['memberships'][0]['roles'][0]); + + $response = $this->client->call(Client::METHOD_GET, '/teams/'.$teamUid.'/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'search' => 'unknown' + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertIsInt($response['body']['sum']); + $this->assertEmpty($response['body']['memberships']); + $this->assertEquals(0, $response['body']['sum']); + /** * Test for FAILURE */