feat: address review comments
This commit is contained in:
parent
cc7d6ad76c
commit
711ca8801a
3 changed files with 58 additions and 4 deletions
|
@ -882,6 +882,26 @@ App::patch('/v1/projects/:projectId/auth/mock-numbers')
|
|||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
/* Ensure there are no duplicate numbers . Numbers have a structure. Throw an exception if there are duplicate numbers
|
||||
[
|
||||
{
|
||||
"number": "+1234567890",
|
||||
"code": "123456"
|
||||
},
|
||||
{
|
||||
"number": "+1234567891",
|
||||
"code": "123456"
|
||||
}
|
||||
]
|
||||
*/
|
||||
$uniqueNumbers = [];
|
||||
foreach ($numbers as $number) {
|
||||
if (isset($uniqueNumbers[$number['number']])) {
|
||||
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Duplicate numbers are not allowed.');
|
||||
}
|
||||
$uniqueNumbers[$number['number']] = $number['code'];
|
||||
}
|
||||
|
||||
$auths = $project->getAttribute('auths', []);
|
||||
|
||||
$auths['mockNumbers'] = $numbers;
|
||||
|
|
|
@ -47,8 +47,8 @@ class MockNumber extends Validator
|
|||
}
|
||||
|
||||
$otp = new Text(6, 6);
|
||||
if (!$otp->isValid($value['otp'])) {
|
||||
$this->message = 'OTP must be a valid string and exactly 6 characters.';
|
||||
if (!$otp->isValid($value['otp']) || !\ctype_digit($value['otp'])) {
|
||||
$this->message = 'Invalid OTP. Please make sure the OTP is a 6 digit number';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1592,7 +1592,7 @@ class ProjectsConsoleClientTest extends Scope
|
|||
]
|
||||
]);
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
$this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and OTP must be a valid string and exactly 6 characters.', $response['body']['message']);
|
||||
$this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']);
|
||||
|
||||
/** Trying to pass an OTP shorter than 6 characters*/
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([
|
||||
|
@ -1607,7 +1607,22 @@ class ProjectsConsoleClientTest extends Scope
|
|||
]
|
||||
]);
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
$this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and OTP must be a valid string and exactly 6 characters.', $response['body']['message']);
|
||||
$this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']);
|
||||
|
||||
/** Trying to pass an OTP with non numeric characters */
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'numbers' => [
|
||||
[
|
||||
'phone' => '+1655513432',
|
||||
'otp' => '123re2'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
$this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']);
|
||||
|
||||
/** Trying to pass an invalid phone number */
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([
|
||||
|
@ -1639,6 +1654,25 @@ class ProjectsConsoleClientTest extends Scope
|
|||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
$this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.', $response['body']['message']);
|
||||
|
||||
/** Trying to pass duplicate numbers */
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'numbers' => [
|
||||
[
|
||||
'phone' => '+1655513432',
|
||||
'otp' => '123456'
|
||||
],
|
||||
[
|
||||
'phone' => '+1655513432',
|
||||
'otp' => '123456'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
$this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.', $response['body']['message']);
|
||||
|
||||
$numbers = [];
|
||||
for ($i = 0; $i < 11; $i++) {
|
||||
$numbers[] = [
|
||||
|
|
Loading…
Reference in a new issue