Fix tests for create/delete collection
This commit is contained in:
parent
8aecf3cf6a
commit
1885a9632d
|
@ -24,6 +24,8 @@ use Utopia\Database\Document as Document2;
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
use Utopia\Database\Validator\Authorization as Authorization2;
|
use Utopia\Database\Validator\Authorization as Authorization2;
|
||||||
|
|
||||||
|
use function Amp\Promise\wait;
|
||||||
|
|
||||||
App::post('/v1/database/collections')
|
App::post('/v1/database/collections')
|
||||||
->desc('Create Collection')
|
->desc('Create Collection')
|
||||||
->groups(['api', 'database'])
|
->groups(['api', 'database'])
|
||||||
|
@ -98,11 +100,11 @@ App::get('/v1/database/collections/:collectionId')
|
||||||
->label('sdk.response.model', Response::MODEL_COLLECTION)
|
->label('sdk.response.model', Response::MODEL_COLLECTION)
|
||||||
->param('collectionId', '', new UID(), 'Collection unique ID.')
|
->param('collectionId', '', new UID(), 'Collection unique ID.')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('dbForExternal')
|
||||||
->action(function ($collectionId, $response, $dbForExternal) {
|
->action(function ($collectionId, $response, $dbForExternal) {
|
||||||
/** @var Appwrite\Utopia\Response $response */
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
/** @var Utopia\Database\Database $dbForExternal */
|
/** @var Utopia\Database\Database $dbForExternal */
|
||||||
|
|
||||||
$collection = $dbForExternal->getCollection($collectionId);
|
$collection = $dbForExternal->getCollection($collectionId);
|
||||||
|
|
||||||
if ($collection->isEmpty()) {
|
if ($collection->isEmpty()) {
|
||||||
|
@ -257,10 +259,10 @@ App::post('/v1/database/collections/:collectionId/attributes')
|
||||||
// TODO@kodumbeats add units to description
|
// TODO@kodumbeats add units to description
|
||||||
->param('size', null, new Numeric(), 'Attribute size.')
|
->param('size', null, new Numeric(), 'Attribute size.')
|
||||||
->param('required', null, new Boolean(), 'Is attribute required?')
|
->param('required', null, new Boolean(), 'Is attribute required?')
|
||||||
->param('signed', null, new Boolean(), 'Is attribute signed?')
|
->param('signed', true, new Boolean(), 'Is attribute signed?', true)
|
||||||
->param('array', null, new Boolean(), 'Is attribute an array?')
|
->param('array', false, new Boolean(), 'Is attribute an array?', true)
|
||||||
// TODO@kodumbeats "We should have here a whitelist of allowed values. We should add a link to a reference in the future documentation. We might be able to hide this option from the public API for now."
|
// TODO@kodumbeats "We should have here a whitelist of allowed values. We should add a link to a reference in the future documentation. We might be able to hide this option from the public API for now."
|
||||||
->param('filters', [], new ArrayList(new Text(256)), 'Array of filters.')
|
->param('filters', [], new ArrayList(new Text(256)), 'Array of filters.', true)
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('dbForExternal')
|
->inject('dbForExternal')
|
||||||
->inject('audits')
|
->inject('audits')
|
||||||
|
@ -597,7 +599,7 @@ App::delete('/v1/database/collections/:collectionId/indexes/:indexId')
|
||||||
|
|
||||||
$collection = $dbForExternal->getCollection($collectionId);
|
$collection = $dbForExternal->getCollection($collectionId);
|
||||||
|
|
||||||
if (empty($collection)) {
|
if ($collection->isEmpty()) {
|
||||||
throw new Exception('Collection not found', 404);
|
throw new Exception('Collection not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,7 +679,7 @@ App::post('/v1/database/collections/:collectionId/documents')
|
||||||
|
|
||||||
$collection = $dbForExternal->getCollection($collectionId);
|
$collection = $dbForExternal->getCollection($collectionId);
|
||||||
|
|
||||||
if (empty($collection)) {
|
if ($collection->isEmpty()) {
|
||||||
throw new Exception('Collection not found', 404);
|
throw new Exception('Collection not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,7 +795,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId')
|
||||||
|
|
||||||
$collection = $dbForExternal->getCollection($collectionId);
|
$collection = $dbForExternal->getCollection($collectionId);
|
||||||
|
|
||||||
if (empty($collection)) {
|
if ($collection->isEmpty()) {
|
||||||
throw new Exception('Collection not found', 404);
|
throw new Exception('Collection not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,7 +905,7 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||||
|
|
||||||
$collection = $dbForExternal->getCollection($collectionId);
|
$collection = $dbForExternal->getCollection($collectionId);
|
||||||
|
|
||||||
if (empty($collection)) {
|
if ($collection->isEmpty()) {
|
||||||
throw new Exception('Collection not found', 404);
|
throw new Exception('Collection not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,8 @@ class Response extends SwooleResponse
|
||||||
// Entities
|
// Entities
|
||||||
->setModel(new Permissions())
|
->setModel(new Permissions())
|
||||||
->setModel(new Collection())
|
->setModel(new Collection())
|
||||||
|
->setModel(new Attribute())
|
||||||
|
->setModel(new Index())
|
||||||
->setModel(new ModelDocument())
|
->setModel(new ModelDocument())
|
||||||
->setModel(new Rule())
|
->setModel(new Rule())
|
||||||
->setModel(new Log())
|
->setModel(new Log())
|
||||||
|
|
|
@ -25,36 +25,39 @@ class DatabaseCustomServerTest extends Scope
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||||
]), [
|
]), [
|
||||||
'name' => 'Actors',
|
'id' => 'Actors',
|
||||||
'read' => ['*'],
|
|
||||||
'write' => ['role:member', 'role:admin'],
|
|
||||||
'rules' => [
|
|
||||||
[
|
|
||||||
'label' => 'First Name',
|
|
||||||
'key' => 'firstName',
|
|
||||||
'type' => 'text',
|
|
||||||
'default' => '',
|
|
||||||
'required' => true,
|
|
||||||
'array' => false
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'label' => 'Last Name',
|
|
||||||
'key' => 'lastName',
|
|
||||||
'type' => 'text',
|
|
||||||
'default' => '',
|
|
||||||
'required' => true,
|
|
||||||
'array' => false
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals($actors['headers']['status-code'], 201);
|
$this->assertEquals($actors['headers']['status-code'], 201);
|
||||||
$this->assertEquals($actors['body']['name'], 'Actors');
|
$this->assertEquals($actors['body']['name'], 'Actors');
|
||||||
$this->assertIsArray($actors['body']['$permissions']);
|
|
||||||
$this->assertIsArray($actors['body']['$permissions']['read']);
|
$firstName = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/attributes', array_merge([
|
||||||
$this->assertIsArray($actors['body']['$permissions']['write']);
|
'content-type' => 'application/json',
|
||||||
$this->assertCount(1, $actors['body']['$permissions']['read']);
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
$this->assertCount(2, $actors['body']['$permissions']['write']);
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||||
|
]), [
|
||||||
|
'id' => 'firstName',
|
||||||
|
'type' => 'string',
|
||||||
|
'size' => 256,
|
||||||
|
'required' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$lastName = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/attributes', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||||
|
]), [
|
||||||
|
'id' => 'lastName',
|
||||||
|
'type' => 'string',
|
||||||
|
'size' => 256,
|
||||||
|
'required' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$collection = $this->client->call(Client::METHOD_GET, '/database/collections/' . $actors['body']['$id'], array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||||
|
]), []);
|
||||||
|
|
||||||
// Add Documents to the collection
|
// Add Documents to the collection
|
||||||
$document1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/documents', array_merge([
|
$document1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/documents', array_merge([
|
||||||
|
@ -80,24 +83,22 @@ class DatabaseCustomServerTest extends Scope
|
||||||
'read' => ['user:'.$this->getUser()['$id']],
|
'read' => ['user:'.$this->getUser()['$id']],
|
||||||
'write' => ['user:'.$this->getUser()['$id']],
|
'write' => ['user:'.$this->getUser()['$id']],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals($document1['headers']['status-code'], 201);
|
$this->assertEquals($document1['headers']['status-code'], 201);
|
||||||
$this->assertEquals($document1['body']['$collection'], $actors['body']['$id']);
|
$this->assertEquals($document1['body']['$collection'], $actors['body']['$id']);
|
||||||
$this->assertIsArray($document1['body']['$permissions']);
|
$this->assertIsArray($document1['body']['$read']);
|
||||||
$this->assertIsArray($document1['body']['$permissions']['read']);
|
$this->assertIsArray($document1['body']['$write']);
|
||||||
$this->assertIsArray($document1['body']['$permissions']['write']);
|
$this->assertCount(1, $document1['body']['$read']);
|
||||||
$this->assertCount(1, $document1['body']['$permissions']['read']);
|
$this->assertCount(1, $document1['body']['$write']);
|
||||||
$this->assertCount(1, $document1['body']['$permissions']['write']);
|
|
||||||
$this->assertEquals($document1['body']['firstName'], 'Tom');
|
$this->assertEquals($document1['body']['firstName'], 'Tom');
|
||||||
$this->assertEquals($document1['body']['lastName'], 'Holland');
|
$this->assertEquals($document1['body']['lastName'], 'Holland');
|
||||||
|
|
||||||
$this->assertEquals($document2['headers']['status-code'], 201);
|
$this->assertEquals($document2['headers']['status-code'], 201);
|
||||||
$this->assertEquals($document2['body']['$collection'], $actors['body']['$id']);
|
$this->assertEquals($document2['body']['$collection'], $actors['body']['$id']);
|
||||||
$this->assertIsArray($document2['body']['$permissions']);
|
$this->assertIsArray($document2['body']['$read']);
|
||||||
$this->assertIsArray($document2['body']['$permissions']['read']);
|
$this->assertIsArray($document2['body']['$write']);
|
||||||
$this->assertIsArray($document2['body']['$permissions']['write']);
|
$this->assertCount(1, $document2['body']['$read']);
|
||||||
$this->assertCount(1, $document2['body']['$permissions']['read']);
|
$this->assertCount(1, $document2['body']['$write']);
|
||||||
$this->assertCount(1, $document2['body']['$permissions']['write']);
|
|
||||||
$this->assertEquals($document2['body']['firstName'], 'Samuel');
|
$this->assertEquals($document2['body']['firstName'], 'Samuel');
|
||||||
$this->assertEquals($document2['body']['lastName'], 'Jackson');
|
$this->assertEquals($document2['body']['lastName'], 'Jackson');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue