diff --git a/src/Domain/Zip/Actions/ZipFilesAction.php b/src/Domain/Zip/Actions/ZipFilesAction.php index 0450d1e9..4d2bb7aa 100644 --- a/src/Domain/Zip/Actions/ZipFilesAction.php +++ b/src/Domain/Zip/Actions/ZipFilesAction.php @@ -1,6 +1,7 @@ add(storage_path("app/files/$file->user_id/$file->basename"), $file->name); + $zip->add(Storage::path($filePath), $file->name); } // s3 client if (is_storage_driver('s3')) { $bucketName = config('filesystems.disks.s3.bucket'); - $zip->add("s3://$bucketName/files/$file->user_id/$file->basename", $file->name); + $zip->add("s3://$bucketName/$filePath", $file->name); } } }); diff --git a/src/Domain/Zip/Actions/ZipFolderAction.php b/src/Domain/Zip/Actions/ZipFolderAction.php index 8d0999d8..9bd15166 100644 --- a/src/Domain/Zip/Actions/ZipFolderAction.php +++ b/src/Domain/Zip/Actions/ZipFolderAction.php @@ -41,14 +41,14 @@ class ZipFolderAction // local disk if (is_storage_driver('local')) { - $zip->add(storage_path("app/files/$user_id/{$file['basename']}"), $zipDestination); + $zip->add(Storage::path($filePath), $zipDestination); } // s3 client if (is_storage_driver('s3')) { $bucketName = config('filesystems.disks.s3.bucket'); - $zip->add("s3://$bucketName/files/$user_id/{$file['basename']}", $zipDestination); + $zip->add("s3://$bucketName/$filePath", $zipDestination); } } } diff --git a/tests/Domain/Zip/UserZippingTest.php b/tests/Domain/Zip/UserZippingTest.php index b7d20134..98778953 100644 --- a/tests/Domain/Zip/UserZippingTest.php +++ b/tests/Domain/Zip/UserZippingTest.php @@ -4,7 +4,6 @@ namespace Tests\Domain\Zip; use Storage; use Tests\TestCase; use App\Users\Models\User; -use Domain\Zip\Models\Zip; use Laravel\Sanctum\Sanctum; use Domain\Files\Models\File; use Domain\Folders\Models\Folder; @@ -35,20 +34,14 @@ class UserZippingTest extends TestCase ])->assertStatus(201); }); - $file_ids = File::all()->pluck('id'); + $file_ids = File::all()->pluck('id')->toArray(); - $this->postJson('/api/zip/files', [ - 'items' => $file_ids, - ])->assertStatus(201); + $ids = implode(',', $file_ids); - $this->assertDatabaseHas('zips', [ - 'user_id' => $user->id, - ]); - - Storage::disk('local') - ->assertExists( - 'zip/' . Zip::first()->basename - ); + $this + ->getJson("/api/zip/files?ids=$ids") + ->assertStatus(200) + ->assertHeader('content-type', 'application/x-zip'); } /** @@ -80,15 +73,7 @@ class UserZippingTest extends TestCase }); $this->getJson("/api/zip/folder/$folder->id") - ->assertStatus(201); - - $this->assertDatabaseHas('zips', [ - 'user_id' => $user->id, - ]); - - Storage::disk('local') - ->assertExists( - 'zip/' . Zip::first()->basename - ); + ->assertStatus(200) + ->assertHeader('content-type', 'application/x-zip'); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index c1648da8..46d045c8 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -25,6 +25,6 @@ abstract class TestCase extends BaseTestCase resolve(CreateDiskDirectoriesAction::class)(); - //$this->withoutExceptionHandling(); + $this->withoutExceptionHandling(); } }