1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00

Throw exception when any enum element is empty

This commit is contained in:
kodumbeats 2021-10-07 14:30:52 -04:00
parent b3d5ba4123
commit f197699523
2 changed files with 21 additions and 0 deletions

View file

@ -783,6 +783,10 @@ App::post('/v1/database/collections/:collectionId/attributes/enum')
$size = 0;
foreach ($elements as $element) {
$length = \strlen($element);
if ($length === 0) {
throw new Exception('Each enum element must not be empty', 400);
}
$size = ($length > $size) ? $length : $size;
}

View file

@ -568,6 +568,23 @@ trait DatabaseBase
$this->assertEquals($booleanResponse['body']['array'], $attributes[7]['array']);
$this->assertEquals($booleanResponse['body']['default'], $attributes[7]['default']);
/**
* Test for FAILURE
*/
$badEnum = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/enum', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'attributeId' => 'enum',
'elements' => ['yes', 'no', ''],
'required' => false,
'default' => 'maybe',
]);
$this->assertEquals(400, $badEnum['headers']['status-code']);
$this->assertEquals('Each enum element must not be empty', $badEnum['body']['message']);
return $data;
}