1
0
Fork 0
mirror of synced 2024-07-03 21:50:34 +12:00

chore: refactor tests and param positioning changes

This commit is contained in:
Bishwajeet Parhi 2023-06-22 09:59:09 +05:30
parent 09162e8880
commit ee30a3e9f4
2 changed files with 8 additions and 98 deletions

View file

@ -1103,14 +1103,14 @@ 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('encrypt', false, new Boolean(), 'Encrypt attribute? Encrypting an attribute means that the attribute can not be queried.', 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)
->param('encrypt', false, new Boolean(), 'Encrypt attribute? Encrypting an attribute means that the attribute can not be queried.', true)
->inject('response')
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?int $size, bool $required, bool $encrypt, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?int $size, bool $required, ?string $default, bool $array, bool $encrypt, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
// Ensure attribute default is within required size
$validator = new Text($size, 0);
@ -1175,7 +1175,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/email'
'required' => $required,
'default' => $default,
'array' => $array,
'format' => APP_DATABASE_ATTRIBUTE_EMAIL
'format' => APP_DATABASE_ATTRIBUTE_EMAIL,
]), $response, $dbForProject, $database, $events);
$response

View file

@ -596,7 +596,7 @@ class DatabasesCustomServerTest extends Scope
/**
* @depends testListCollections
*/
public function testCreateEncryptedAttribute(array $data): array
public function testCreateEncryptedAttribute(array $data): void
{
$databaseId = $data['databaseId'];
@ -652,26 +652,6 @@ class DatabasesCustomServerTest extends Scope
'encrypt' => true,
]);
$age = $this->client->call(Client::METHOD_POST, $attributesPath . '/integer', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'key' => 'age',
'min' => 0,
'max' => 120,
'required' => false,
]);
$alias = $this->client->call(Client::METHOD_POST, $attributesPath . '/string', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'key' => 'alias',
'size' => 256,
'required' => false,
]);
/**
* Check Status of every Attribute
@ -684,16 +664,8 @@ class DatabasesCustomServerTest extends Scope
$this->assertEquals('lastName', $lastName['body']['key']);
$this->assertEquals('string', $lastName['body']['type']);
$this->assertEquals(202, $alias['headers']['status-code']);
$this->assertEquals('alias', $alias['body']['key']);
$this->assertEquals('string', $alias['body']['type']);
$this->assertEquals(202, $age['headers']['status-code']);
$this->assertEquals('age', $age['body']['key']);
$this->assertEquals('integer', $age['body']['type']);
// Wait for database worker to finish creating attributes
sleep(5);
sleep(2);
// Creating document to ensure cache is purged on schema change
$document = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $actors['body']['$id'] . '/documents', array_merge([
@ -705,8 +677,6 @@ class DatabasesCustomServerTest extends Scope
'data' => [
'firstName' => 'Jonah',
'lastName' => 'Jameson',
'age' => 25,
'alias' => 'JJ'
],
'permissions' => [
Permission::read(Role::any()),
@ -715,50 +685,6 @@ class DatabasesCustomServerTest extends Scope
],
]);
$index = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $actors['body']['$id'] . '/indexes', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'key' => 'key_lastName',
'type' => 'key',
'attributes' => [
'lastName',
],
]);
// Wait for database worker to finish creating index
sleep(2);
$collection = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $actors['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), []);
$this->assertEquals(200, $collection['headers']['status-code']);
$this->assertIsArray($collection['body']['attributes']);
$this->assertCount(4, $collection['body']['attributes']);
$this->assertEquals($collection['body']['attributes'][0]['key'], $firstName['body']['key']);
$this->assertEquals($collection['body']['attributes'][1]['key'], $lastName['body']['key']);
$this->assertEquals($collection['body']['attributes'][2]['key'], $age['body']['key']);
$this->assertEquals($collection['body']['attributes'][3]['key'], $alias['body']['key']);
$this->assertCount(1, $collection['body']['indexes']);
$this->assertEquals($collection['body']['indexes'][0]['key'], $index['body']['key']);
$unneededId = $alias['body']['key'];
// Delete attribute
$attribute = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $actors ['body']['$id'] . '/attributes/' . $unneededId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]));
$this->assertEquals(204, $attribute['headers']['status-code']);
sleep(2);
// Check document to ensure cache is purged on schema change
$document = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $actors['body']['$id'] . '/documents/' . $document['body']['$id'], array_merge([
'content-type' => 'application/json',
@ -766,25 +692,9 @@ class DatabasesCustomServerTest extends Scope
'x-appwrite-key' => $this->getProject()['apiKey']
]));
$this->assertNotContains($unneededId, $document['body']);
$collection = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $actors['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), []);
$this->assertEquals(200, $collection['headers']['status-code']);
$this->assertIsArray($collection['body']['attributes']);
$this->assertCount(3, $collection['body']['attributes']);
$this->assertEquals($collection['body']['attributes'][0]['key'], $firstName['body']['key']);
$this->assertEquals($collection['body']['attributes'][1]['key'], $lastName['body']['key']);
return [
'collectionId' => $actors['body']['$id'],
'key' => $index['body']['key'],
'databaseId' => $databaseId
];
$this->assertEquals(200, $document['headers']['status-code']);
$this->assertEquals('Jonah', $document['body']['firstName']);
$this->assertEquals('Jameson', $document['body']['lastName']);
}
public function testDeleteAttribute(): array