1
0
Fork 0
mirror of synced 2024-06-03 03:14:50 +12:00

Merge pull request #4292 from Akshay-Rana-Gujjar/fix-3810-incorrect-error-when-updating-phone-to-existing-number

fixed: wrong error message show on adding duplicate number to a user
This commit is contained in:
Christy Jacob 2022-10-14 12:02:39 +04:00 committed by GitHub
commit 98bdcfe04e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 1 deletions

View file

@ -888,7 +888,7 @@ App::patch('/v1/users/:userId/phone')
try {
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
} catch (Duplicate $th) {
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
throw new Exception(Exception::USER_PHONE_ALREADY_EXISTS);
}
$events->setParam('userId', $user->getId());

View file

@ -926,6 +926,81 @@ trait UsersBase
return $data;
}
/**
* @depends testGetUser
*/
public function testUpdateUserNumber(array $data): array
{
/**
* Test for SUCCESS
*/
$updatedNumber = "+910000000000"; //dummy number
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/phone', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'number' => $updatedNumber,
]);
$this->assertEquals($user['headers']['status-code'], 200);
$this->assertEquals($user['body']['phone'], $updatedNumber);
$user = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals($user['headers']['status-code'], 200);
$this->assertEquals($user['body']['phone'], $updatedNumber);
/**
* Test for FAILURE
*/
$errorType = "user_phone_already_exists";
$user1Id = "user1";
$statusCodeForUserPhoneAlredyExists = 409;
// adding same number ($updatedNumber) to different user i.e user1
$response = $this->client->call(Client::METHOD_PATCH, '/users/' . $user1Id . '/phone', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'number' => $updatedNumber,
]);
$this->assertEquals($response['headers']['status-code'], $statusCodeForUserPhoneAlredyExists);
$this->assertNotEmpty($response['body']);
$this->assertEquals($response['body']['type'], $errorType);
return $data;
}
/**
* @depends testUpdateUserNumber
*/
public function testUpdateUserNumberSearch($data): void
{
$id = $data['userId'] ?? '';
$newNumber = "+910000000000"; //dummy number
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/users', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'search' => $newNumber,
]);
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertNotEmpty($response['body']);
$this->assertNotEmpty($response['body']['users']);
$this->assertCount(1, $response['body']['users']);
$this->assertEquals($response['body']['users'][0]['$id'], $id);
$this->assertEquals($response['body']['users'][0]['phone'], $newNumber);
}
/**
* @depends testGetUser