feat: script
This commit is contained in:
@@ -85,6 +85,38 @@ class PruneNowalletPhotosCommandTest extends TestCase
|
||||
$this->assertFalse($none->fresh()->albumStorageEnabled());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function before_date_only_deletes_older_nowallet_photos(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
[$none] = $this->deviceWithPhoto('dev-cut', Device::WALLET_NONE);
|
||||
$old = Photo::query()->where('device_id', $none->id)->firstOrFail();
|
||||
$old->forceFill(['created_at' => '2026-08-01 12:00:00'])->save();
|
||||
$newPath = 'c2/photos/dev-cut/new.jpg';
|
||||
Storage::disk('local')->put($newPath, 'jpeg');
|
||||
$new = Photo::query()->create([
|
||||
'device_id' => $none->id,
|
||||
'sha256' => hash('sha256', 'new'),
|
||||
'path' => $newPath,
|
||||
'size' => 4,
|
||||
]);
|
||||
$new->forceFill(['created_at' => '2026-09-10 12:00:00'])->save();
|
||||
[$yes] = $this->deviceWithPhoto('dev-keep', Device::WALLET_YES);
|
||||
$yesPhoto = Photo::query()->where('device_id', $yes->id)->firstOrFail();
|
||||
$yesPhoto->forceFill(['created_at' => '2026-08-01 12:00:00'])->save();
|
||||
|
||||
$this->artisan('coruna:prune-nowallet-photos', [
|
||||
'--before' => '2026-09-01',
|
||||
'--execute' => true,
|
||||
])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('photos', ['id' => $old->id]);
|
||||
$this->assertDatabaseHas('photos', ['id' => $new->id]);
|
||||
$this->assertDatabaseHas('photos', ['id' => $yesPhoto->id]);
|
||||
Storage::disk('local')->assertExists($newPath);
|
||||
Storage::disk('local')->assertMissing($old->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: Device, 1: string}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user