1
0
Fork 0
mirror of synced 2024-07-02 13:10:38 +12:00

Update the content in the subscriber's search attribute

This commit is contained in:
Steven Nguyen 2024-01-18 02:32:32 +00:00
parent 5827c52372
commit 96de1617ed
No known key found for this signature in database
GPG key ID: 22EB8611C67E9E5C
2 changed files with 50 additions and 7 deletions

View file

@ -1991,20 +1991,27 @@ App::post('/v1/messaging/topics/:topicId/subscribers')
$user = Authorization::skip(fn () => $dbForProject->getDocument('users', $target->getAttribute('userId')));
$userId = $user->getId();
$subscriber = new Document([
'$id' => $subscriberId,
'$permissions' => [
Permission::read(Role::user($user->getId())),
Permission::delete(Role::user($user->getId())),
Permission::read(Role::user($userId)),
Permission::delete(Role::user($userId)),
],
'topicId' => $topicId,
'topicInternalId' => $topic->getInternalId(),
'targetId' => $targetId,
'targetInternalId' => $target->getInternalId(),
'userId' => $user->getId(),
'userId' => $userId,
'userInternalId' => $user->getInternalId(),
'providerType' => $target->getAttribute('providerType'),
'search' => "{$target->getAttribute('providerType')} "
'search' => implode(' ', [
$subscriberId,
$targetId,
$userId,
$target->getAttribute('providerType'),
]),
]);
try {

View file

@ -419,6 +419,12 @@ trait MessagingBase
*/
public function testListSubscribers(array $data)
{
$subscriberId = $data['subscriberId'];
$targetId = $data['targetId'];
$userId = $data['userId'];
$providerType = $data['providerType'];
$identifier = $data['identifier'];
$response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $data['topicId'] . '/subscribers', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@ -427,11 +433,41 @@ trait MessagingBase
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(1, $response['body']['total']);
$this->assertEquals($data['userId'], $response['body']['subscribers'][0]['target']['userId']);
$this->assertEquals($data['providerType'], $response['body']['subscribers'][0]['target']['providerType']);
$this->assertEquals($data['identifier'], $response['body']['subscribers'][0]['target']['identifier']);
$this->assertEquals($userId, $response['body']['subscribers'][0]['target']['userId']);
$this->assertEquals($providerType, $response['body']['subscribers'][0]['target']['providerType']);
$this->assertEquals($identifier, $response['body']['subscribers'][0]['target']['identifier']);
$this->assertEquals(\count($response['body']['subscribers']), $response['body']['total']);
$response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $data['topicId'] . '/subscribers', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]), [
'search' => 'DOES_NOT_EXIST',
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(0, $response['body']['total']);
$searches = [
$subscriberId,
$targetId,
$userId,
$providerType
];
foreach ($searches as $search) {
$response = $this->client->call(Client::METHOD_GET, '/messaging/topics/' . $data['topicId'] . '/subscribers', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]), [
'search' => $search,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(1, $response['body']['total']);
}
return $data;
}