1
0
Fork 0
mirror of synced 2024-08-19 20:21:41 +12:00

WIP client test updates

This commit is contained in:
Jake Barnby 2022-05-04 21:19:36 +12:00
parent d94d5d53bf
commit 9d2aad1134
No known key found for this signature in database
GPG key ID: A4674EBC0E404657

View file

@ -18,18 +18,15 @@ class GraphQLClientTest extends Scope
{ {
$projectId = $this->getProject()['$id']; $projectId = $this->getProject()['$id'];
$query = $this->getQuery(self::$CREATE_ACCOUNT); $query = $this->getQuery(self::$CREATE_ACCOUNT);
$time = \time(); $email = 'test' . \rand() . '@test.com';
$variables = [
'email' => "test{$time}@test.com",
'password' => 'password',
];
$graphQLPayload = [ $graphQLPayload = [
'query' => $query, 'query' => $query,
'variables' => \array_merge($variables, [ 'variables' => [
'userId' => 'unique()', 'userId' => 'unique()',
'name' => 'Tester', 'name' => 'Tester',
]) 'email' => $email,
'password' => 'password',
],
]; ];
$account1 = $this->client->call(Client::METHOD_POST, '/graphql', [ $account1 = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json', 'content-type' => 'application/json',
@ -39,15 +36,16 @@ class GraphQLClientTest extends Scope
$this->assertIsArray($account1['body']['data']); $this->assertIsArray($account1['body']['data']);
$account1 = $account1['body']['data']['accountCreate']; $account1 = $account1['body']['data']['accountCreate'];
$this->assertEquals('Tester', $account1['name']); $this->assertEquals('Tester', $account1['name']);
$this->assertEquals($variables['email'], $account1['email']); $this->assertEquals($email, $account1['email']);
/* // Create First Account Session
* Create First Account Session
*/
$query = $this->getQuery(self::$CREATE_ACCOUNT_SESSION); $query = $this->getQuery(self::$CREATE_ACCOUNT_SESSION);
$graphQLPayload = [ $graphQLPayload = [
'query' => $query, 'query' => $query,
'variables' => $variables 'variables' => [
'email' => $email,
'password' => 'password',
]
]; ];
$session1 = $this->client->call(Client::METHOD_POST, '/graphql', [ $session1 = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json', 'content-type' => 'application/json',
@ -56,33 +54,35 @@ class GraphQLClientTest extends Scope
$this->assertIsArray($session1['body']['data']); $this->assertIsArray($session1['body']['data']);
$this->assertIsArray($session1['body']['data']['accountCreateSession']); $this->assertIsArray($session1['body']['data']['accountCreateSession']);
$session1Cookie = $this->client->parseCookie((string)$session1['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']]; $session1Cookie = $this->client->parseCookie((string)$session1['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
/* /*
* Create Second Account * Create Second Account
*/ */
$query = $this->getQuery(self::$CREATE_ACCOUNT); $query = $this->getQuery(self::$CREATE_ACCOUNT);
$time = \time(); $email = 'test' . \rand() . '@test.com';
$variables = [
'email' => "test{$time}@test.com",
'password' => 'password'
];
$graphQLPayload = [ $graphQLPayload = [
'query' => $query, 'query' => $query,
'variables' => $variables 'variables' => [
'userId' => 'unique()',
'email' => $email,
'password' => 'password',
'name' => 'Tester2',
],
]; ];
$account2 = $this->client->call(Client::METHOD_POST, '/graphql', [ $account2 = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $projectId, 'x-appwrite-project' => $projectId,
], $graphQLPayload); ], $graphQLPayload);
$this->assertNull($account2['body']['errors']);
$this->assertIsArray($account2['body']['data']); $this->assertIsArray($account2['body']['data']);
$this->assertIsArray($account2['body']['data']['accountCreate']); $this->assertIsArray($account2['body']['data']['accountCreate']);
$this->assertArrayNotHasKey('errors', $account2['body']);
$account2 = $account2['body']['data']['accountCreate']; $account2 = $account2['body']['data']['accountCreate'];
$this->assertEquals($variables['name'], $account2['name']); $this->assertEquals('Tester2', $account2['name']);
$this->assertEquals($variables['email'], $account2['email']); $this->assertEquals($email, $account2['email']);
/* /*
* Create Second Account Session * Create Second Account Session
@ -90,19 +90,19 @@ class GraphQLClientTest extends Scope
$query = $this->getQuery(self::$CREATE_ACCOUNT_SESSION); $query = $this->getQuery(self::$CREATE_ACCOUNT_SESSION);
$graphQLPayload = [ $graphQLPayload = [
'query' => $query, 'query' => $query,
'variables' => \array_merge($variables, [ 'variables' => [
'userId' => 'unique()', 'email' => $email,
'name' => 'Tester 2', 'password' => 'password',
]) ],
]; ];
$session2 = $this->client->call(Client::METHOD_POST, '/graphql', [ $session2 = $this->client->call(Client::METHOD_POST, '/graphql', [
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $projectId, 'x-appwrite-project' => $projectId,
], $graphQLPayload); ], $graphQLPayload);
$this->assertNull($session2['body']['errors']);
$this->assertIsArray($session2['body']['data']); $this->assertIsArray($session2['body']['data']);
$this->assertIsArray($session2['body']['data']['accountCreateSession']); $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']]; $session2Cookie = $this->client->parseCookie((string)$session2['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
return [ return [
@ -465,7 +465,7 @@ class GraphQLClientTest extends Scope
/* /*
* Create a membership * Create a membership
*/ */
$email = \time() . 'friend@localhost.test'; $email = \rand() . 'friend@localhost.test';
$query = $this->getQuery(self::$CREATE_TEAM_MEMBERSHIP); $query = $this->getQuery(self::$CREATE_TEAM_MEMBERSHIP);
$createMembershipVariable = [ $createMembershipVariable = [
'teamId' => $team['id'], 'teamId' => $team['id'],