2022-06-30 21:26:46 +12:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\GraphQL;
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\SideServer;
|
2023-01-16 22:25:40 +13:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2023-08-24 08:23:52 +12:00
|
|
|
use Utopia\Database\Query;
|
2022-06-30 21:26:46 +12:00
|
|
|
|
2022-09-22 20:29:42 +12:00
|
|
|
class UsersTest extends Scope
|
2022-06-30 21:26:46 +12:00
|
|
|
{
|
|
|
|
use ProjectCustom;
|
|
|
|
use SideServer;
|
2022-09-22 20:29:42 +12:00
|
|
|
use Base;
|
2022-06-30 21:26:46 +12:00
|
|
|
|
|
|
|
public function testCreateUser(): array
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$CREATE_USER);
|
|
|
|
$email = 'users.service@example.com';
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
2022-09-22 13:53:41 +12:00
|
|
|
'userId' => ID::unique(),
|
2022-06-30 21:26:46 +12:00
|
|
|
'email' => $email,
|
|
|
|
'password' => 'password',
|
|
|
|
'name' => 'Project User',
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
|
|
|
|
$user = $user['body']['data']['usersCreate'];
|
|
|
|
$this->assertEquals('Project User', $user['name']);
|
|
|
|
$this->assertEquals($email, $user['email']);
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
2023-10-18 06:59:10 +13:00
|
|
|
/**
|
|
|
|
* @depends testCreateUser
|
|
|
|
*/
|
|
|
|
public function testCreateUserTarget(array $user)
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_MAILGUN_PROVIDER);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'providerId' => ID::unique(),
|
|
|
|
'name' => 'Mailgun1',
|
|
|
|
'apiKey' => 'api-key',
|
|
|
|
'domain' => 'domain',
|
2023-12-06 07:24:55 +13:00
|
|
|
'fromName' => 'sender name',
|
|
|
|
'fromEmail' => 'from@domain.com',
|
2023-10-18 06:59:10 +13:00
|
|
|
'isEuRegion' => false,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$provider = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
$providerId = $provider['body']['data']['messagingCreateMailgunProvider']['_id'];
|
|
|
|
|
|
|
|
$this->assertEquals(200, $provider['headers']['status-code']);
|
|
|
|
|
|
|
|
$query = $this->getQuery(self::$CREATE_USER_TARGET);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'targetId' => ID::unique(),
|
|
|
|
'userId' => $user['_id'],
|
2023-11-15 01:44:07 +13:00
|
|
|
'providerType' => 'email',
|
2023-10-18 06:59:10 +13:00
|
|
|
'providerId' => $providerId,
|
2023-11-21 22:49:19 +13:00
|
|
|
'identifier' => 'random-email@mail.org',
|
2023-10-18 06:59:10 +13:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$target = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $target['headers']['status-code']);
|
2023-11-21 22:49:19 +13:00
|
|
|
$this->assertEquals('random-email@mail.org', $target['body']['data']['usersCreateTarget']['identifier']);
|
2023-10-18 06:59:10 +13:00
|
|
|
|
|
|
|
return $target['body']['data']['usersCreateTarget'];
|
|
|
|
}
|
|
|
|
|
2022-06-30 21:26:46 +12:00
|
|
|
public function testGetUsers()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$GET_USERS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
2022-09-22 18:54:58 +12:00
|
|
|
'queries' => [
|
2023-12-20 23:55:09 +13:00
|
|
|
Query::limit(100)->toString(),
|
|
|
|
Query::offset(0)->toString(),
|
2022-09-22 18:54:58 +12:00
|
|
|
],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$users = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($users['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $users['body']);
|
|
|
|
$this->assertIsArray($users['body']['data']['usersList']);
|
|
|
|
$this->assertGreaterThan(0, \count($users['body']['data']['usersList']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUser()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$GET_USER);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersGet']);
|
2022-12-08 16:08:57 +13:00
|
|
|
$this->assertEquals($this->getUser()['$id'], $user['body']['data']['usersGet']['_id']);
|
2022-06-30 21:26:46 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserPreferences()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$GET_USER_PREFERENCES);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersGetPrefs']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserSessions()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$GET_USER_SESSIONS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
2022-09-22 13:57:31 +12:00
|
|
|
$this->assertIsArray($user['body']['data']['usersListSessions']);
|
2022-06-30 21:26:46 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserMemberships()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$GET_USER_MEMBERSHIPS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
2022-09-22 18:54:58 +12:00
|
|
|
$this->assertIsArray($user['body']['data']['usersListMemberships']);
|
2022-06-30 21:26:46 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserLogs()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$GET_USER_LOGS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
2022-09-21 19:03:28 +12:00
|
|
|
$this->assertIsArray($user['body']['data']['usersListLogs']);
|
2022-06-30 21:26:46 +12:00
|
|
|
}
|
|
|
|
|
2023-10-18 06:59:10 +13:00
|
|
|
/**
|
|
|
|
* @depends testCreateUserTarget
|
|
|
|
*/
|
|
|
|
public function testListUserTargets(array $target)
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$LIST_USER_TARGETS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $target['userId'],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$targets = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $targets['headers']['status-code']);
|
|
|
|
$this->assertIsArray($targets['body']['data']['usersListTargets']);
|
2023-11-29 02:12:34 +13:00
|
|
|
$this->assertCount(2, $targets['body']['data']['usersListTargets']['targets']);
|
2023-10-18 06:59:10 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateUserTarget
|
|
|
|
*/
|
|
|
|
public function testGetUserTarget(array $target)
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$GET_USER_TARGET);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $target['userId'],
|
|
|
|
'targetId' => $target['_id'],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$target = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $target['headers']['status-code']);
|
2023-11-21 22:49:19 +13:00
|
|
|
$this->assertEquals('random-email@mail.org', $target['body']['data']['usersGetTarget']['identifier']);
|
2023-10-18 06:59:10 +13:00
|
|
|
}
|
|
|
|
|
2022-06-30 21:26:46 +12:00
|
|
|
public function testUpdateUserStatus()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_STATUS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
|
|
|
'status' => true,
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersUpdateStatus']);
|
2022-12-08 16:08:57 +13:00
|
|
|
$this->assertEquals($this->getUser()['$id'], $user['body']['data']['usersUpdateStatus']['_id']);
|
2022-06-30 21:26:46 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateUserEmailVerification()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_EMAIL_VERIFICATION);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
|
|
|
'emailVerification' => true,
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
2022-07-01 12:02:59 +12:00
|
|
|
$this->assertIsArray($user['body']['data']['usersUpdateEmailVerification']);
|
2022-06-30 21:26:46 +12:00
|
|
|
}
|
|
|
|
|
2022-07-01 12:02:59 +12:00
|
|
|
public function testUpdateUserPhoneVerification()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_PHONE_VERIFICATION);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
|
|
|
'phoneVerification' => true,
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-07-01 12:02:59 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersUpdatePhoneVerification']);
|
2022-12-08 16:08:57 +13:00
|
|
|
$this->assertEquals($this->getUser()['$id'], $user['body']['data']['usersUpdatePhoneVerification']['_id']);
|
2022-07-01 12:02:59 +12:00
|
|
|
}
|
2022-06-30 21:26:46 +12:00
|
|
|
|
|
|
|
public function testUpdateUserName()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_NAME);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
|
|
|
'name' => 'Updated Name',
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersUpdateName']);
|
|
|
|
$this->assertEquals('Updated Name', $user['body']['data']['usersUpdateName']['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateUserEmail()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_EMAIL);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
'email' => 'newemail@appwrite.io'
|
2022-06-30 21:26:46 +12:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersUpdateEmail']);
|
|
|
|
$this->assertEquals('newemail@appwrite.io', $user['body']['data']['usersUpdateEmail']['email']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateUserPassword()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_PASSWORD);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
'password' => 'newpassword'
|
2022-06-30 21:26:46 +12:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersUpdatePassword']);
|
|
|
|
}
|
|
|
|
|
2022-07-06 15:51:49 +12:00
|
|
|
public function testUpdateUserPhone()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_PHONE);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
'number' => '+123456789'
|
2022-07-06 15:51:49 +12:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersUpdatePhone']);
|
2022-09-22 18:54:58 +12:00
|
|
|
$this->assertEquals('+123456789', $user['body']['data']['usersUpdatePhone']['phone']);
|
2022-07-06 15:51:49 +12:00
|
|
|
}
|
2022-06-30 21:26:46 +12:00
|
|
|
|
|
|
|
public function testUpdateUserPrefs()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_PREFS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
|
|
|
'prefs' => [
|
2023-08-24 08:23:52 +12:00
|
|
|
'key' => 'value'
|
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertIsArray($user['body']['data']);
|
|
|
|
$this->assertArrayNotHasKey('errors', $user['body']);
|
|
|
|
$this->assertIsArray($user['body']['data']['usersUpdatePrefs']);
|
|
|
|
$this->assertEquals('{"key":"value"}', $user['body']['data']['usersUpdatePrefs']['data']);
|
|
|
|
}
|
|
|
|
|
2023-10-18 06:59:10 +13:00
|
|
|
/**
|
|
|
|
* @depends testCreateUserTarget
|
|
|
|
*/
|
|
|
|
public function testUpdateUserTarget(array $target)
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$UPDATE_USER_TARGET);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $target['userId'],
|
|
|
|
'targetId' => $target['_id'],
|
2023-11-21 22:49:19 +13:00
|
|
|
'identifier' => 'random-email1@mail.org',
|
2023-10-18 06:59:10 +13:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$target = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $target['headers']['status-code']);
|
2023-11-21 22:49:19 +13:00
|
|
|
$this->assertEquals('random-email1@mail.org', $target['body']['data']['usersUpdateTarget']['identifier']);
|
2023-10-18 06:59:10 +13:00
|
|
|
}
|
|
|
|
|
2022-06-30 21:26:46 +12:00
|
|
|
public function testDeleteUserSessions()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$DELETE_USER_SESSIONS);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
2022-07-18 21:38:13 +12:00
|
|
|
$this->assertIsNotArray($user['body']);
|
2022-06-30 21:26:46 +12:00
|
|
|
$this->assertEquals(204, $user['headers']['status-code']);
|
|
|
|
|
|
|
|
unset(self::$user[$this->getProject()['$id']]);
|
|
|
|
$this->getUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteUserSession()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$DELETE_USER_SESSION);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
|
|
|
'sessionId' => $this->getUser()['sessionId'],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
2022-07-18 21:38:13 +12:00
|
|
|
$this->assertIsNotArray($user['body']);
|
2022-06-30 21:26:46 +12:00
|
|
|
$this->assertEquals(204, $user['headers']['status-code']);
|
|
|
|
|
|
|
|
unset(self::$user[$this->getProject()['$id']]);
|
|
|
|
$this->getUser();
|
|
|
|
}
|
|
|
|
|
2023-10-18 06:59:10 +13:00
|
|
|
/**
|
|
|
|
* @depends testCreateUserTarget
|
|
|
|
*/
|
|
|
|
public function testDeleteUserTarget(array $target)
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$DELETE_USER_TARGET);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $target['userId'],
|
|
|
|
'targetId' => $target['_id'],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$target = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $target['headers']['status-code']);
|
|
|
|
}
|
|
|
|
|
2022-06-30 21:26:46 +12:00
|
|
|
public function testDeleteUser()
|
|
|
|
{
|
|
|
|
$projectId = $this->getProject()['$id'];
|
|
|
|
$query = $this->getQuery(self::$DELETE_USER);
|
|
|
|
$graphQLPayload = [
|
|
|
|
'query' => $query,
|
|
|
|
'variables' => [
|
|
|
|
'userId' => $this->getUser()['$id'],
|
2023-08-24 08:23:52 +12:00
|
|
|
]
|
2022-06-30 21:26:46 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), $graphQLPayload);
|
|
|
|
|
2022-07-18 21:38:13 +12:00
|
|
|
$this->assertIsNotArray($user['body']);
|
2022-06-30 21:26:46 +12:00
|
|
|
$this->assertEquals(204, $user['headers']['status-code']);
|
|
|
|
}
|
2022-07-12 09:52:00 +12:00
|
|
|
}
|