From a2d3bdd67b937bcf7b3b43ad5bb39173ee046910 Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Sat, 27 Feb 2021 14:46:19 +0100 Subject: [PATCH] added it_upload_new_file --- tests/Feature/FileTest.php | 46 +++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/tests/Feature/FileTest.php b/tests/Feature/FileTest.php index b0f62521..d7479066 100644 --- a/tests/Feature/FileTest.php +++ b/tests/Feature/FileTest.php @@ -58,15 +58,17 @@ class FileTest extends TestCase 'is_last' => true, ])->assertStatus(201); - Storage::disk('local')->assertMissing( + $disk = Storage::disk('local'); + + $disk->assertMissing( "chunks/fake-image.jpg" ); - Storage::disk('local')->assertExists( + $disk->assertExists( "files/$user->id/fake-image.jpg" ); - Storage::disk('local')->assertExists( + $disk->assertExists( "files/$user->id/thumbnail-fake-image.jpg" ); @@ -75,6 +77,44 @@ class FileTest extends TestCase ]); } + /** + * @test + */ + public function it_upload_new_file() + { + Storage::fake('local'); + + $this->setup->create_directories(); + + $file = UploadedFile::fake() + ->create('fake-file.pdf', 1200, 'application/pdf'); + + $user = User::factory(User::class) + ->create(); + + Sanctum::actingAs($user); + + $this->postJson('/api/upload', [ + 'file' => $file, + 'folder_id' => null, + 'is_last' => true, + ])->assertStatus(201); + + $disk = Storage::disk('local'); + + $disk->assertMissing( + "chunks/fake-file.pdf" + ); + + $disk->assertExists( + "files/$user->id/fake-file.pdf" + ); + + $this->assertDatabaseHas('traffic', [ + 'user_id' => $user->id, + ]); + } + /** * @test */