You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

  1. <?php
  2. namespace Tests\Feature;
  3. use App\Image\ImageProcessor;
  4. use App\Models\Collection;
  5. use App\Models\File;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Illuminate\Foundation\Testing\WithFaker;
  8. use Illuminate\Support\Facades\Storage;
  9. use Tests\Feature\Traits\FileTraits;
  10. use Tests\TestCase;
  11. class FileUpdateTest extends TestCase
  12. {
  13. use FileTraits;
  14. // public function test_user_can_not_access_update_without_permission()
  15. // {
  16. // $this->assertFalse("it's not mohammad's fault, I'm waiting for dynamic policy");
  17. // }
  18. public function test_user_update_not_exits_files_not_found()
  19. {
  20. $data = [
  21. "original_name" => 'original name is very bad',
  22. "description" => 'this is a description for file and has beed updated',
  23. ];
  24. $response = $this->loginAs()->putJson(route('api.files.update', ['collection_name' => 'not_exits', 'uuid' => app()->uuid, 'extention' => 'jpg']), $data);
  25. $response->assertNotFound();
  26. }
  27. public function test_user_can_update_file()
  28. {
  29. $file = $this->one(File::class, dependencyAttributes: ['withImage' => true]);
  30. $collection = Collection::find($file->collection_id);
  31. $data = [
  32. "original_name" => 'original name is very bad',
  33. "description" => 'this is a description for file and has beed updated',
  34. ];
  35. $response = $this->loginAs()->putJson(route('api.files.update', ['collection_name' => $collection->name, 'uuid' => $file->uuid, 'extention' => $collection->ext]), $data);
  36. $response->assertok()->assertJson(['data' => $data]);
  37. }
  38. }