Fix tests for create/delete collection
This commit is contained in:
parent
8aecf3cf6a
commit
1885a9632d
3 changed files with 51 additions and 46 deletions
|
@ -24,6 +24,8 @@ use Utopia\Database\Document as Document2;
|
|||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization as Authorization2;
|
||||
|
||||
use function Amp\Promise\wait;
|
||||
|
||||
App::post('/v1/database/collections')
|
||||
->desc('Create Collection')
|
||||
->groups(['api', 'database'])
|
||||
|
@ -98,7 +100,7 @@ App::get('/v1/database/collections/:collectionId')
|
|||
->label('sdk.response.model', Response::MODEL_COLLECTION)
|
||||
->param('collectionId', '', new UID(), 'Collection unique ID.')
|
||||
->inject('response')
|
||||
->inject('projectDB')
|
||||
->inject('dbForExternal')
|
||||
->action(function ($collectionId, $response, $dbForExternal) {
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Utopia\Database\Database $dbForExternal */
|
||||
|
@ -257,10 +259,10 @@ App::post('/v1/database/collections/:collectionId/attributes')
|
|||
// TODO@kodumbeats add units to description
|
||||
->param('size', null, new Numeric(), 'Attribute size.')
|
||||
->param('required', null, new Boolean(), 'Is attribute required?')
|
||||
->param('signed', null, new Boolean(), 'Is attribute signed?')
|
||||
->param('array', null, new Boolean(), 'Is attribute an array?')
|
||||
->param('signed', true, new Boolean(), 'Is attribute signed?', true)
|
||||
->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."
|
||||
->param('filters', [], new ArrayList(new Text(256)), 'Array of filters.')
|
||||
->param('filters', [], new ArrayList(new Text(256)), 'Array of filters.', true)
|
||||
->inject('response')
|
||||
->inject('dbForExternal')
|
||||
->inject('audits')
|
||||
|
@ -597,7 +599,7 @@ App::delete('/v1/database/collections/:collectionId/indexes/:indexId')
|
|||
|
||||
$collection = $dbForExternal->getCollection($collectionId);
|
||||
|
||||
if (empty($collection)) {
|
||||
if ($collection->isEmpty()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
|
@ -677,7 +679,7 @@ App::post('/v1/database/collections/:collectionId/documents')
|
|||
|
||||
$collection = $dbForExternal->getCollection($collectionId);
|
||||
|
||||
if (empty($collection)) {
|
||||
if ($collection->isEmpty()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
|
@ -793,7 +795,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
|
||||
$collection = $dbForExternal->getCollection($collectionId);
|
||||
|
||||
if (empty($collection)) {
|
||||
if ($collection->isEmpty()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
|
@ -903,7 +905,7 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
|
||||
$collection = $dbForExternal->getCollection($collectionId);
|
||||
|
||||
if (empty($collection)) {
|
||||
if ($collection->isEmpty()) {
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
|
|
|
@ -182,6 +182,8 @@ class Response extends SwooleResponse
|
|||
// Entities
|
||||
->setModel(new Permissions())
|
||||
->setModel(new Collection())
|
||||
->setModel(new Attribute())
|
||||
->setModel(new Index())
|
||||
->setModel(new ModelDocument())
|
||||
->setModel(new Rule())
|
||||
->setModel(new Log())
|
||||
|
|
|
@ -25,36 +25,39 @@ class DatabaseCustomServerTest extends Scope
|
|||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'name' => '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
|
||||
],
|
||||
],
|
||||
'id' => 'Actors',
|
||||
]);
|
||||
|
||||
$this->assertEquals($actors['headers']['status-code'], 201);
|
||||
$this->assertEquals($actors['body']['name'], 'Actors');
|
||||
$this->assertIsArray($actors['body']['$permissions']);
|
||||
$this->assertIsArray($actors['body']['$permissions']['read']);
|
||||
$this->assertIsArray($actors['body']['$permissions']['write']);
|
||||
$this->assertCount(1, $actors['body']['$permissions']['read']);
|
||||
$this->assertCount(2, $actors['body']['$permissions']['write']);
|
||||
|
||||
$firstName = $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' => '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
|
||||
$document1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/documents', array_merge([
|
||||
|
@ -83,21 +86,19 @@ class DatabaseCustomServerTest extends Scope
|
|||
|
||||
$this->assertEquals($document1['headers']['status-code'], 201);
|
||||
$this->assertEquals($document1['body']['$collection'], $actors['body']['$id']);
|
||||
$this->assertIsArray($document1['body']['$permissions']);
|
||||
$this->assertIsArray($document1['body']['$permissions']['read']);
|
||||
$this->assertIsArray($document1['body']['$permissions']['write']);
|
||||
$this->assertCount(1, $document1['body']['$permissions']['read']);
|
||||
$this->assertCount(1, $document1['body']['$permissions']['write']);
|
||||
$this->assertIsArray($document1['body']['$read']);
|
||||
$this->assertIsArray($document1['body']['$write']);
|
||||
$this->assertCount(1, $document1['body']['$read']);
|
||||
$this->assertCount(1, $document1['body']['$write']);
|
||||
$this->assertEquals($document1['body']['firstName'], 'Tom');
|
||||
$this->assertEquals($document1['body']['lastName'], 'Holland');
|
||||
|
||||
$this->assertEquals($document2['headers']['status-code'], 201);
|
||||
$this->assertEquals($document2['body']['$collection'], $actors['body']['$id']);
|
||||
$this->assertIsArray($document2['body']['$permissions']);
|
||||
$this->assertIsArray($document2['body']['$permissions']['read']);
|
||||
$this->assertIsArray($document2['body']['$permissions']['write']);
|
||||
$this->assertCount(1, $document2['body']['$permissions']['read']);
|
||||
$this->assertCount(1, $document2['body']['$permissions']['write']);
|
||||
$this->assertIsArray($document2['body']['$read']);
|
||||
$this->assertIsArray($document2['body']['$write']);
|
||||
$this->assertCount(1, $document2['body']['$read']);
|
||||
$this->assertCount(1, $document2['body']['$write']);
|
||||
$this->assertEquals($document2['body']['firstName'], 'Samuel');
|
||||
$this->assertEquals($document2['body']['lastName'], 'Jackson');
|
||||
|
||||
|
|
Loading…
Reference in a new issue