1
0
Fork 0
mirror of synced 2024-07-05 14:40:42 +12:00

fix(messaging): disable validation for subquery to prevent error

If there are more than 100 targets, the validation throws an error. This
change skips the validation so no error is thrown.
This commit is contained in:
Steven Nguyen 2024-06-20 22:34:08 +00:00 committed by GitHub
parent c6489d172f
commit 3a3a0594dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 2 deletions

View file

@ -607,9 +607,9 @@ Database::addFilter(
])
));
if (\count($targetIds) > 0) {
return $database->find('targets', [
return $database->skipValidation(fn () => $database->find('targets', [
Query::equal('$internalId', $targetIds)
]);
]));
}
return [];
}

View file

@ -511,6 +511,55 @@ trait MessagingBase
];
}
public function testSubscriberTargetSubQuery()
{
$response = $this->client->call(Client::METHOD_POST, '/messaging/topics', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'topicId' => 'sub-query-test',
'name' => 'sub-query-test',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$topic = $response['body'];
$prefix = uniqid();
for ($i = 1; $i <= 101; $i++) {
$response = $this->client->call(Client::METHOD_POST, '/users', [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], [
'userId' => "$prefix-$i",
'email' => "$prefix-$i@example.com",
'password' => 'password',
'name' => "User $prefix $i",
]);
$this->assertEquals(201, $response['headers']['status-code']);
$user = $response['body'];
$targets = $user['targets'] ?? [];
$this->assertGreaterThan(0, count($targets));
$target = $targets[0];
$response = $this->client->call(Client::METHOD_POST, '/messaging/topics/' . $topic['$id'] . '/subscribers', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'subscriberId' => $user['$id'],
'targetId' => $target['$id'],
]);
$this->assertEquals(201, $response['headers']['status-code']);
}
}
/**
* @depends testCreateSubscriber
*/