Added more tests to users API
This commit is contained in:
parent
1131fb57dc
commit
66b043b980
|
@ -398,26 +398,19 @@ $utopia->patch('/v1/users/:userId/prefs')
|
||||||
throw new Exception('Failed saving user to DB', 500);
|
throw new Exception('Failed saving user to DB', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oauthKeys = [];
|
$prefs = $user->getAttribute('prefs', '');
|
||||||
|
|
||||||
foreach ($providers as $key => $provider) {
|
if (empty($prefs)) {
|
||||||
if (!$provider['enabled']) {
|
$prefs = '[]';
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$oauthKeys[] = 'oauth'.ucfirst($key);
|
|
||||||
$oauthKeys[] = 'oauth'.ucfirst($key).'AccessToken';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$response
|
try {
|
||||||
->json(array_merge($user->getArrayCopy(array_merge([
|
$prefs = json_decode($prefs, true);
|
||||||
'$uid',
|
} catch (\Exception $error) {
|
||||||
'status',
|
throw new Exception('Failed to parse prefs', 500);
|
||||||
'email',
|
}
|
||||||
'registration',
|
|
||||||
'confirm',
|
$response->json($prefs);
|
||||||
'name',
|
|
||||||
], $oauthKeys)), ['roles' => []]));
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,34 @@ class ProjectUsersTest extends BaseProjects
|
||||||
$this->assertEquals($logs['headers']['status-code'], 200);
|
$this->assertEquals($logs['headers']['status-code'], 200);
|
||||||
$this->assertIsArray($logs['body']);
|
$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;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,4 +130,30 @@ class ProjectUsersTest extends BaseProjects
|
||||||
|
|
||||||
return $data;
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue