|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Pterodactyl\Tests\Integration\Api\Client\Server\Files; |
| 4 | + |
| 5 | +use Mockery\MockInterface; |
| 6 | +use Pterodactyl\Models\Permission; |
| 7 | +use Pterodactyl\Repositories\Wings\DaemonFileRepository; |
| 8 | +use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase; |
| 9 | + |
| 10 | +class CompressFilesTest extends ClientApiIntegrationTestCase |
| 11 | +{ |
| 12 | + public function testEndpointRequiresAuthorization(): void |
| 13 | + { |
| 14 | + [$user, $server] = $this->generateTestAccount([Permission::ACTION_CONTROL_CONSOLE]); |
| 15 | + |
| 16 | + $this->postJson($this->link($server, '/files/compress'))->assertUnauthorized(); |
| 17 | + |
| 18 | + $this->actingAs($user) |
| 19 | + ->postJson($this->link($server, '/files/compress')) |
| 20 | + ->assertForbidden(); |
| 21 | + } |
| 22 | + |
| 23 | + public function testEndpointTriggersWingsCall(): void |
| 24 | + { |
| 25 | + [$user, $server] = $this->generateTestAccount([Permission::ACTION_FILE_ARCHIVE]); |
| 26 | + |
| 27 | + $this->mock(DaemonFileRepository::class, function (MockInterface $mock) { |
| 28 | + $mock->expects('setServer->compressFiles')->with('/', ['test.txt'])->andReturn([ |
| 29 | + 'name' => 'test.tar.gz', |
| 30 | + 'mime' => 'application/gzip', |
| 31 | + ]); |
| 32 | + }); |
| 33 | + |
| 34 | + $this->actingAs($user) |
| 35 | + ->postJson($endpoint = $this->link($server, '/files/compress'), []) |
| 36 | + ->assertUnprocessable() |
| 37 | + ->assertJsonPath('errors.0.meta', ['source_field' => 'files', 'rule' => 'required']); |
| 38 | + |
| 39 | + $this->postJson($endpoint, ['root' => '/', 'files' => ['test.txt']]) |
| 40 | + ->assertOk() |
| 41 | + ->assertJsonPath('object', 'file_object') |
| 42 | + ->assertJsonPath('attributes.name', 'test.tar.gz') |
| 43 | + ->assertJsonPath('attributes.mimetype', 'application/gzip'); |
| 44 | + } |
| 45 | +} |
0 commit comments