mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
added permission upsert test
This commit is contained in:
@@ -1693,6 +1693,107 @@ class RealtimeCustomClientTest extends Scope
|
||||
$this->assertIsArray($response2['data']['payload']['$permissions']);
|
||||
}
|
||||
|
||||
// bulk upsert
|
||||
$this->client->call(Client::METHOD_PUT, "/databases/{$databaseId}/collections/{$actorsId}/documents", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'documents' => [
|
||||
[
|
||||
'$id' => ID::unique(),
|
||||
'name' => 'Robert Downey Jr.',
|
||||
'$permissions' => [
|
||||
Permission::read(Role::user($user1Id)),
|
||||
],
|
||||
],
|
||||
[
|
||||
'$id' => ID::unique(),
|
||||
'name' => 'Thor',
|
||||
'$permissions' => [
|
||||
Permission::read(Role::user($user2Id)),
|
||||
],
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$response = json_decode($client1->receive(), true);
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(6, $response['data']['channels']);
|
||||
|
||||
$this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.{$response['data']['payload']['$id']}.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.*.documents.*.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.{$actorsId}.documents.*.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.*", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.*.documents.*", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.*.documents.*", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.{$actorsId}.documents.*", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.{$actorsId}", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.*", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.*", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.{$actorsId}", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.*", $response['data']['events']);
|
||||
|
||||
$this->assertNotEmpty($response['data']['payload']);
|
||||
$this->assertIsArray($response['data']['payload']);
|
||||
$this->assertArrayHasKey('$id', $response['data']['payload']);
|
||||
$this->assertArrayHasKey('name', $response['data']['payload']);
|
||||
$this->assertArrayHasKey('$permissions', $response['data']['payload']);
|
||||
$this->assertIsArray($response['data']['payload']['$permissions']);
|
||||
|
||||
// client1 shouldnot receive more than 1 event
|
||||
try {
|
||||
json_decode(json_decode($client1->receive(), true));
|
||||
$this->fail('Expected TimeoutException was not thrown.');
|
||||
} catch (Exception $e) {
|
||||
$this->assertInstanceOf(TimeoutException::class, $e);
|
||||
}
|
||||
|
||||
$response = json_decode($client2->receive(), true);
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('event', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertArrayHasKey('timestamp', $response['data']);
|
||||
$this->assertCount(6, $response['data']['channels']);
|
||||
|
||||
$this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.{$response['data']['payload']['$id']}.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.*.documents.*.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.{$actorsId}.documents.*.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.{$actorsId}.documents.*", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.*.documents.*", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.*.documents.*", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.{$actorsId}.documents.*", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.{$actorsId}", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.*", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.*", $response['data']['events']);
|
||||
$this->assertContains("databases.*.collections.{$actorsId}", $response['data']['events']);
|
||||
$this->assertContains("databases.{$databaseId}.collections.*.documents.*.upsert", $response['data']['events']);
|
||||
$this->assertContains("databases.*", $response['data']['events']);
|
||||
|
||||
$this->assertNotEmpty($response['data']['payload']);
|
||||
$this->assertIsArray($response['data']['payload']);
|
||||
$this->assertArrayHasKey('$id', $response['data']['payload']);
|
||||
$this->assertArrayHasKey('name', $response['data']['payload']);
|
||||
$this->assertArrayHasKey('$permissions', $response['data']['payload']);
|
||||
$this->assertIsArray($response['data']['payload']['$permissions']);
|
||||
|
||||
// client2 shouldnot receive more than 1 event
|
||||
try {
|
||||
json_decode(json_decode($client2->receive(), true));
|
||||
$this->fail('Expected TimeoutException was not thrown.');
|
||||
} catch (Exception $e) {
|
||||
$this->assertInstanceOf(TimeoutException::class, $e);
|
||||
}
|
||||
|
||||
|
||||
$client1->close();
|
||||
$client2->close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user