Bill transfer storage monthly with a 15-day grace period before deletion.
Deploy Ladill Transfer / deploy (push) Successful in 51s
Deploy Ladill Transfer / deploy (push) Successful in 51s
Files stay available while wallet renewals succeed each month. Failed renewals keep files for TRANSFER_GRACE_PERIOD_DAYS (default 15) before automatic cleanup. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,16 +8,19 @@ use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\Concerns\FakesTransferBilling;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TransferApiTest extends TestCase
|
||||
{
|
||||
use FakesTransferBilling;
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Storage::fake('qr');
|
||||
$this->fakeTransferBillingApi();
|
||||
config([
|
||||
'transfer.service_api_keys' => ['webmail' => 'test-webmail-key'],
|
||||
'identity.api_url' => 'https://ladill.com/api',
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Transfer;
|
||||
use App\Models\User;
|
||||
use App\Services\Transfer\TransferBillingService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\Concerns\FakesTransferBilling;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TransferBillingTest extends TestCase
|
||||
{
|
||||
use FakesTransferBilling;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_failed_renewal_enters_grace_period(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => (string) Str::uuid(),
|
||||
'name' => 'Grace User',
|
||||
'email' => 'grace+'.uniqid().'@example.com',
|
||||
]);
|
||||
|
||||
$transfer = Transfer::create([
|
||||
'user_id' => $user->id,
|
||||
'title' => 'Due soon',
|
||||
'retention_days' => 30,
|
||||
'paid_until' => now()->subMinute(),
|
||||
'status' => Transfer::STATUS_ACTIVE,
|
||||
'storage_bytes' => 1024 * 1024 * 1024,
|
||||
]);
|
||||
|
||||
$base = rtrim((string) config('billing.api_url'), '/');
|
||||
Http::fake([
|
||||
$base.'/can-afford*' => Http::response(['affordable' => false]),
|
||||
]);
|
||||
|
||||
$result = app(TransferBillingService::class)->processDueRenewals();
|
||||
|
||||
$transfer->refresh();
|
||||
$this->assertSame(1, $result['graced']);
|
||||
$this->assertSame(Transfer::STATUS_GRACE, $transfer->status);
|
||||
$this->assertNotNull($transfer->grace_ends_at);
|
||||
$this->assertTrue($transfer->grace_ends_at->isFuture());
|
||||
$this->assertTrue($transfer->isAccessible());
|
||||
}
|
||||
|
||||
public function test_transfer_past_grace_period_is_deleted(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => (string) Str::uuid(),
|
||||
'name' => 'Delete User',
|
||||
'email' => 'delete+'.uniqid().'@example.com',
|
||||
]);
|
||||
|
||||
Transfer::create([
|
||||
'user_id' => $user->id,
|
||||
'title' => 'Expired',
|
||||
'retention_days' => 30,
|
||||
'paid_until' => now()->subDays(20),
|
||||
'grace_ends_at' => now()->subMinute(),
|
||||
'status' => Transfer::STATUS_GRACE,
|
||||
'storage_bytes' => 1024,
|
||||
]);
|
||||
|
||||
$base = rtrim((string) config('billing.api_url'), '/');
|
||||
Http::fake([
|
||||
$base.'/can-afford*' => Http::response(['affordable' => false]),
|
||||
]);
|
||||
|
||||
$result = app(TransferBillingService::class)->processDueRenewals();
|
||||
|
||||
$this->assertSame(1, $result['deleted']);
|
||||
$this->assertDatabaseHas('transfers', [
|
||||
'title' => 'Expired',
|
||||
'status' => Transfer::STATUS_DELETED,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_successful_renewal_extends_paid_until(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => (string) Str::uuid(),
|
||||
'name' => 'Renew User',
|
||||
'email' => 'renew+'.uniqid().'@example.com',
|
||||
]);
|
||||
|
||||
$transfer = Transfer::create([
|
||||
'user_id' => $user->id,
|
||||
'title' => 'Renew me',
|
||||
'retention_days' => 30,
|
||||
'paid_until' => now()->subMinute(),
|
||||
'status' => Transfer::STATUS_ACTIVE,
|
||||
'storage_bytes' => 1024 * 1024 * 1024,
|
||||
]);
|
||||
|
||||
$this->fakeTransferBillingApi();
|
||||
|
||||
$result = app(TransferBillingService::class)->processDueRenewals();
|
||||
|
||||
$transfer->refresh();
|
||||
$this->assertSame(1, $result['renewed']);
|
||||
$this->assertSame(Transfer::STATUS_ACTIVE, $transfer->status);
|
||||
$this->assertTrue($transfer->paid_until->isFuture());
|
||||
$this->assertNull($transfer->grace_ends_at);
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,18 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\Concerns\FakesTransferBilling;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TransferTest extends TestCase
|
||||
{
|
||||
use FakesTransferBilling;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_authenticated_user_can_create_transfer_with_files(): void
|
||||
{
|
||||
Storage::fake('qr');
|
||||
$this->fakeTransferBillingApi();
|
||||
|
||||
$user = User::create([
|
||||
'public_id' => (string) Str::uuid(),
|
||||
@@ -27,7 +30,6 @@ class TransferTest extends TestCase
|
||||
$response = $this->actingAs($user)->post(route('transfer.transfers.store'), [
|
||||
'title' => 'Project assets',
|
||||
'message' => 'Here are the files.',
|
||||
'retention_days' => 14,
|
||||
'files' => [
|
||||
UploadedFile::fake()->create('brief.pdf', 100, 'application/pdf'),
|
||||
UploadedFile::fake()->create('photo.jpg', 50, 'image/jpeg'),
|
||||
@@ -41,7 +43,8 @@ class TransferTest extends TestCase
|
||||
|
||||
$transfer = Transfer::first();
|
||||
$this->assertNotNull($transfer->qr_code_id);
|
||||
$this->assertSame(14, $transfer->retention_days);
|
||||
$this->assertNotNull($transfer->paid_until);
|
||||
$this->assertTrue($transfer->paid_until->isFuture());
|
||||
}
|
||||
|
||||
public function test_dashboard_requires_auth(): void
|
||||
|
||||
Reference in New Issue
Block a user