1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00

FIxed 409 for createCollection

This commit is contained in:
Matej Baco 2022-01-12 20:51:13 +01:00
parent babd77f663
commit 6b77fcf21f
2 changed files with 18 additions and 2 deletions

View file

@ -166,8 +166,6 @@ App::post('/v1/database/collections')
$collectionId = $collectionId == 'unique()' ? $dbForProject->getId() : $collectionId;
try {
$dbForProject->createCollection('collection_' . $collectionId);
$collection = $dbForProject->createDocument('collections', new Document([
'$id' => $collectionId,
'$read' => $read ?? [], // Collection permissions for collection documents (based on permission model)
@ -183,6 +181,8 @@ App::post('/v1/database/collections')
throw new Exception('Collection already exists', 409);
}
$dbForProject->createCollection('collection_' . $collectionId);
$audits
->setParam('event', 'database.collections.create')
->setParam('resource', 'collection/'.$collectionId)

View file

@ -7,6 +7,7 @@ use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
use Tests\E2E\Client;
use Utopia\Database\Database;
use function array_merge;
class DatabaseCustomServerTest extends Scope
{
@ -136,6 +137,21 @@ class DatabaseCustomServerTest extends Scope
]);
$this->assertEquals($response['headers']['status-code'], 400);
// This collection already exists
$response = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'name' => 'Test 1',
'collectionId' => 'first',
'read' => ['role:all'],
'write' => ['role:all'],
'permission' => 'document'
]);
$this->assertEquals($response['headers']['status-code'], 409);
}
public function testDeleteAttribute(): array