FIxed 409 for createCollection
This commit is contained in:
parent
babd77f663
commit
6b77fcf21f
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue