Merge pull request #10739 from appwrite/copilot/sub-pr-10738

Add test coverage for webp upload and preview functionality
This commit is contained in:
Steven Nguyen 2025-11-06 15:07:52 -08:00 committed by GitHub
commit 4f1940ac0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 60 additions and 3 deletions

View file

@ -30,7 +30,7 @@ trait StorageBase
'name' => 'Test Bucket',
'fileSecurity' => true,
'maximumFileSize' => 2000000, //2MB
'allowedFileExtensions' => ['jpg', 'png', 'jfif'],
'allowedFileExtensions' => ['jpg', 'png', 'jfif', 'webp'],
'permissions' => [
Permission::read(Role::any()),
Permission::create(Role::any()),
@ -263,7 +263,39 @@ trait StorageBase
$this->assertEquals(400, $res['headers']['status-code']);
$this->assertEquals(Exception::STORAGE_INVALID_APPWRITE_ID, $res['body']['type']);
return ['bucketId' => $bucketId, 'fileId' => $file['body']['$id'], 'largeFileId' => $largeFile['body']['$id'], 'largeBucketId' => $bucket2['body']['$id']];
/**
* Test for SUCCESS - Upload and view webp image
*/
$webpFile = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'fileId' => ID::unique(),
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/image.webp'), 'image/webp', 'image.webp'),
'permissions' => [
Permission::read(Role::any()),
Permission::update(Role::any()),
Permission::delete(Role::any()),
],
]);
$this->assertEquals(201, $webpFile['headers']['status-code']);
$this->assertNotEmpty($webpFile['body']['$id']);
$this->assertEquals('image.webp', $webpFile['body']['name']);
$this->assertEquals('image/webp', $webpFile['body']['mimeType']);
$webpFileId = $webpFile['body']['$id'];
// View webp file
$webpView = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $webpFileId . '/view', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $webpView['headers']['status-code']);
$this->assertEquals('image/webp', $webpView['headers']['content-type']);
$this->assertNotEmpty($webpView['body']);
return ['bucketId' => $bucketId, 'fileId' => $file['body']['$id'], 'largeFileId' => $largeFile['body']['$id'], 'largeBucketId' => $bucket2['body']['$id'], 'webpFileId' => $webpFileId];
}
public function testCreateBucketFileZstdCompression(): array
@ -416,7 +448,7 @@ trait StorageBase
],
]);
$this->assertEquals(200, $files['headers']['status-code']);
$this->assertEquals(0, count($files['body']['files']));
$this->assertEquals(1, count($files['body']['files']));
$files = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([
'content-type' => 'application/json',
@ -869,6 +901,31 @@ trait StorageBase
return $data;
}
/**
* @depends testCreateBucketFile
*/
public function testFilePreview(array $data): array
{
$bucketId = $data['bucketId'];
$fileId = $data['fileId'];
// Preview PNG as webp
$preview = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'width' => 300,
'height' => 300,
'output' => 'webp',
]);
$this->assertEquals(200, $preview['headers']['status-code']);
$this->assertEquals('image/webp', $preview['headers']['content-type']);
$this->assertNotEmpty($preview['body']);
return $data;
}
/**
* @depends testUpdateBucketFile
*/

BIN
tests/resources/image.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B