IconControllerTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Tests\Api\v1\Controllers;
  3. use Illuminate\Foundation\Testing\WithoutMiddleware;
  4. use Illuminate\Http\UploadedFile;
  5. use Tests\FeatureTestCase;
  6. /**
  7. * @covers \App\Api\v1\Controllers\IconController
  8. */
  9. class IconControllerTest extends FeatureTestCase
  10. {
  11. use WithoutMiddleware;
  12. /**
  13. * @test
  14. */
  15. public function test_upload_icon_returns_filename()
  16. {
  17. $file = UploadedFile::fake()->image('testIcon.jpg');
  18. $response = $this->json('POST', '/api/v1/icons', [
  19. 'icon' => $file,
  20. ])
  21. ->assertCreated()
  22. ->assertJsonStructure([
  23. 'filename',
  24. ]);
  25. }
  26. /**
  27. * @test
  28. */
  29. public function test_upload_with_invalid_data_returns_validation_error()
  30. {
  31. $response = $this->json('POST', '/api/v1/icons', [
  32. 'icon' => null,
  33. ])
  34. ->assertStatus(422);
  35. }
  36. /**
  37. * @test
  38. */
  39. public function test_fetch_logo_returns_filename()
  40. {
  41. $response = $this->json('POST', '/api/v1/icons/default', [
  42. 'service' => 'twitter',
  43. ])
  44. ->assertStatus(201)
  45. ->assertJsonStructure([
  46. 'filename',
  47. ]);
  48. }
  49. /**
  50. * @test
  51. */
  52. public function test_fetch_unknown_logo_returns_nothing()
  53. {
  54. $response = $this->json('POST', '/api/v1/icons/default', [
  55. 'service' => 'unknown_company',
  56. ])
  57. ->assertNoContent();
  58. }
  59. /**
  60. * @test
  61. */
  62. public function test_delete_icon_returns_success()
  63. {
  64. $response = $this->json('DELETE', '/api/v1/icons/testIcon.jpg')
  65. ->assertNoContent(204);
  66. }
  67. /**
  68. * @test
  69. */
  70. public function test_delete_invalid_icon_returns_success()
  71. {
  72. $response = $this->json('DELETE', '/api/v1/icons/null')
  73. ->assertNoContent(204);
  74. }
  75. }