From 617ba2a6a88e4360758641b9c2b3684914dcd864 Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Tue, 2 Mar 2021 17:05:57 +0100 Subject: [PATCH] - added it_delete_zips_older_than_one_day test - refactored scheduler tasks into SchedulerService.php --- database/factories/ZipFactory.php | 32 ++++++++++++++++++ tests/Feature/SchedulerTest.php | 54 +++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 database/factories/ZipFactory.php create mode 100644 tests/Feature/SchedulerTest.php 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'); + } +}