mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch 'master' into feat-storage-buckets
This commit is contained in:
@@ -21,7 +21,7 @@ export default function () {
|
||||
// const url = new URL('wss://appwrite-realtime.monitor-api.com/v1/realtime');
|
||||
// url.searchParams.append('project', '604249e6b1a9f');
|
||||
const url = new URL('ws://localhost/v1/realtime');
|
||||
url.searchParams.append('project', '612625394933c');
|
||||
url.searchParams.append('project', 'console');
|
||||
url.searchParams.append('channels[]', 'files');
|
||||
|
||||
const res = ws.connect(url.toString(), function (socket) {
|
||||
|
||||
+15
-12
@@ -151,10 +151,11 @@ class Client
|
||||
* @param string $path
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
* @param bool $decode
|
||||
* @return array|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function call(string $method, string $path = '', array $headers = [], array $params = [])
|
||||
public function call(string $method, string $path = '', array $headers = [], array $params = [], bool $decode = true)
|
||||
{
|
||||
$headers = array_merge($this->headers, $headers);
|
||||
$ch = curl_init($this->endpoint . $path . (($method == self::METHOD_GET && !empty($params)) ? '?' . http_build_query($params) : ''));
|
||||
@@ -216,17 +217,19 @@ class Client
|
||||
$responseType = $responseHeaders['content-type'] ?? '';
|
||||
$responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
switch (substr($responseType, 0, strpos($responseType, ';'))) {
|
||||
case 'application/json':
|
||||
$json = json_decode($responseBody, true);
|
||||
|
||||
if ($json === null) {
|
||||
throw new Exception('Failed to parse response: '.$responseBody);
|
||||
}
|
||||
|
||||
$responseBody = $json;
|
||||
$json = null;
|
||||
break;
|
||||
if($decode) {
|
||||
switch (substr($responseType, 0, strpos($responseType, ';'))) {
|
||||
case 'application/json':
|
||||
$json = json_decode($responseBody, true);
|
||||
|
||||
if ($json === null) {
|
||||
throw new Exception('Failed to parse response: '.$responseBody);
|
||||
}
|
||||
|
||||
$responseBody = $json;
|
||||
$json = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((curl_errno($ch)/* || 200 != $responseStatus*/)) {
|
||||
|
||||
@@ -18,7 +18,7 @@ class HTTPTest extends Scope
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_OPTIONS, '/', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_OPTIONS, '/', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
]), []);
|
||||
@@ -38,7 +38,7 @@ class HTTPTest extends Scope
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/error', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_GET, '/error', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
]), []);
|
||||
@@ -54,7 +54,7 @@ class HTTPTest extends Scope
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/manifest.json', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_GET, '/manifest.json', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
]), []);
|
||||
@@ -73,7 +73,7 @@ class HTTPTest extends Scope
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/humans.txt', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_GET, '/humans.txt', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
|
||||
@@ -86,7 +86,7 @@ class HTTPTest extends Scope
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/robots.txt', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_GET, '/robots.txt', \array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
]), []);
|
||||
|
||||
@@ -128,26 +128,36 @@ class HTTPTest extends Scope
|
||||
'content-type' => 'application/json',
|
||||
], []);
|
||||
|
||||
if(!file_put_contents(__DIR__ . '/../../resources/open-api3.json', json_encode($response['body']))) {
|
||||
throw new Exception('Failed to save spec file');
|
||||
}
|
||||
$directory = __DIR__ . '/../../../app/config/specs/';
|
||||
|
||||
$files = scandir($directory);
|
||||
$client = new Client();
|
||||
$client->setEndpoint('https://validator.swagger.io');
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $client->call(Client::METHOD_POST, '/validator/debug', [
|
||||
'content-type' => 'application/json',
|
||||
], json_decode(file_get_contents(realpath(__DIR__ . '/../../resources/open-api3.json')), true));
|
||||
foreach($files as $file) {
|
||||
if(in_array($file, ['.', '..'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$response['body'] = json_decode($response['body'], true);
|
||||
if(
|
||||
(strpos($file, 'latest') === false) &&
|
||||
(strpos($file, '0.12.x') === false)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertTrue(empty($response['body']));
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $client->call(Client::METHOD_POST, '/validator/debug', [
|
||||
'content-type' => 'application/json',
|
||||
], json_decode(file_get_contents($directory.$file), true));
|
||||
|
||||
unlink(realpath(__DIR__ . '/../../resources/open-api3.json'));
|
||||
$response['body'] = json_decode($response['body'], true);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertTrue(empty($response['body']));
|
||||
}
|
||||
}
|
||||
|
||||
public function testResponseHeader() {
|
||||
@@ -155,7 +165,7 @@ class HTTPTest extends Scope
|
||||
/**
|
||||
* Test without header
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
], $this->getHeaders()));
|
||||
@@ -173,7 +183,7 @@ class HTTPTest extends Scope
|
||||
/**
|
||||
* Test with header
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
'x-appwrite-response-format' => '0.6.2'
|
||||
@@ -192,7 +202,7 @@ class HTTPTest extends Scope
|
||||
/**
|
||||
* Test without header
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/versions', array_merge([
|
||||
$response = $this->client->call(Client::METHOD_GET, '/versions', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
], $this->getHeaders()));
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ abstract class Scope extends TestCase
|
||||
|
||||
protected function getLastRequest():array
|
||||
{
|
||||
sleep(1);
|
||||
sleep(5);
|
||||
|
||||
$resquest = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true);
|
||||
$resquest['data'] = json_decode($resquest['data'], true);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Tests\E2E\Services\Account;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use function array_merge;
|
||||
|
||||
trait AccountBase
|
||||
{
|
||||
@@ -751,6 +752,36 @@ trait AccountBase
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 400);
|
||||
|
||||
/**
|
||||
* Prefs size exceeded
|
||||
*/
|
||||
$prefsObject = ["longValue" => str_repeat("🍰", 100000)];
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
||||
]), [
|
||||
'prefs' => $prefsObject
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
// Now let's test the same thing, but with normal symbol instead of multi-byte cake emoji
|
||||
$prefsObject = ["longValue" => str_repeat("-", 100000)];
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
||||
]), [
|
||||
'prefs' => $prefsObject
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -343,49 +343,49 @@ trait DatabaseBase
|
||||
// wait for database worker to create attributes
|
||||
sleep(30);
|
||||
|
||||
$stringResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$collectionId}_{$string['body']['key']}",array_merge([
|
||||
$stringResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$string['body']['key']}",array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$emailResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$collectionId}_{$email['body']['key']}",array_merge([
|
||||
$emailResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$email['body']['key']}",array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$enumResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$collectionId}_{$enum['body']['key']}",array_merge([
|
||||
$enumResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$enum['body']['key']}",array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$ipResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$collectionId}_{$ip['body']['key']}",array_merge([
|
||||
$ipResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$ip['body']['key']}",array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$urlResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$collectionId}_{$url['body']['key']}",array_merge([
|
||||
$urlResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$url['body']['key']}",array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$integerResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$collectionId}_{$integer['body']['key']}",array_merge([
|
||||
$integerResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$integer['body']['key']}",array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$floatResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$collectionId}_{$float['body']['key']}",array_merge([
|
||||
$floatResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$float['body']['key']}",array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$booleanResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$collectionId}_{$boolean['body']['key']}",array_merge([
|
||||
$booleanResponse = $this->client->call(Client::METHOD_GET, "/database/collections/{$collectionId}/attributes/{$boolean['body']['key']}",array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
@@ -827,6 +827,10 @@ trait DatabaseBase
|
||||
$this->assertEquals(2019, $documents['body']['documents'][2]['releaseYear']);
|
||||
$this->assertCount(3, $documents['body']['documents']);
|
||||
|
||||
foreach ($documents['body']['documents'] as $document) {
|
||||
$this->assertEquals($data['moviesId'], $document['$collection']);
|
||||
}
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -841,7 +845,28 @@ trait DatabaseBase
|
||||
$this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(3, $documents['body']['documents']);
|
||||
|
||||
return [];
|
||||
return $documents['body']['documents'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testListDocuments
|
||||
*/
|
||||
public function testGetDocument(array $documents): void
|
||||
{
|
||||
foreach ($documents as $document) {
|
||||
$response = $this->client->call(Client::METHOD_GET, '/database/collections/' . $document['$collection'] . '/documents/' . $document['$id'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
$this->assertEquals($response['body']['$id'], $document['$id']);
|
||||
$this->assertEquals($response['body']['$collection'], $document['$collection']);
|
||||
$this->assertEquals($response['body']['title'], $document['title']);
|
||||
$this->assertEquals($response['body']['releaseYear'], $document['releaseYear']);
|
||||
$this->assertEquals($response['body']['$read'], $document['$read']);
|
||||
$this->assertEquals($response['body']['$write'], $document['$write']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1120,6 +1145,17 @@ trait DatabaseBase
|
||||
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['$id.equal("' . $documents['body']['documents'][0]['$id'] . '")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertCount(1, $documents['body']['documents']);
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -1176,6 +1212,21 @@ trait DatabaseBase
|
||||
$this->assertEquals(400, $documents['headers']['status-code']);
|
||||
$this->assertEquals('Index not found: actors', $documents['body']['message']);
|
||||
|
||||
$conditions = [];
|
||||
|
||||
for ($i=0; $i < 101; $i++) {
|
||||
$conditions[] = $i;
|
||||
}
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['releaseYear.equal(' . implode(',', $conditions) . ')'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $documents['headers']['status-code']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -1218,6 +1269,8 @@ trait DatabaseBase
|
||||
]);
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 200);
|
||||
$this->assertEquals($document['body']['$id'], $id);
|
||||
$this->assertEquals($document['body']['$collection'], $data['moviesId']);
|
||||
$this->assertEquals($document['body']['title'], 'Thor: Ragnarok');
|
||||
$this->assertEquals($document['body']['releaseYear'], 2017);
|
||||
$this->assertEquals('role:member', $document['body']['$read'][0]);
|
||||
@@ -1280,7 +1333,7 @@ trait DatabaseBase
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 404);
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ class HealthCustomServerTest extends Scope
|
||||
], $this->getHeaders()), []);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('OK', $response['body']['status']);
|
||||
$this->assertEquals('pass', $response['body']['status']);
|
||||
$this->assertIsInt($response['body']['ping']);
|
||||
$this->assertLessThan(100, $response['body']['ping']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -45,7 +47,9 @@ class HealthCustomServerTest extends Scope
|
||||
], $this->getHeaders()), []);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('OK', $response['body']['status']);
|
||||
$this->assertEquals('pass', $response['body']['status']);
|
||||
$this->assertIsInt($response['body']['ping']);
|
||||
$this->assertLessThan(100, $response['body']['ping']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -65,7 +69,9 @@ class HealthCustomServerTest extends Scope
|
||||
], $this->getHeaders()), []);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('OK', $response['body']['status']);
|
||||
$this->assertEquals('pass', $response['body']['status']);
|
||||
$this->assertIsInt($response['body']['ping']);
|
||||
$this->assertLessThan(100, $response['body']['ping']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -85,10 +91,10 @@ class HealthCustomServerTest extends Scope
|
||||
], $this->getHeaders()), []);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['remote']);
|
||||
$this->assertIsInt($response['body']['local']);
|
||||
$this->assertNotEmpty($response['body']['remote']);
|
||||
$this->assertNotEmpty($response['body']['local']);
|
||||
$this->assertIsInt($response['body']['remoteTime']);
|
||||
$this->assertIsInt($response['body']['localTime']);
|
||||
$this->assertNotEmpty($response['body']['remoteTime']);
|
||||
$this->assertNotEmpty($response['body']['localTime']);
|
||||
$this->assertLessThan(10, $response['body']['diff']);
|
||||
|
||||
/**
|
||||
@@ -152,7 +158,7 @@ class HealthCustomServerTest extends Scope
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(160, $response['body']['size']);
|
||||
$this->assertLessThan(200, $response['body']['size']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -193,7 +199,9 @@ class HealthCustomServerTest extends Scope
|
||||
], $this->getHeaders()), []);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('OK', $response['body']['status']);
|
||||
$this->assertEquals('pass', $response['body']['status']);
|
||||
$this->assertIsInt($response['body']['ping']);
|
||||
$this->assertLessThan(100, $response['body']['ping']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
|
||||
@@ -7,7 +7,7 @@ use WebSocket\Client as WebSocketClient;
|
||||
|
||||
trait RealtimeBase
|
||||
{
|
||||
private function getWebsocket($channels = [], $headers = [], $projectId = null)
|
||||
private function getWebsocket($channels = [], $headers = [], $projectId = null): WebSocketClient
|
||||
{
|
||||
if (is_null($projectId)) {
|
||||
$projectId = $this->getProject()['$id'];
|
||||
@@ -28,7 +28,7 @@ trait RealtimeBase
|
||||
]);
|
||||
}
|
||||
|
||||
public function testConnection()
|
||||
public function testConnection(): void
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
@@ -36,10 +36,10 @@ trait RealtimeBase
|
||||
$client = $this->getWebsocket(['documents']);
|
||||
$this->assertNotEmpty($client->receive());
|
||||
$client->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
public function testConnectionFailureMissingChannels(): void
|
||||
{
|
||||
$client = $this->getWebsocket();
|
||||
$payload = json_decode($client->receive(), true);
|
||||
|
||||
@@ -50,22 +50,10 @@ trait RealtimeBase
|
||||
$this->assertEquals('Missing channels', $payload['data']['message']);
|
||||
$this->expectException(ConnectionException::class); // Check if server disconnnected client
|
||||
$client->close();
|
||||
}
|
||||
|
||||
$client = new WebSocketClient('ws://appwrite-traefik/v1/realtime?channels[]=files"', [
|
||||
'headers' => [
|
||||
'Origin' => 'appwrite.test'
|
||||
]
|
||||
]);
|
||||
$payload = json_decode($client->receive(), true);
|
||||
|
||||
$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();
|
||||
|
||||
public function testConnectionFailureUnknownProject(): void
|
||||
{
|
||||
$client = new WebSocketClient('ws://appwrite-traefik/v1/realtime?project=123', [
|
||||
'headers' => [
|
||||
'Origin' => 'appwrite.test'
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\E2E\Services\Teams;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectConsole;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
@@ -12,4 +13,52 @@ class TeamsConsoleClientTest extends Scope
|
||||
use TeamsBaseClient;
|
||||
use ProjectConsole;
|
||||
use SideClient;
|
||||
|
||||
public function testRequestHeader() {
|
||||
/**
|
||||
* Test without header
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/teams', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console'
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Latest version Team',
|
||||
'teamId' => 'unique()'
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$team1Id = $response['body']['$id'];
|
||||
|
||||
/**
|
||||
* Test with header
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/teams', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
'x-appwrite-response-format' => '0.11.0'
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Latest version Team'
|
||||
// Notice "teamId' is not defined
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$team2Id = $response['body']['$id'];
|
||||
|
||||
/**
|
||||
* Cleanup, so I don't invalidate some listTeams requests by mistake
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team1Id, \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(204, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team2Id, \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(204, $response['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -20,13 +20,20 @@ trait UsersBase
|
||||
'email' => 'cristiano.ronaldo@manchester-united.co.uk',
|
||||
'password' => 'password',
|
||||
'name' => 'Cristiano Ronaldo',
|
||||
]);
|
||||
], false);
|
||||
|
||||
// Test empty prefs is object not array
|
||||
$bodyString = $user['body'];
|
||||
$prefs = substr($bodyString, strpos($bodyString, '"prefs":')+8,2);
|
||||
$this->assertEquals('{}', $prefs);
|
||||
|
||||
$body = json_decode($bodyString, true);
|
||||
|
||||
$this->assertEquals($user['headers']['status-code'], 201);
|
||||
$this->assertEquals($user['body']['name'], 'Cristiano Ronaldo');
|
||||
$this->assertEquals($user['body']['email'], 'cristiano.ronaldo@manchester-united.co.uk');
|
||||
$this->assertEquals($user['body']['status'], true);
|
||||
$this->assertGreaterThan(0, $user['body']['registration']);
|
||||
$this->assertEquals($body['name'], 'Cristiano Ronaldo');
|
||||
$this->assertEquals($body['email'], 'cristiano.ronaldo@manchester-united.co.uk');
|
||||
$this->assertEquals($body['status'], true);
|
||||
$this->assertGreaterThan(0, $body['registration']);
|
||||
|
||||
/**
|
||||
* Test Create with Custom ID for SUCCESS
|
||||
@@ -48,7 +55,7 @@ trait UsersBase
|
||||
$this->assertEquals(true, $res['body']['status']);
|
||||
$this->assertGreaterThan(0, $res['body']['registration']);
|
||||
|
||||
return ['userId' => $user['body']['$id']];
|
||||
return ['userId' => $body['$id']];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,13 +22,13 @@ class ResponseTest extends TestCase
|
||||
|
||||
public function testSetFilter()
|
||||
{
|
||||
$this->assertEquals($this->object->isFilter(), false);
|
||||
$this->assertEquals($this->object->hasFilter(), false);
|
||||
$this->assertEquals($this->object->getFilter(), null);
|
||||
|
||||
$filter = new V06();
|
||||
$this->object->setFilter($filter);
|
||||
|
||||
$this->assertEquals($this->object->isFilter(), true);
|
||||
$this->assertEquals($this->object->hasFilter(), true);
|
||||
$this->assertEquals($this->object->getFilter(), $filter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user