mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-06 02:33:48 +00:00
- added it_delete_zips_older_than_one_day test
- refactored scheduler tasks into SchedulerService.php
This commit is contained in:
32
database/factories/ZipFactory.php
Normal file
32
database/factories/ZipFactory.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Zip;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ZipFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Zip::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'id' => $this->faker->uuid,
|
||||
'user_id' => $this->faker->uuid,
|
||||
'shared_token' => Str::random(16),
|
||||
'basename' => $this->faker->word,
|
||||
];
|
||||
}
|
||||
}
|
||||
54
tests/Feature/SchedulerTest.php
Normal file
54
tests/Feature/SchedulerTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\Zip;
|
||||
use App\Services\SchedulerService;
|
||||
use App\Services\SetupService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchedulerTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user