diff --git a/database/factories/ZipFactory.php b/database/factories/ZipFactory.php new file mode 100644 index 00000000..03551230 --- /dev/null +++ b/database/factories/ZipFactory.php @@ -0,0 +1,32 @@ + $this->faker->uuid, + 'user_id' => $this->faker->uuid, + 'shared_token' => Str::random(16), + 'basename' => $this->faker->word, + ]; + } +} diff --git a/tests/Feature/SchedulerTest.php b/tests/Feature/SchedulerTest.php new file mode 100644 index 00000000..033f3e46 --- /dev/null +++ b/tests/Feature/SchedulerTest.php @@ -0,0 +1,54 @@ +setup = app()->make(SetupService::class); + $this->scheduler = app()->make(SchedulerService::class); + } + + /** + * @test + */ + public function it_delete_zips_older_than_one_day() + { + Storage::fake('local'); + + $this->setup->create_directories(); + + $file = UploadedFile::fake() + ->create('archive.zip', 2000, 'application/zip'); + + Storage::putFileAs('zip', $file, 'EHWKcuvKzA4Gv29v-archive.zip'); + + $zip = Zip::factory(Zip::class)->create([ + 'basename' => 'EHWKcuvKzA4Gv29v-archive.zip', + 'created_at' => Carbon::now()->subDay(), + ]); + + $this->scheduler->delete_old_zips(); + + $this->assertDatabaseMissing('zips', [ + 'id' => $zip->id + ]); + + Storage::disk('local') + ->assertMissing('zip/EHWKcuvKzA4Gv29v-archive.zip'); + } +}