mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 17:08:45 +00: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:
commit
98bdcfe04e
2 changed files with 76 additions and 1 deletions
|
|
@ -888,7 +888,7 @@ App::patch('/v1/users/:userId/phone')
|
||||||
try {
|
try {
|
||||||
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
||||||
} catch (Duplicate $th) {
|
} catch (Duplicate $th) {
|
||||||
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
|
throw new Exception(Exception::USER_PHONE_ALREADY_EXISTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
$events->setParam('userId', $user->getId());
|
$events->setParam('userId', $user->getId());
|
||||||
|
|
|
||||||
|
|
@ -926,6 +926,81 @@ trait UsersBase
|
||||||
return $data;
|
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
|
* @depends testGetUser
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue