diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 9eedbb986..c4ff448ce 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1103,7 +1103,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string ->param('key', '', new Key(), 'Attribute Key.') ->param('size', null, new Range(1, APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH, Range::TYPE_INTEGER), 'Attribute size for text attributes, in number of characters.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Text(0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true) + ->param('default', null, new Text(0, 0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true) ->param('array', false, new Boolean(), 'Is attribute an array?', true) ->inject('response') ->inject('dbForProject') @@ -1112,7 +1112,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string ->action(function (string $databaseId, string $collectionId, string $key, ?int $size, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) { // Ensure attribute default is within required size - $validator = new Text($size); + $validator = new Text($size, 0); if (!is_null($default) && !$validator->isValid($default)) { throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, $validator->getDescription()); } @@ -1777,7 +1777,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') - ->param('default', null, new Nullable(new Text(0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') + ->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') ->inject('response') ->inject('dbForProject') ->inject('events') diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 0648db849..c511bf990 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -157,6 +157,7 @@ trait DatabasesBase public function testCreateAttributes(array $data): array { $databaseId = $data['databaseId']; + $title = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -167,6 +168,17 @@ trait DatabasesBase 'required' => true, ]); + $description = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'description', + 'size' => 256, + 'required' => false, + 'default' => '', + ]); + $releaseYear = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/integer', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -226,6 +238,13 @@ trait DatabasesBase $this->assertEquals($title['body']['size'], 256); $this->assertEquals($title['body']['required'], true); + $this->assertEquals(202, $description['headers']['status-code']); + $this->assertEquals($description['body']['key'], 'description'); + $this->assertEquals($description['body']['type'], 'string'); + $this->assertEquals($description['body']['size'], 256); + $this->assertEquals($description['body']['required'], false); + $this->assertEquals($description['body']['default'], ''); + $this->assertEquals(202, $releaseYear['headers']['status-code']); $this->assertEquals($releaseYear['body']['key'], 'releaseYear'); $this->assertEquals($releaseYear['body']['type'], 'integer'); @@ -266,13 +285,14 @@ trait DatabasesBase ]), []); $this->assertIsArray($movies['body']['attributes']); - $this->assertCount(6, $movies['body']['attributes']); + $this->assertCount(7, $movies['body']['attributes']); $this->assertEquals($movies['body']['attributes'][0]['key'], $title['body']['key']); - $this->assertEquals($movies['body']['attributes'][1]['key'], $releaseYear['body']['key']); - $this->assertEquals($movies['body']['attributes'][2]['key'], $duration['body']['key']); - $this->assertEquals($movies['body']['attributes'][3]['key'], $actors['body']['key']); - $this->assertEquals($movies['body']['attributes'][4]['key'], $datetime['body']['key']); - $this->assertEquals($movies['body']['attributes'][5]['key'], $relationship['body']['key']); + $this->assertEquals($movies['body']['attributes'][1]['key'], $description['body']['key']); + $this->assertEquals($movies['body']['attributes'][2]['key'], $releaseYear['body']['key']); + $this->assertEquals($movies['body']['attributes'][3]['key'], $duration['body']['key']); + $this->assertEquals($movies['body']['attributes'][4]['key'], $actors['body']['key']); + $this->assertEquals($movies['body']['attributes'][5]['key'], $datetime['body']['key']); + $this->assertEquals($movies['body']['attributes'][6]['key'], $relationship['body']['key']); return $data; }