File tree Expand file tree Collapse file tree 2 files changed +0
-23
lines changed
app/Http/Controllers/Admin
tests/Feature/App/Http/Controllers/Admin Expand file tree Collapse file tree 2 files changed +0
-23
lines changed Original file line number Diff line number Diff line change @@ -29,10 +29,6 @@ public function __invoke(Request $request): JsonResponse
2929
3030 $ file = $ request ->file ('upload ' );
3131
32- if (is_array ($ file )) {
33- $ file = $ file [0 ];
34- }
35-
3632 if (! $ file instanceof UploadedFile) {
3733 return response ()->json (['error ' => 'Invalid upload ' ], 400 );
3834 }
Original file line number Diff line number Diff line change 2525 Storage::disk ('images ' )->assertExists ($ path );
2626});
2727
28- test ('handles valid upload when file is sent as an array ' , function () {
29- $ file = UploadedFile::fake ()->image ('photo.jpg ' );
30-
31- $ mockRequest = Mockery::mock (Request::class);
32- $ mockRequest ->shouldReceive ('validate ' )->andReturn (['upload ' => [$ file ]]);
33- $ mockRequest ->shouldReceive ('hasFile ' )->once ()->with ('upload ' )->andReturn (true );
34- $ mockRequest ->shouldReceive ('file ' )->once ()->with ('upload ' )->andReturn ([$ file ]);
35-
36- $ controller = new UploadController ;
37-
38- $ response = $ controller ($ mockRequest );
39-
40- expect ($ response ->getStatusCode ())->toBe (200 );
41- expect ($ response ->getData (true ))->toHaveKey ('url ' );
42-
43- $ path = str_replace ('/images/ ' , '' , $ response ->getData (true )['url ' ]);
44- Storage::disk ('images ' )->assertExists ($ path );
45- });
46-
4728test ('fails when no file is uploaded ' , function () {
4829 postJson (route ('image-upload ' ), [])->assertStatus (422 );
4930});
You can’t perform that action at this time.
0 commit comments