Remove redundant tests
This commit is contained in:
parent
2b3ba0370b
commit
fead0f89b9
|
@ -14,106 +14,6 @@ class GraphQLClientTest extends Scope
|
|||
use SideClient;
|
||||
use GraphQLBase;
|
||||
|
||||
public function testCreateAccounts(): array
|
||||
{
|
||||
$projectId = $this->getProject()['$id'];
|
||||
$query = $this->getQuery(self::$CREATE_ACCOUNT);
|
||||
$email = 'test' . \rand() . '@test.com';
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'userId' => 'unique()',
|
||||
'name' => 'Tester',
|
||||
'email' => $email,
|
||||
'password' => 'password',
|
||||
],
|
||||
];
|
||||
$account1 = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $graphQLPayload);
|
||||
|
||||
$this->assertIsArray($account1['body']['data']);
|
||||
$account1 = $account1['body']['data']['accountCreate'];
|
||||
$this->assertEquals('Tester', $account1['name']);
|
||||
$this->assertEquals($email, $account1['email']);
|
||||
|
||||
// Create First Account Session
|
||||
$query = $this->getQuery(self::$CREATE_ACCOUNT_SESSION);
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'email' => $email,
|
||||
'password' => 'password',
|
||||
]
|
||||
];
|
||||
|
||||
$session1 = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $graphQLPayload);
|
||||
|
||||
$this->assertIsArray($session1['body']['data']);
|
||||
$this->assertIsArray($session1['body']['data']['accountCreateSession']);
|
||||
|
||||
$session1Cookie = $this->client->parseCookie((string)$session1['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
||||
|
||||
/*
|
||||
* Create Second Account
|
||||
*/
|
||||
$query = $this->getQuery(self::$CREATE_ACCOUNT);
|
||||
$email = 'test' . \rand() . '@test.com';
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'userId' => 'unique()',
|
||||
'email' => $email,
|
||||
'password' => 'password',
|
||||
'name' => 'Tester2',
|
||||
],
|
||||
];
|
||||
$account2 = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $graphQLPayload);
|
||||
|
||||
$this->assertIsArray($account2['body']['data']);
|
||||
$this->assertIsArray($account2['body']['data']['accountCreate']);
|
||||
$this->assertArrayNotHasKey('errors', $account2['body']);
|
||||
|
||||
$account2 = $account2['body']['data']['accountCreate'];
|
||||
$this->assertEquals('Tester2', $account2['name']);
|
||||
$this->assertEquals($email, $account2['email']);
|
||||
|
||||
/*
|
||||
* Create Second Account Session
|
||||
*/
|
||||
$query = $this->getQuery(self::$CREATE_ACCOUNT_SESSION);
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => [
|
||||
'email' => $email,
|
||||
'password' => 'password',
|
||||
],
|
||||
];
|
||||
$session2 = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $graphQLPayload);
|
||||
|
||||
$this->assertIsArray($session2['body']['data']);
|
||||
$this->assertIsArray($session2['body']['data']['accountCreateSession']);
|
||||
$this->assertArrayNotHasKey('errors', $session2['body']);
|
||||
$session2Cookie = $this->client->parseCookie((string)$session2['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
||||
|
||||
return [
|
||||
'session1Cookie' => $session1Cookie,
|
||||
'session2Cookie' => $session2Cookie,
|
||||
'user1Id' => $session1['body']['data']['accountCreateSession']['userId'],
|
||||
'user2Id' => $session2['body']['data']['accountCreateSession']['userId'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCollection
|
||||
* @depends testCreateStringAttribute
|
||||
|
|
|
@ -14,194 +14,6 @@ class GraphQLServerTest extends Scope
|
|||
use SideServer;
|
||||
use GraphQLBase;
|
||||
|
||||
/**
|
||||
* @depends testCreateCollection
|
||||
* @depends testCreateStringAttribute
|
||||
* @depends testCreateIntegerAttribute
|
||||
* @depends testCreateBooleanAttribute
|
||||
*/
|
||||
public function testDocumentCreate(array $data)
|
||||
{
|
||||
$projectId = $this->getProject()['$id'];
|
||||
$key = '';
|
||||
$query = $this->getQuery(self::$CREATE_DOCUMENT_REST);
|
||||
|
||||
$variables = [
|
||||
'documentId' => 'unique()',
|
||||
'collectionId' => $data['collectionId'],
|
||||
'data' => [
|
||||
'name' => 'Robert',
|
||||
'age' => 100,
|
||||
'alive' => true,
|
||||
],
|
||||
'read' => ['role:all'],
|
||||
'write' => ['role:all'],
|
||||
];
|
||||
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => $variables
|
||||
];
|
||||
|
||||
$document = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $key
|
||||
], $graphQLPayload);
|
||||
|
||||
$errorMessage = 'User (role: guest) missing scope (documents.write)';
|
||||
$this->assertEquals($errorMessage, $document['body']['errors'][0]['message']);
|
||||
$this->assertIsArray($document['body']['data']);
|
||||
$this->assertNull($document['body']['data']['databaseCreateDocument']);
|
||||
|
||||
$key = $this->getNewKey(['documents.write']);
|
||||
$document = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $key
|
||||
]), $graphQLPayload);
|
||||
|
||||
$this->assertArrayNotHasKey('errors', $document['body']);
|
||||
$this->assertIsArray($document['body']['data']);
|
||||
$this->assertIsArray($document['body']['data']['databaseCreateDocument']);
|
||||
|
||||
$doc = $document['body']['data']['databaseCreateDocument'];
|
||||
|
||||
$this->assertArrayHasKey('_id', $doc);
|
||||
$this->assertEquals($data['collectionId'], $doc['_collection']);
|
||||
$this->assertEquals($variables['read'], $doc['_read']);
|
||||
$this->assertEquals($variables['write'], $doc['_write']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testUserCreate()
|
||||
{
|
||||
/**
|
||||
* Try to create a user without the required scope
|
||||
*/
|
||||
$projectId = $this->getProject()['$id'];
|
||||
$query = $this->getQuery(self::$CREATE_USER);
|
||||
|
||||
$variables = [
|
||||
'userId' => 'unique()',
|
||||
'email' => 'users.service@example.com',
|
||||
'password' => 'password',
|
||||
'name' => 'Project User',
|
||||
];
|
||||
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => $variables
|
||||
];
|
||||
|
||||
$user = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $graphQLPayload);
|
||||
|
||||
$errorMessage = 'User (role: guest) missing scope (users.write)';
|
||||
$this->assertEquals($errorMessage, $user['body']['errors'][0]['message']);
|
||||
$this->assertArrayNotHasKey('data', $user['body']);
|
||||
|
||||
/**
|
||||
* Create the user with the required scopes
|
||||
*/
|
||||
$key = $this->getNewKey(['users.write']);
|
||||
$user = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $key
|
||||
]), $graphQLPayload);
|
||||
|
||||
$this->assertIsArray($user['body']['data']);
|
||||
$this->assertIsArray($user['body']['data']['usersCreate']);
|
||||
|
||||
$data = $user['body']['data']['usersCreate'];
|
||||
$this->assertArrayHasKey('_id', $data);
|
||||
$this->assertArrayHasKey('registration', $data);
|
||||
$this->assertEquals($variables['name'], $data['name']);
|
||||
$this->assertEquals($variables['email'], $data['email']);
|
||||
$this->assertEquals(true, $data['status']);
|
||||
$this->assertEquals(false, $data['emailVerification']);
|
||||
|
||||
return ['userId' => $user['body']['data']['usersCreate']['_id']];
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testUserCreate
|
||||
*/
|
||||
public function testUserDelete(array $data)
|
||||
{
|
||||
/**
|
||||
* Try to delete a user without the required scope
|
||||
*/
|
||||
$projectId = $this->getProject()['$id'];
|
||||
$key = '';
|
||||
$query = $this->getQuery(self::$DELETE_USER);
|
||||
|
||||
$variables = [
|
||||
'userId' => $data['userId'],
|
||||
];
|
||||
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => $variables
|
||||
];
|
||||
|
||||
$user = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $key
|
||||
], $graphQLPayload);
|
||||
|
||||
$errorMessage = 'User (role: guest) missing scope (users.write)';
|
||||
$this->assertEquals($errorMessage, $user['body']['errors'][0]['message']);
|
||||
$this->assertArrayNotHasKey('data', $user['body']);
|
||||
|
||||
/**
|
||||
* Delete the user with the required scopes
|
||||
*/
|
||||
$key = $this->getNewKey(['users.write']);
|
||||
$user = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $key
|
||||
]), $graphQLPayload);
|
||||
|
||||
$this->assertNull($user['body']['errors']);
|
||||
$this->assertIsArray($user['body']['data']);
|
||||
$this->assertIsArray($user['body']['data']['usersDeleteUser']);
|
||||
$this->assertEquals([], $user['body']['data']['usersDeleteUser']);
|
||||
|
||||
/**
|
||||
* Try to fetch the user and check that its empty
|
||||
*/
|
||||
$query = $this->getQuery(self::$GET_USER);
|
||||
$key = $this->getNewKey(['users.read']);
|
||||
|
||||
$graphQLPayload = [
|
||||
'query' => $query,
|
||||
'variables' => $variables
|
||||
];
|
||||
|
||||
$user = $this->client->call(Client::METHOD_POST, '/graphql', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $key
|
||||
], $graphQLPayload);
|
||||
|
||||
$errorMessage = 'User not found';
|
||||
$this->assertEquals($errorMessage, $user['body']['errors'][0]['message']);
|
||||
$this->assertIsArray($user['body']['data']);
|
||||
$this->assertNull($user['body']['data']['users_get']);
|
||||
}
|
||||
|
||||
|
||||
public function testScopeBasedAuth()
|
||||
{
|
||||
$key = $this->getNewKey(['locale.read']);
|
||||
|
|
Loading…
Reference in a new issue