1
0
Fork 0
mirror of synced 2024-06-25 17:50:38 +12:00

Added more tests to users API

This commit is contained in:
eldadfux 2019-10-21 09:43:12 +03:00
parent 1131fb57dc
commit 66b043b980
2 changed files with 64 additions and 17 deletions

View file

@ -398,26 +398,19 @@ $utopia->patch('/v1/users/:userId/prefs')
throw new Exception('Failed saving user to DB', 500);
}
$oauthKeys = [];
$prefs = $user->getAttribute('prefs', '');
foreach ($providers as $key => $provider) {
if (!$provider['enabled']) {
continue;
}
$oauthKeys[] = 'oauth'.ucfirst($key);
$oauthKeys[] = 'oauth'.ucfirst($key).'AccessToken';
if (empty($prefs)) {
$prefs = '[]';
}
$response
->json(array_merge($user->getArrayCopy(array_merge([
'$uid',
'status',
'email',
'registration',
'confirm',
'name',
], $oauthKeys)), ['roles' => []]));
try {
$prefs = json_decode($prefs, true);
} catch (\Exception $error) {
throw new Exception('Failed to parse prefs', 500);
}
$response->json($prefs);
}
);

View file

@ -72,6 +72,34 @@ class ProjectUsersTest extends BaseProjects
$this->assertEquals($logs['headers']['status-code'], 200);
$this->assertIsArray($logs['body']);
$users = $this->client->call(Client::METHOD_GET, '/users', [
'content-type' => 'application/json',
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
]);
$this->assertEquals($users['headers']['status-code'], 200);
$this->assertIsArray($users['body']);
$this->assertIsArray($users['body']['users']);
$this->assertIsInt($users['body']['sum']);
$this->assertGreaterThan(0, $users['body']['sum']);
$users = $this->client->call(Client::METHOD_GET, '/users', [
'content-type' => 'application/json',
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'search' => 'demo'
]);
$this->assertEquals($users['headers']['status-code'], 200);
$this->assertIsArray($users['body']);
$this->assertIsArray($users['body']['users']);
$this->assertIsInt($users['body']['sum']);
$this->assertEquals(1, $users['body']['sum']);
$this->assertGreaterThan(0, $users['body']['sum']);
$this->assertCount(1, $users['body']['users']);
return $data;
}
@ -102,4 +130,30 @@ class ProjectUsersTest extends BaseProjects
return $data;
}
/**
* @depends testUserReadSuccess
*/
public function testUserUpdatePrefsSuccess($data)
{
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', [
'content-type' => 'application/json',
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'prefs' => [
'key1' => 'value1',
'key2' => 'value2',
],
]);
$this->assertEquals($user['headers']['status-code'], 200);
$this->assertEquals($user['body']['key1'], 'value1');
$this->assertEquals($user['body']['key2'], 'value2');
return $data;
}
// TODO add test for session delete
// TODO add test for all sessions delete
}