1
0
Fork 0
mirror of synced 2024-06-03 11:24:48 +12:00

Added test for better storage coverage

This commit is contained in:
eldadfux 2019-11-17 22:33:02 +02:00
parent c3b3a66787
commit 6a9110ac46
2 changed files with 100 additions and 6 deletions

View file

@ -529,9 +529,9 @@ $utopia->put('/v1/storage/files/:fileId')
->param('fileId', '', function () { return new UID(); }, 'File unique ID.')
->param('read', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->param('folderId', '', function () { return new UID(); }, 'Folder to associate files with.', true)
//->param('folderId', '', function () { return new UID(); }, 'Folder to associate files with.', true)
->action(
function ($fileId, $read, $write, $folderId) use ($response, $projectDB) {
function ($fileId, $read, $write, $folderId = '') use ($response, $projectDB) {
$file = $projectDB->getDocument($fileId);
if (empty($file->getUid()) || Database::SYSTEM_COLLECTION_FILES != $file->getCollection()) {

View file

@ -50,12 +50,90 @@ class ProjectStorafeTest extends BaseProjects
*/
public function testFileReadSuccess(array $data): array
{
$file = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'], [
$file1 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'], [
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
]);
$this->assertEquals($file['headers']['status-code'], 200);
$this->assertEquals($file1['headers']['status-code'], 200);
$this->assertNotEmpty($file1['body']['$uid']);
$this->assertIsInt($file1['body']['dateCreated']);
$this->assertEquals('logo.png', $file1['body']['name']);
$this->assertEquals('image/png', $file1['body']['mimeType']);
$this->assertEquals(47218, $file1['body']['sizeOriginal']);
//$this->assertEquals(54944, $file1['body']['sizeActual']);
//$this->assertEquals('gzip', $file1['body']['algorithm']);
//$this->assertEquals('1', $file1['body']['fileOpenSSLVersion']);
//$this->assertEquals('aes-128-gcm', $file1['body']['fileOpenSSLCipher']);
//$this->assertNotEmpty($file1['body']['fileOpenSSLTag']);
//$this->assertNotEmpty($file1['body']['fileOpenSSLIV']);
$this->assertIsArray($file1['body']['$permissions']['read']);
$this->assertIsArray($file1['body']['$permissions']['write']);
$this->assertCount(1, $file1['body']['$permissions']['read']);
$this->assertCount(1, $file1['body']['$permissions']['write']);
$file2 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/preview', [
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
]);
$this->assertEquals(200, $file2['headers']['status-code']);
$this->assertEquals('image/png; charset=UTF-8', $file2['headers']['content-type']);
$this->assertNotEmpty($file2['body']);
$file3 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/download', [
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
]);
$this->assertEquals(200, $file3['headers']['status-code']);
$this->assertEquals('attachment; filename="logo.png"', $file3['headers']['content-disposition']);
$this->assertEquals('image/png; charset=UTF-8', $file3['headers']['content-type']);
$this->assertNotEmpty($file3['body']);
$file4 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/view', [
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
]);
$this->assertEquals(200, $file4['headers']['status-code']);
$this->assertEquals('image/png; charset=UTF-8', $file4['headers']['content-type']);
$this->assertNotEmpty($file4['body']);
return $data;
}
/**
* @depends testFileReadSuccess
*/
public function testFileListSuccess(array $data): array
{
$files = $this->client->call(Client::METHOD_GET, '/storage/files', [
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
]);
$this->assertEquals(200, $files['headers']['status-code']);
$this->assertEquals(1, $files['body']['sum']);
$this->assertCount(1, $files['body']['files']);
return $data;
}
/**
* @depends testFileListSuccess
*/
public function testFileUpdateSuccess(array $data): array
{
$file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['fileId'], [
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
], [
'read' => ['*'],
'write' => ['*'],
]);
$this->assertEquals(200, $file['headers']['status-code']);
$this->assertNotEmpty($file['body']['$uid']);
$this->assertIsInt($file['body']['dateCreated']);
$this->assertEquals('logo.png', $file['body']['name']);
@ -69,9 +147,25 @@ class ProjectStorafeTest extends BaseProjects
//$this->assertNotEmpty($file['body']['fileOpenSSLIV']);
$this->assertIsArray($file['body']['$permissions']['read']);
$this->assertIsArray($file['body']['$permissions']['write']);
$this->assertCount(1, $file['body']['$permissions']['read']);
$this->assertCount(1, $file['body']['$permissions']['write']);
$this->assertCount(0, $file['body']['$permissions']['read']);
$this->assertCount(0, $file['body']['$permissions']['write']);
return $data;
}
/**
* @depends testFileUpdateSuccess
*/
public function testFileDeleteSuccess(array $data): array
{
$file = $this->client->call(Client::METHOD_DELETE, '/storage/files/' . $data['fileId'], [
'x-appwrite-project' => $data['projectUid'],
'x-appwrite-key' => $data['projectAPIKeySecret'],
]);
$this->assertEquals(204, $file['headers']['status-code']);
$this->assertEmpty($file['body']);
return $data;
}
}