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 */