1
0
Fork 0
mirror of synced 2024-06-02 10:54:44 +12:00

delete bucket endpoint and test

This commit is contained in:
Damodar Lohani 2021-06-16 16:02:14 +05:45
parent 1a82529e49
commit 8c30043bd3
3 changed files with 80 additions and 2 deletions

View file

@ -194,6 +194,51 @@ App::put('/v1/storage/buckets/:bucketId')
$response->dynamic2($bucket, Response::MODEL_BUCKET);
});
App::delete('/v1/storage/buckets/:bucketId')
->desc('Delete Bucket')
->groups(['api', 'storage'])
->label('scope', 'buckets.write')
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
->label('sdk.namespace', 'storage')
->label('sdk.method', 'deleteBucket')
->label('sdk.description', '/docs/references/storage/delete-bucket.md')
->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT)
->label('sdk.response.model', Response::MODEL_NONE)
->param('bucketId', '', new UID(), 'Bucket unique ID.')
->inject('response')
->inject('dbForInternal')
->inject('audits')
->inject('deletes')
->action(function ($bucketId, $response, $dbForInternal, $audits, $deletes) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Appwrite\Event\Event $audits */
/** @var Appwrite\Event\Event $deletes */
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if (empty($bucket->getId())) {
throw new Exception('Bucket not found', 404);
}
$deletes
->setParam('type', DELETE_TYPE_DOCUMENT)
->setParam('document', $bucket)
;
if(!$dbForInternal->deleteDocument('buckets', $bucketId)) {
throw new Exception('Failed to remove project from DB', 500);
}
$audits
->setParam('event', 'storage.buckets.delete')
->setParam('resource', 'storage/buckets/' . $bucket->getId())
->setParam('data', $bucket->getArrayCopy())
;
$response->noContent();
});
App::post('/v1/storage/files')
->desc('Create File')
->groups(['api', 'storage'])

View file

@ -0,0 +1 @@
Delete a storage bucket by its unique ID.

View file

@ -75,7 +75,7 @@ class StorageCustomServerTest extends Scope
/**
* @depends testCreateBucket
*/
public function testGetBucket($data): array
public function testGetBucket(array $data): array
{
$id = $data['bucketId'] ?? '';
/**
@ -115,7 +115,7 @@ class StorageCustomServerTest extends Scope
/**
* @depends testCreateBucket
*/
public function testUpdateBucket($data):array
public function testUpdateBucket(array $data):array
{
$id = $data['bucketId'] ?? '';
/**
@ -154,4 +154,36 @@ class StorageCustomServerTest extends Scope
return ['bucketId' => $bucketId];
}
/**
* @depends testCreateBucket
*/
public function testDeleteBucket(array $data): array
{
$id = $data['bucketId'] ?? '';
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $id,
array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $id,
array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(404, $response['headers']['status-code']);
/**
* Test for FAILURE
*/
return $data;
}
}