1
0
Fork 0
mirror of synced 2024-10-04 12:15:14 +13:00

Add avatars service tests

This commit is contained in:
Jake Barnby 2022-07-04 18:16:32 +12:00
parent c22ffc1dfe
commit 4a0042f3d6
2 changed files with 269 additions and 3 deletions

View file

@ -0,0 +1,163 @@
<?php
namespace Tests\E2E\Services\GraphQL;
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideClient;
use Tests\E2E\Scopes\SideServer;
class GraphQLAvatarsTest extends Scope
{
use ProjectCustom;
use SideServer;
use GraphQLBase;
public function testGetCreditCardIcon()
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_CREDIT_CARD_ICON);
$graphQLPayload = [
'query' => $query,
'variables' => [
'code' => 'visa',
],
];
$creditCardIcon = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertEquals(18767, \strlen($creditCardIcon['body']));
return $creditCardIcon['body'];
}
public function testGetBrowserIcon()
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_BROWSER_ICON);
$graphQLPayload = [
'query' => $query,
'variables' => [
'code' => 'ff',
],
];
$browserIcon = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertEquals(11100, \strlen($browserIcon['body']));
return $browserIcon['body'];
}
public function testGetCountryFlag()
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_COUNTRY_FLAG);
$graphQLPayload = [
'query' => $query,
'variables' => [
'code' => 'us',
],
];
$countryFlag = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertEquals(7460, \strlen($countryFlag['body']));
return $countryFlag['body'];
}
public function testGetImageFromURL()
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_IMAGE_FROM_URL);
$graphQLPayload = [
'query' => $query,
'variables' => [
'url' => 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
],
];
$image = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertEquals(36036, \strlen($image['body']));
return $image['body'];
}
public function testGetFavicon()
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_FAVICON);
$graphQLPayload = [
'query' => $query,
'variables' => [
'url' => 'https://www.google.com/',
],
];
$favicon = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertEquals(5430, \strlen($favicon['body']));
return $favicon['body'];
}
public function testGetQRCode()
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_QRCODE);
$graphQLPayload = [
'query' => $query,
'variables' => [
'text' => 'https://www.google.com/',
],
];
$qrCode = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertEquals(14771, \strlen($qrCode['body']));
return $qrCode['body'];
}
public function testGetInitials()
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$GET_USER_INITIALS);
$graphQLPayload = [
'query' => $query,
'variables' => [
'name' => 'John Doe',
],
];
$initials = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertEquals(3948, \strlen($initials['body']));
return $initials['body'];
}
}

View file

@ -41,8 +41,23 @@ trait GraphQLBase
public static string $UPDATE_DOCUMENT = 'update_document';
public static string $DELETE_DOCUMENT = 'delete_document';
// Locales
// Localization
public static string $GET_LOCALE = 'get_locale';
public static string $LIST_COUNTRIES = 'list_countries';
public static string $LIST_EU_COUNTRIES = 'list_eu_countries';
public static string $LIST_COUNTRY_PHONE_CODES = 'list_country_phone_codes';
public static string $LIST_CONTINENTS = 'list_continents';
public static string $LIST_CURRENCIES = 'list_currencies';
public static string $LIST_LANGUAGES = 'list_languages';
// Avatars
public static string $GET_CREDIT_CARD_ICON = 'get_credit_card_icon';
public static string $GET_BROWSER_ICON = 'get_browser_icon';
public static string $GET_COUNTRY_FLAG = 'get_country_flag';
public static string $GET_IMAGE_FROM_URL = 'get_image_from_url';
public static string $GET_FAVICON = 'get_favicon';
public static string $GET_QRCODE = 'get_qrcode';
public static string $GET_USER_INITIALS = 'get_user_initials';
// Projects
public static string $CREATE_API_KEY = 'create_key';
@ -558,6 +573,15 @@ trait GraphQLBase
return 'mutation deleteUser($userId: String!) {
usersDelete(userId: $userId)
}';
case self::$GET_LOCALE:
return 'query getLocale {
localeGet {
ip
country
continent
currency
}
}';
case self::$LIST_COUNTRIES:
return 'query listCountries {
localeGetCountries{
@ -568,6 +592,85 @@ trait GraphQLBase
}
}
}';
case self::$LIST_EU_COUNTRIES:
return 'query listEuCountries {
localeGetCountriesEU{
total
countries {
name
code
}
}
}';
case self::$LIST_COUNTRY_PHONE_CODES:
return 'query listCountryPhoneCodes {
localeGetCountriesPhones {
total
phones {
code
countryName
}
}
}';
case self::$LIST_CONTINENTS:
return 'query listContinents {
localeGetContinents{
total
continents {
name
code
}
}
}';
case self::$LIST_CURRENCIES:
return 'query listCurrencies {
localeGetCurrencies{
total
currencies {
name
code
symbol
}
}
}';
case self::$LIST_LANGUAGES:
return 'query listLanguages {
localeGetLanguages{
total
languages {
name
code
}
}
}';
case self::$GET_CREDIT_CARD_ICON:
return 'query getCreditCardIcon($code: String!) {
avatarsGetCreditCard(code: $code)
}';
case self::$GET_BROWSER_ICON:
return 'query getBrowserIcon($code: String!) {
avatarsGetBrowser(code: $code)
}';
case self::$GET_COUNTRY_FLAG:
return 'query getCountryFlag($code: String!) {
avatarsGetFlag(code: $code)
}';
case self::$GET_IMAGE_FROM_URL:
return 'query getImageFromUrl($url: String!) {
avatarsGetImage(url: $url)
}';
case self::$GET_FAVICON:
return 'query getFavicon($url: String!) {
avatarsGetFavicon(url: $url)
}';
case self::$GET_QRCODE:
return 'query getQrCode($text: String!) {
avatarsGetQR(text: $text)
}';
case self::$GET_USER_INITIALS:
return 'query getUserInitials($name: String!) {
avatarsGetInitials(name: $name)
}';
case self::$CREATE_API_KEY:
return 'mutation createKey($projectId: String!, $name: String!, $scopes: [String!]!){
projectsCreateKey(projectId: $projectId, name: $name, scopes: $scopes) {
@ -1029,8 +1132,8 @@ trait GraphQLBase
functionsDeleteExecution(functionId: $functionId, executionId: $executionId)
}';
case self::$RETRY_BUILD:
return 'mutation retryBuild($functionId: String!, $deploymentId: String!) {
functionsRetryBuild(functionId: $functionId, deploymentId: $deploymentId)
return 'mutation retryBuild($functionId: String!, $deploymentId: String!, $buildId: String!) {
functionsRetryBuild(functionId: $functionId, deploymentId: $deploymentId, buildId: $buildId)
}';
case self::$CREATE_BUCKET:
return 'mutation createBucket($bucketId: String!, $name: String!, $permission: String!, $read: [String!]!, $write: [String!]!) {