From 4a0042f3d6b1f2c78e20cf0c367125fbe601008a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 4 Jul 2022 18:16:32 +1200 Subject: [PATCH] Add avatars service tests --- .../Services/GraphQL/GraphQLAvatarsTest.php | 163 ++++++++++++++++++ tests/e2e/Services/GraphQL/GraphQLBase.php | 109 +++++++++++- 2 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/Services/GraphQL/GraphQLAvatarsTest.php diff --git a/tests/e2e/Services/GraphQL/GraphQLAvatarsTest.php b/tests/e2e/Services/GraphQL/GraphQLAvatarsTest.php new file mode 100644 index 0000000000..1007dd1ff1 --- /dev/null +++ b/tests/e2e/Services/GraphQL/GraphQLAvatarsTest.php @@ -0,0 +1,163 @@ +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']; + } +} \ No newline at end of file diff --git a/tests/e2e/Services/GraphQL/GraphQLBase.php b/tests/e2e/Services/GraphQL/GraphQLBase.php index 82890e41db..9b87ecdd57 100644 --- a/tests/e2e/Services/GraphQL/GraphQLBase.php +++ b/tests/e2e/Services/GraphQL/GraphQLBase.php @@ -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!]!) {