1
0
Fork 0
mirror of synced 2024-06-26 10:10:57 +12:00

update tests

This commit is contained in:
Torsten Dittmann 2021-08-27 10:20:44 +02:00
parent 45cb05bb31
commit 67ae70ed69
3 changed files with 324 additions and 161 deletions

View file

@ -305,7 +305,10 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
$server->send(
$receivers,
json_encode($event['data'])
json_encode([
'type' => 'event',
'data' => $event['data']
])
);
if (($num = count($receivers)) > 0) {
@ -421,8 +424,11 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server,
$stats->incr($project->getId(), 'connectionsTotal');
} catch (\Throwable $th) {
$response = [
'code' => $th->getCode(),
'message' => $th->getMessage()
'type' => 'error',
'data' => [
'code' => $th->getCode(),
'message' => $th->getMessage()
]
];
$server->send([$connection], json_encode($response));
@ -504,6 +510,14 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re
$channels = Realtime::convertChannels(array_flip($realtime->connections[$connection]['channels']), $user->getId());
$realtime->subscribe($realtime->connections[$connection]['projectId'], $connection, $roles, $channels);
$server->send([$connection], json_encode([
'type' => 'response',
'data' => [
'to' => 'authentication',
'success' => true
]
]));
break;
default:
@ -512,8 +526,11 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re
}
} catch (\Throwable $th) {
$response = [
'code' => $th->getCode(),
'message' => $th->getMessage()
'type' => 'error',
'data' => [
'code' => $th->getCode(),
'message' => $th->getMessage()
]
];
$server->send([$connection], json_encode($response));

View file

@ -42,15 +42,23 @@ trait RealtimeBase
*/
$client = $this->getWebsocket(['documents'], ['origin' => 'http://appwrite.unknown']);
$payload = json_decode($client->receive(), true);
$this->assertEquals(1008, $payload['code']);
$this->assertEquals('Invalid Origin. Register your new client (appwrite.unknown) as a new Web platform on your project console dashboard', $payload['message']);
$this->assertArrayHasKey('type', $payload);
$this->assertArrayHasKey('data', $payload);
$this->assertEquals('error', $payload['type']);
$this->assertEquals(1008, $payload['data']['code']);
$this->assertEquals('Invalid Origin. Register your new client (appwrite.unknown) as a new Web platform on your project console dashboard', $payload['data']['message']);
$this->expectException(ConnectionException::class); // Check if server disconnnected client
$client->close();
$client = $this->getWebsocket();
$payload = json_decode($client->receive(), true);
$this->assertEquals(1008, $payload['code']);
$this->assertEquals('Missing channels', $payload['message']);
$this->assertArrayHasKey('type', $payload);
$this->assertArrayHasKey('data', $payload);
$this->assertEquals('error', $payload['type']);
$this->assertEquals(1008, $payload['data']['code']);
$this->assertEquals('Missing channels', $payload['data']['message']);
$this->expectException(ConnectionException::class); // Check if server disconnnected client
$client->close();
@ -60,8 +68,12 @@ trait RealtimeBase
]
]);
$payload = json_decode($client->receive(), true);
$this->assertEquals(1008, $payload['code']);
$this->assertEquals('Missing or unknown project ID', $payload['message']);
$this->assertArrayHasKey('type', $payload);
$this->assertArrayHasKey('data', $payload);
$this->assertEquals('error', $payload['type']);
$this->assertEquals(1008, $payload['data']['code']);
$this->assertEquals('Missing or unknown project ID', $payload['data']['message']);
$this->expectException(ConnectionException::class); // Check if server disconnnected client
$client->close();
@ -71,8 +83,12 @@ trait RealtimeBase
]
]);
$payload = json_decode($client->receive(), true);
$this->assertEquals(1008, $payload['code']);
$this->assertEquals('Missing or unknown project ID', $payload['message']);
$this->assertArrayHasKey('type', $payload);
$this->assertArrayHasKey('data', $payload);
$this->assertEquals('error', $payload['type']);
$this->assertEquals(1008, $payload['data']['code']);
$this->assertEquals('Missing or unknown project ID', $payload['data']['message']);
$this->expectException(ConnectionException::class); // Check if server disconnnected client
$client->close();
}
@ -95,14 +111,16 @@ trait RealtimeBase
$client = $this->getWebsocket(['account'], $headers);
$response = json_decode($client->receive(), true);
$this->assertCount(1, $response);
$this->assertCount(2, $response);
$this->assertArrayHasKey('account', $response);
$this->assertArrayHasKey('account.' . $userId, $response);
$client->close();
$client = $this->getWebsocket(['account', 'documents', 'account.123'], $headers);
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response);
$this->assertCount(3, $response);
$this->assertArrayHasKey('documents', $response);
$this->assertArrayHasKey('account', $response);
$this->assertArrayHasKey('account.' . $userId, $response);
$client->close();
@ -119,9 +137,11 @@ trait RealtimeBase
'documents.1',
'documents.2',
], $headers);
$response = json_decode($client->receive(), true);
$this->assertCount(11, $response);
$this->assertCount(12, $response);
$this->assertArrayHasKey('account', $response);
$this->assertArrayHasKey('account.' . $userId, $response);
$this->assertArrayHasKey('files', $response);
$this->assertArrayHasKey('files.1', $response);
@ -136,6 +156,40 @@ trait RealtimeBase
$client->close();
}
public function testAuthenticateMessage()
{
$user = $this->getUser();
$userId = $user['$id'] ?? '';
$session = $user['session'] ?? '';
$projectId = $this->getProject()['$id'];
$client = $this->getWebsocket(['account'], [
'origin' => 'http://localhost'
]);
$response = json_decode($client->receive(), true);
$this->assertCount(1, $response);
$this->assertArrayHasKey('account', $response);
$client->send(\json_encode([
'type' => 'authentication',
'data' => [
'session' => $session
]
]));
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('response', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertEquals('authentication', $response['data']['to']);
$this->assertTrue($response['data']['success']);
$client->close();
}
public function testChannelAccount()
{
$user = $this->getUser();
@ -148,7 +202,9 @@ trait RealtimeBase
'cookie' => 'a_session_'.$projectId.'=' . $session
]);
$response = json_decode($client->receive(), true);
$this->assertCount(1, $response);
$this->assertCount(2, $response);
$this->assertArrayHasKey('account', $response);
$this->assertArrayHasKey('account.' . $userId, $response);
/**
@ -167,14 +223,18 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.update.name', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.update.name', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$this->assertEquals($name, $response['payload']['name']);
$this->assertEquals($name, $response['data']['payload']['name']);
/**
@ -192,14 +252,18 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.update.password', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.update.password', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$this->assertEquals($name, $response['payload']['name']);
$this->assertEquals($name, $response['data']['payload']['name']);
/**
* Test Account Email Update
@ -216,14 +280,18 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.update.email', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.update.email', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$this->assertEquals('torsten@appwrite.io', $response['payload']['email']);
$this->assertEquals('torsten@appwrite.io', $response['data']['payload']['email']);
/**
* Test Account Verification Create
@ -239,11 +307,15 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.verification.create', $response['event']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.verification.create', $response['data']['event']);
$lastEmail = $this->getLastEmail();
$verification = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
@ -263,11 +335,15 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.verification.update', $response['event']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.verification.update', $response['data']['event']);
/**
* Test Acoount Prefs Update
@ -286,12 +362,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.update.prefs', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.update.prefs', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
/**
* Test Account Session Create
@ -310,12 +390,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.sessions.create', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.sessions.create', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
/**
* Test Account Session Delete
@ -329,12 +413,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.sessions.delete', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.sessions.delete', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
/**
* Test Account Create Recovery
@ -353,12 +441,16 @@ trait RealtimeBase
$lastEmail = $this->getLastEmail();
$recovery = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.recovery.create', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.recovery.create', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$response = $this->client->call(Client::METHOD_PUT, '/account/recovery', array_merge([
'origin' => 'http://localhost',
@ -373,12 +465,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response['channels']);
$this->assertArrayHasKey('timestamp', $response);
$this->assertContains('account', $response['channels']);
$this->assertContains('account.' . $userId, $response['channels']);
$this->assertEquals('account.recovery.update', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertContains('account', $response['data']['channels']);
$this->assertContains('account.' . $userId, $response['data']['channels']);
$this->assertEquals('account.recovery.update', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$client->close();
}
@ -394,6 +490,7 @@ trait RealtimeBase
'cookie' => 'a_session_'.$projectId.'=' . $session
]);
$response = json_decode($client->receive(), true);
$this->assertCount(2, $response);
$this->assertArrayHasKey('documents', $response);
$this->assertArrayHasKey('collections', $response);
@ -431,12 +528,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(2, $response['channels']);
$this->assertContains('collections', $response['channels']);
$this->assertContains('collections.' . $actors['body']['$id'], $response['channels']);
$this->assertEquals('database.collections.create', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertContains('collections', $response['data']['channels']);
$this->assertContains('collections.' . $actors['body']['$id'], $response['data']['channels']);
$this->assertEquals('database.collections.create', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$data = ['actorsId' => $actors['body']['$id']];
@ -457,13 +558,17 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(3, $response['channels']);
$this->assertContains('documents', $response['channels']);
$this->assertContains('documents.' . $document['body']['$id'], $response['channels']);
$this->assertContains('collections.' . $actors['body']['$id'] . '.documents', $response['channels']);
$this->assertEquals('database.documents.create', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(3, $response['data']['channels']);
$this->assertContains('documents', $response['data']['channels']);
$this->assertContains('documents.' . $document['body']['$id'], $response['data']['channels']);
$this->assertContains('collections.' . $actors['body']['$id'] . '.documents', $response['data']['channels']);
$this->assertEquals('database.documents.create', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$data['documentId'] = $document['body']['$id'];
@ -484,16 +589,20 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(3, $response['channels']);
$this->assertContains('documents', $response['channels']);
$this->assertContains('documents.' . $data['documentId'], $response['channels']);
$this->assertContains('collections.' . $data['actorsId'] . '.documents', $response['channels']);
$this->assertEquals('database.documents.update', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(3, $response['data']['channels']);
$this->assertContains('documents', $response['data']['channels']);
$this->assertContains('documents.' . $data['documentId'], $response['data']['channels']);
$this->assertContains('collections.' . $data['actorsId'] . '.documents', $response['data']['channels']);
$this->assertEquals('database.documents.update', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$this->assertEquals($response['payload']['firstName'], 'Chris1');
$this->assertEquals($response['payload']['lastName'], 'Evans2');
$this->assertEquals($response['data']['payload']['firstName'], 'Chris1');
$this->assertEquals($response['data']['payload']['lastName'], 'Evans2');
/**
* Test Document Delete
@ -520,13 +629,17 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(3, $response['channels']);
$this->assertContains('documents', $response['channels']);
$this->assertContains('documents.' . $document['body']['$id'], $response['channels']);
$this->assertContains('collections.' . $data['actorsId'] . '.documents', $response['channels']);
$this->assertEquals('database.documents.delete', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(3, $response['data']['channels']);
$this->assertContains('documents', $response['data']['channels']);
$this->assertContains('documents.' . $document['body']['$id'], $response['data']['channels']);
$this->assertContains('collections.' . $data['actorsId'] . '.documents', $response['data']['channels']);
$this->assertEquals('database.documents.delete', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$client->close();
}
@ -560,12 +673,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(2, $response['channels']);
$this->assertContains('files', $response['channels']);
$this->assertContains('files.' . $file['body']['$id'], $response['channels']);
$this->assertEquals('storage.files.create', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertContains('files', $response['data']['channels']);
$this->assertContains('files.' . $file['body']['$id'], $response['data']['channels']);
$this->assertEquals('storage.files.create', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$data = ['fileId' => $file['body']['$id']];
@ -582,12 +699,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(2, $response['channels']);
$this->assertContains('files', $response['channels']);
$this->assertContains('files.' . $file['body']['$id'], $response['channels']);
$this->assertEquals('storage.files.update', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertContains('files', $response['data']['channels']);
$this->assertContains('files.' . $file['body']['$id'], $response['data']['channels']);
$this->assertEquals('storage.files.update', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
/**
* Test File Delete
@ -599,12 +720,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(2, $response['channels']);
$this->assertContains('files', $response['channels']);
$this->assertContains('files.' . $file['body']['$id'], $response['channels']);
$this->assertEquals('storage.files.delete', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertContains('files', $response['data']['channels']);
$this->assertContains('files.' . $file['body']['$id'], $response['data']['channels']);
$this->assertEquals('storage.files.delete', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$client->close();
}
@ -678,21 +803,29 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$responseUpdate = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(3, $response['channels']);
$this->assertContains('executions', $response['channels']);
$this->assertContains('executions.' . $execution['body']['$id'], $response['channels']);
$this->assertContains('functions.' . $execution['body']['functionId'], $response['channels']);
$this->assertEquals('functions.executions.create', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(3, $response['data']['channels']);
$this->assertContains('executions', $response['data']['channels']);
$this->assertContains('executions.' . $execution['body']['$id'], $response['data']['channels']);
$this->assertContains('functions.' . $execution['body']['functionId'], $response['data']['channels']);
$this->assertEquals('functions.executions.create', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$this->assertArrayHasKey('timestamp', $responseUpdate);
$this->assertCount(3, $responseUpdate['channels']);
$this->assertContains('executions', $responseUpdate['channels']);
$this->assertContains('executions.' . $execution['body']['$id'], $responseUpdate['channels']);
$this->assertContains('functions.' . $execution['body']['functionId'], $responseUpdate['channels']);
$this->assertEquals('functions.executions.update', $responseUpdate['event']);
$this->assertNotEmpty($responseUpdate['payload']);
$this->assertArrayHasKey('type', $responseUpdate);
$this->assertArrayHasKey('data', $responseUpdate);
$this->assertEquals('event', $responseUpdate['type']);
$this->assertNotEmpty($responseUpdate['data']);
$this->assertArrayHasKey('timestamp', $responseUpdate['data']);
$this->assertCount(3, $responseUpdate['data']['channels']);
$this->assertContains('executions', $responseUpdate['data']['channels']);
$this->assertContains('executions.' . $execution['body']['$id'], $responseUpdate['data']['channels']);
$this->assertContains('functions.' . $execution['body']['functionId'], $responseUpdate['data']['channels']);
$this->assertEquals('functions.executions.update', $responseUpdate['data']['event']);
$this->assertNotEmpty($responseUpdate['data']['payload']);
$client->close();
}
@ -730,12 +863,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(2, $response['channels']);
$this->assertContains('teams', $response['channels']);
$this->assertContains('teams.' . $teamId, $response['channels']);
$this->assertEquals('teams.create', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertContains('teams', $response['data']['channels']);
$this->assertContains('teams.' . $teamId, $response['data']['channels']);
$this->assertEquals('teams.create', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
/**
* Test Team Update
@ -752,12 +889,16 @@ trait RealtimeBase
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(2, $response['channels']);
$this->assertContains('teams', $response['channels']);
$this->assertContains('teams.' . $teamId, $response['channels']);
$this->assertEquals('teams.update', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertContains('teams', $response['data']['channels']);
$this->assertContains('teams.' . $teamId, $response['data']['channels']);
$this->assertEquals('teams.update', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$client->close();
@ -805,12 +946,17 @@ trait RealtimeBase
]);
$response = json_decode($client->receive(), true);
$this->assertArrayHasKey('timestamp', $response);
$this->assertCount(2, $response['channels']);
$this->assertContains('memberships', $response['channels']);
$this->assertContains('memberships.' . $membershipId, $response['channels']);
$this->assertEquals('teams.memberships.update', $response['event']);
$this->assertNotEmpty($response['payload']);
$this->assertArrayHasKey('type', $response);
$this->assertArrayHasKey('data', $response);
$this->assertEquals('event', $response['type']);
$this->assertNotEmpty($response['data']);
$this->assertArrayHasKey('timestamp', $response['data']);
$this->assertCount(2, $response['data']['channels']);
$this->assertContains('memberships', $response['data']['channels']);
$this->assertContains('memberships.' . $membershipId, $response['data']['channels']);
$this->assertEquals('teams.memberships.update', $response['data']['event']);
$this->assertNotEmpty($response['data']['payload']);
$client->close();
}

View file

@ -149,11 +149,11 @@ class MessagingTest extends TestCase
];
$channels = Realtime::convertChannels($channels, $user->getId());
$this->assertCount(3, $channels);
$this->assertCount(4, $channels);
$this->assertArrayHasKey('files', $channels);
$this->assertArrayHasKey('documents', $channels);
$this->assertArrayHasKey('documents.789', $channels);
$this->assertArrayNotHasKey('account', $channels);
$this->assertArrayHasKey('account', $channels);
$this->assertArrayNotHasKey('account.456', $channels);
}
@ -187,12 +187,12 @@ class MessagingTest extends TestCase
$channels = Realtime::convertChannels($channels, $user->getId());
$this->assertCount(4, $channels);
$this->assertCount(5, $channels);
$this->assertArrayHasKey('files', $channels);
$this->assertArrayHasKey('documents', $channels);
$this->assertArrayHasKey('documents.789', $channels);
$this->assertArrayHasKey('account.123', $channels);
$this->assertArrayNotHasKey('account', $channels);
$this->assertArrayHasKey('account', $channels);
$this->assertArrayNotHasKey('account.456', $channels);
}
}