Path: blob/1.0-develop/tests/Integration/Api/Client/Server/Files/CompressFilesTest.php
10277 views
<?php12namespace Pterodactyl\Tests\Integration\Api\Client\Server\Files;34use Mockery\MockInterface;5use Pterodactyl\Models\Permission;6use Pterodactyl\Repositories\Wings\DaemonFileRepository;7use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;89class CompressFilesTest extends ClientApiIntegrationTestCase10{11public function testEndpointRequiresAuthorization(): void12{13[$user, $server] = $this->generateTestAccount([Permission::ACTION_CONTROL_CONSOLE]);1415$this->postJson($this->link($server, '/files/compress'))->assertUnauthorized();1617$this->actingAs($user)18->postJson($this->link($server, '/files/compress'))19->assertForbidden();20}2122public function testEndpointTriggersWingsCall(): void23{24[$user, $server] = $this->generateTestAccount([Permission::ACTION_FILE_ARCHIVE]);2526$this->mock(DaemonFileRepository::class, function (MockInterface $mock) {27$mock->expects('setServer->compressFiles')->with('/', ['test.txt'])->andReturn([28'name' => 'test.tar.gz',29'mime' => 'application/gzip',30]);31});3233$this->actingAs($user)34->postJson($endpoint = $this->link($server, '/files/compress'), [])35->assertUnprocessable()36->assertJsonPath('errors.0.meta', ['source_field' => 'files', 'rule' => 'required']);3738$this->postJson($endpoint, ['root' => '/', 'files' => ['test.txt']])39->assertOk()40->assertJsonPath('object', 'file_object')41->assertJsonPath('attributes.name', 'test.tar.gz')42->assertJsonPath('attributes.mimetype', 'application/gzip');43}44}454647