IconControllerTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Tests\Api\v1\Controllers;
  3. use Illuminate\Http\UploadedFile;
  4. use Illuminate\Foundation\Testing\WithoutMiddleware;
  5. use Tests\TestCase;
  6. class IconControllerTest extends TestCase
  7. {
  8. use WithoutMiddleware;
  9. /**
  10. * @test
  11. */
  12. public function test_upload_icon_returns_filename()
  13. {
  14. $file = UploadedFile::fake()->image('testIcon.jpg');
  15. $response = $this->json('POST', '/api/v1/icons', [
  16. 'icon' => $file,
  17. ])
  18. ->assertCreated()
  19. ->assertJsonStructure([
  20. 'filename'
  21. ]);
  22. }
  23. /**
  24. * @test
  25. */
  26. public function test_upload_with_invalid_data_returns_validation_error()
  27. {
  28. $response = $this->json('POST', '/api/v1/icons', [
  29. 'icon' => null,
  30. ])
  31. ->assertStatus(422);
  32. }
  33. /**
  34. * @test
  35. */
  36. public function test_delete_icon_returns_success()
  37. {
  38. $response = $this->json('DELETE', '/api/v1/icons/testIcon.jpg')
  39. ->assertNoContent(204);
  40. }
  41. /**
  42. * @test
  43. */
  44. public function test_delete_invalid_icon_returns_success()
  45. {
  46. $response = $this->json('DELETE', '/api/v1/icons/null')
  47. ->assertNoContent(204);
  48. }
  49. }