1
0
Fork 0
mirror of synced 2024-07-01 04:30:59 +12:00

Add content-type tests

This commit is contained in:
Jake Barnby 2022-07-13 15:50:25 +12:00
parent d0874e7612
commit bf284f4fde
2 changed files with 125 additions and 0 deletions

View file

@ -181,6 +181,10 @@ class Client
$query = $this->flatten($params);
break;
case 'application/graphql':
$query = $params[0];
break;
default:
$query = http_build_query($params);
break;

View file

@ -0,0 +1,121 @@
<?php
namespace Tests\E2E\Services\GraphQL;
use CURLFile;
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
class GraphQLBodyTypeTest extends Scope
{
use ProjectCustom;
use SideServer;
use GraphQLBase;
public function testGraphQLContentType()
{
$projectId = $this->getProject()['$id'];
$query = 'query { localeGetCountries { total countries { code } } }';
$graphQLPayload = [$query]; // Needs to be an array because the test client expects it
$response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/graphql',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertIsArray($response['body']['data']);
$this->assertArrayNotHasKey('errors', $response['body']);
$response = $response['body']['data']['localeGetCountries'];
$this->assertEquals(194, $response['total']);
}
public function testSingleQueryJSONContentType()
{
$projectId = $this->getProject()['$id'];
$query = 'query { localeGetCountries { total countries { code } } }';
$graphQLPayload = ['query' => $query];
$response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertIsArray($response['body']['data']);
$this->assertArrayNotHasKey('errors', $response['body']);
$response = $response['body']['data']['localeGetCountries'];
$this->assertEquals(194, $response['total']);
}
public function testBatchedJSONContentType()
{
$projectId = $this->getProject()['$id'];
$query1 = 'query { localeGetCountries { total countries { code } } }';
$query2 = 'query { localeGetContinents { total continents { code } } }';
$graphQLPayload = [
['query' => $query1],
['query' => $query2],
];
$response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $graphQLPayload);
$this->assertIsArray($response['body']['data']);
$this->assertArrayNotHasKey('errors', $response['body']);
$this->assertArrayHasKey('localeGetCountries', $response['body']['data']);
$this->assertArrayHasKey('localeGetContinents', $response['body']['data']);
$this->assertEquals(194, $response['body']['data']['localeGetCountries']['total']);
$this->assertEquals(7, $response['body']['data']['localeGetContinents']['total']);
}
public function testMultipartFormDataContentType()
{
$projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_BUCKET);
$gqlPayload = [
'query' => $query,
'variables' => [
'bucketId' => 'unique()',
'name' => 'Test Bucket',
'permission' => 'bucket',
'read' => ['role:all'],
'write' => ['role:all'],
]
];
$bucket = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$bucket = $bucket['body']['data']['storageCreateBucket'];
$query = $this->getQuery(self::$CREATE_FILE);
$gqlPayload = [
'operations' => \json_encode([
'query' => $query,
'variables' => [
'bucketId' => $bucket['_id'],
'fileId' => 'unique()',
'file' => null,
'permissions' => 'file',
'read' => ['role:all'],
'write' => ['role:all'],
]
]),
'map' => \json_encode([
'file' => ["variables.file"]
]),
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
];
$file = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $projectId,
], $this->getHeaders()), $gqlPayload);
$this->assertIsArray($file['body']['data']);
$this->assertArrayNotHasKey('errors', $file['body']);
$this->assertIsArray($file['body']['data']['storageCreateFile']);
}
}