From 52d4b649e4710a8cd94a9866742c35cce48e3f3f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 21 Feb 2024 13:09:14 +1300 Subject: [PATCH 1/3] Add missing unique index --- app/config/collections.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index a8965c011d..cdc5d03b8d 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2113,6 +2113,13 @@ $commonCollections = [ 'lengths' => [], 'orders' => [], ], + [ + '$id' => ID::custom('_unique_target_topic'), + 'type' => Database::INDEX_UNIQUE, + 'attributes' => ['targetInternalId', 'topicInternalId'], + 'lengths' => [], + 'orders' => [], + ], [ '$id' => ID::custom('_fulltext_search'), 'type' => Database::INDEX_FULLTEXT, From 81d475d98b69290138e0cd63b9dfc354bfc2ab47 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 21 Feb 2024 13:16:25 +1300 Subject: [PATCH 2/3] Add test --- tests/e2e/Services/Messaging/MessagingBase.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 956ac5f68a..b3d760e6cc 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -444,6 +444,17 @@ trait MessagingBase $this->assertEquals($target['body']['userId'], $response['body']['target']['userId']); $this->assertEquals($target['body']['providerType'], $response['body']['target']['providerType']); + // Test duplicate subscribers not allowed + $response = $this->client->call(Client::METHOD_POST, '/messaging/topics/' . $topics['public']['$id'] . '/subscribers', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'subscriberId' => ID::unique(), + 'targetId' => $target['body']['$id'], + ]); + + $this->assertEquals(409, $response['headers']['status-code']); + $topic = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $topics['public']['$id'], [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], From ca1d66fc7e60a26b2c3a7b288234db978e613161 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 21 Feb 2024 13:31:48 +1300 Subject: [PATCH 3/3] Fix test --- tests/e2e/Services/Messaging/MessagingBase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index b3d760e6cc..25bf985692 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -445,7 +445,7 @@ trait MessagingBase $this->assertEquals($target['body']['providerType'], $response['body']['target']['providerType']); // Test duplicate subscribers not allowed - $response = $this->client->call(Client::METHOD_POST, '/messaging/topics/' . $topics['public']['$id'] . '/subscribers', \array_merge([ + $failure = $this->client->call(Client::METHOD_POST, '/messaging/topics/' . $topics['public']['$id'] . '/subscribers', \array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -453,7 +453,7 @@ trait MessagingBase 'targetId' => $target['body']['$id'], ]); - $this->assertEquals(409, $response['headers']['status-code']); + $this->assertEquals(409, $failure['headers']['status-code']); $topic = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $topics['public']['$id'], [ 'content-type' => 'application/json',