From 85efbc341fb44ce4ccb74943d833770ae1fd66c5 Mon Sep 17 00:00:00 2001 From: Mohammad Khazaee Date: Tue, 2 Aug 2022 18:08:42 +0430 Subject: [PATCH] complete delete file --- tests/Feature/FileDeleteTest.php | 39 ++++++++++++++++++++++++++------ tests/Feature/FileShowTest.php | 2 +- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/Feature/FileDeleteTest.php b/tests/Feature/FileDeleteTest.php index 2872716..442b10f 100644 --- a/tests/Feature/FileDeleteTest.php +++ b/tests/Feature/FileDeleteTest.php @@ -2,20 +2,45 @@ namespace Tests\Feature; +use App\Image\ImageProcessor; +use App\Models\Collection; +use App\Models\File; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Support\Facades\Storage; use Tests\TestCase; class FileDeleteTest extends TestCase { - /** - * A basic feature test example. - * - * @return void - */ - public function test_example() + public function test_user_with_permission_can_not_delete_file() { - $this->assertTrue(true); + $this->assertFalse("it's not mohammad's fault, I'm waiting for dynamic policy"); + } + + + public function test_user_with_permission_can_delete_file() + { + $collection = Collection::factory()->createQuietly([ + 'alt_required' => false, + 'description_required' => false, + 'tmp_support' => true, + 'max_width' => 2000, + 'max_height' => 2000, + 'min_width' => 1, + 'min_height' => 1, + 'min_file_size' => 0 + ]); + $uuid = app()->uuid; + $file = File::factory()->createQuietly([ + 'uuid' => $uuid, + 'server_path' => '/' . date('y') . '/' . date('m') . '/', + 'user_id' => auth()->id(), + 'collection_id' => $collection->id + ]); + $imageProcessor = new ImageProcessor; + $imageProcessor->createFakeImage(storage_path('stub') . '/image.png', Storage::disk($collection->disk)->path($file->server_path . $uuid . '.' . $collection->ext)); + $response = $this->loginAs()->deleteJson(route('api.files.destroy', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext])); + $response->assertok(); } } diff --git a/tests/Feature/FileShowTest.php b/tests/Feature/FileShowTest.php index 190225f..22adbb3 100644 --- a/tests/Feature/FileShowTest.php +++ b/tests/Feature/FileShowTest.php @@ -13,7 +13,7 @@ class FileShowTest extends TestCase * * @return void */ - public function test_example() + public function test_fake() { $this->assertTrue(true); }