diff --git a/tests/e2e/Services/GraphQL/GraphQLBase.php b/tests/e2e/Services/GraphQL/GraphQLBase.php index 9b87ecdd57..a4d29cca00 100644 --- a/tests/e2e/Services/GraphQL/GraphQLBase.php +++ b/tests/e2e/Services/GraphQL/GraphQLBase.php @@ -155,6 +155,19 @@ trait GraphQLBase public static string $UPDATE_FILE = 'update_file'; public static string $DELETE_FILE = 'delete_file'; + // Health + public static string $GET_HTTP_HEALTH = 'get_http_health'; + public static string $GET_DB_HEALTH = 'get_db_health'; + public static string $GET_CACHE_HEALTH = 'get_cache_health'; + public static string $GET_TIME_HEALTH = 'get_time_health'; + public static string $GET_WEBHOOKS_QUEUE_HEALTH = 'get_webhooks_queue_health'; + public static string $GET_LOGS_QUEUE_HEALTH = 'get_logs_queue_health'; + public static string $GET_CERTIFICATES_QUEUE_HEALTH = 'get_certificates_queue_health'; + public static string $GET_FUNCTION_QUEUE_HEALTH = 'get_functions_queue_health'; + public static string $GET_LOCAL_STORAGE_HEALTH = 'get_local_storage_health'; + public static string $GET_ANITVIRUS_HEALTH = 'get_antivirus_health'; + + public function getQuery(string $name): string { switch ($name) { @@ -1230,6 +1243,73 @@ trait GraphQLBase return 'mutation deleteFile($bucketId: String!, $fileId: String!) { storageDeleteFile(bucketId: $bucketId, fileId: $fileId) }'; + case self::$GET_HTTP_HEALTH: + return 'query getHttpHealth { + healthGet { + ping + status + } + }'; + case self::$GET_DB_HEALTH: + return 'query getDbHealth { + healthGetDB { + ping + status + } + }'; + case self::$GET_CACHE_HEALTH: + return 'query getCacheHealth { + healthGetCache { + ping + status + } + }'; + case self::$GET_TIME_HEALTH: + return 'query getTimeHealth { + healthGetTime { + remoteTime + localTime + diff + } + }'; + case self::$GET_WEBHOOKS_QUEUE_HEALTH: + return 'query getWebhooksQueueHealth { + healthGetQueueWebhooks { + size + } + }'; + case self::$GET_LOGS_QUEUE_HEALTH: + return 'query getLogsQueueHealth { + healthGetQueueLogs { + size + } + }'; + case self::$GET_CERTIFICATES_QUEUE_HEALTH: + return 'query getCertificatesQueueHealth { + healthGetQueueCertificates { + size + } + }'; + case self::$GET_FUNCTION_QUEUE_HEALTH: + return 'query getFunctionQueueHealth { + healthGetQueueFunctions { + size + } + }'; + case self::$GET_LOCAL_STORAGE_HEALTH: + return 'query getLocalStorageHealth { + healthGetStorageLocal { + ping + status + } + }'; + case self::$GET_ANITVIRUS_HEALTH: + return 'query getAntivirusHealth { + healthGetAntivirus { + version + status + } + }'; } throw new \InvalidArgumentException('Invalid query type'); diff --git a/tests/e2e/Services/GraphQL/GraphQLHealthTest.php b/tests/e2e/Services/GraphQL/GraphQLHealthTest.php new file mode 100644 index 0000000000..9e51aaadd0 --- /dev/null +++ b/tests/e2e/Services/GraphQL/GraphQLHealthTest.php @@ -0,0 +1,226 @@ +getProject()['$id']; + $query = $this->getQuery(self::$GET_HTTP_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $httpHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($httpHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $httpHealth['body']); + $httpHealth = $httpHealth['body']['data']['healthGet']; + $this->assertIsArray($httpHealth); + + return $httpHealth; + } + + public function testGetDBHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_DB_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $dbHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($dbHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $dbHealth['body']); + $dbHealth = $dbHealth['body']['data']['healthGetDB']; + $this->assertIsArray($dbHealth); + + return $dbHealth; + } + + public function testGetCacheHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_CACHE_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $cacheHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($cacheHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $cacheHealth['body']); + $cacheHealth = $cacheHealth['body']['data']['healthGetCache']; + $this->assertIsArray($cacheHealth); + + return $cacheHealth; + } + + public function testGetTimeHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_TIME_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $timeHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($timeHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $timeHealth['body']); + $timeHealth = $timeHealth['body']['data']['healthGetTime']; + $this->assertIsArray($timeHealth); + + return $timeHealth; + } + + public function testGetWebhooksQueueHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_WEBHOOKS_QUEUE_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $webhooksQueueHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($webhooksQueueHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $webhooksQueueHealth['body']); + $webhooksQueueHealth = $webhooksQueueHealth['body']['data']['healthGetQueueWebhooks']; + $this->assertIsArray($webhooksQueueHealth); + + return $webhooksQueueHealth; + } + + public function testGetLogsQueueHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_LOGS_QUEUE_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $logsQueueHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($logsQueueHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $logsQueueHealth['body']); + $logsQueueHealth = $logsQueueHealth['body']['data']['healthGetQueueLogs']; + $this->assertIsArray($logsQueueHealth); + + return $logsQueueHealth; + } + + public function testGetCertificatesQueueHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_CERTIFICATES_QUEUE_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $certificatesQueueHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($certificatesQueueHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $certificatesQueueHealth['body']); + $certificatesQueueHealth = $certificatesQueueHealth['body']['data']['healthGetQueueCertificates']; + $this->assertIsArray($certificatesQueueHealth); + + return $certificatesQueueHealth; + } + + public function testGetFunctionsQueueHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_FUNCTION_QUEUE_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $functionsQueueHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($functionsQueueHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $functionsQueueHealth['body']); + $functionsQueueHealth = $functionsQueueHealth['body']['data']['healthGetQueueFunctions']; + $this->assertIsArray($functionsQueueHealth); + + return $functionsQueueHealth; + } + + public function testGetLocalStorageHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_LOCAL_STORAGE_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $localStorageHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($localStorageHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $localStorageHealth['body']); + $localStorageHealth = $localStorageHealth['body']['data']['healthGetStorageLocal']; + $this->assertIsArray($localStorageHealth); + + return $localStorageHealth; + } + + public function testGetAntiVirusHealth() + { + $projectId = $this->getProject()['$id']; + $query = $this->getQuery(self::$GET_ANITVIRUS_HEALTH); + $graphQLPayload = [ + 'query' => $query, + ]; + + $antiVirusHealth = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), $graphQLPayload); + + $this->assertIsArray($antiVirusHealth['body']['data']); + $this->assertArrayNotHasKey('errors', $antiVirusHealth['body']); + $antiVirusHealth = $antiVirusHealth['body']['data']['healthGetAntivirus']; + $this->assertIsArray($antiVirusHealth); + + return $antiVirusHealth; + } +} \ No newline at end of file