feat(refund): enhance refund process by adding backfill for refunded_units and updating inventory restoration logic
This commit is contained in:
@@ -23,6 +23,7 @@ use Database\Seeders\AttributeSeeder;
|
||||
use Database\Seeders\AuthorizationSeeder;
|
||||
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
@@ -254,7 +255,7 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
$this->assertSame(1, $inventory->fresh()->refunded_units);
|
||||
}
|
||||
|
||||
public function test_existing_refunds_do_not_increment_the_new_refunded_units_counter(): void
|
||||
public function test_backfill_restores_existing_refunds_before_new_refunds(): void
|
||||
{
|
||||
$tenant = $this->createTenant('ticket-historical-refund');
|
||||
$tenant->update([
|
||||
@@ -280,6 +281,20 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
$this->assertSame(0, $inventory->fresh()->refunded_units);
|
||||
$this->assertSame(0, $inventory->fresh()->real_stock);
|
||||
|
||||
Log::shouldReceive('info')->once()->with('inventory.refunded_units_backfill.completed', [
|
||||
'refunds_seen' => 1,
|
||||
'refunds_applied' => 1,
|
||||
'bundles_skipped' => 0,
|
||||
'inventories_updated' => 1,
|
||||
'refunded_units_added' => 1,
|
||||
'real_stock_added' => 1,
|
||||
]);
|
||||
$backfill = require database_path('migrations/2026_09_16_000100_backfill_refunded_units.php');
|
||||
$backfill->up();
|
||||
|
||||
$this->assertSame(1, $inventory->fresh()->refunded_units);
|
||||
$this->assertSame(1, $inventory->fresh()->real_stock);
|
||||
|
||||
$newTicket = $this->createTicket($tenant, $admin, [
|
||||
'source_purchase_item_id' => $purchaseItem->id,
|
||||
'source_catalog_item_id' => $historicalTicket->source_catalog_item_id,
|
||||
@@ -289,8 +304,8 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
])->assertOk();
|
||||
|
||||
$this->assertSame(2, $inventory->fresh()->sold_units);
|
||||
$this->assertSame(1, $inventory->fresh()->refunded_units);
|
||||
$this->assertSame(1, $inventory->fresh()->real_stock);
|
||||
$this->assertSame(2, $inventory->fresh()->refunded_units);
|
||||
$this->assertSame(2, $inventory->fresh()->real_stock);
|
||||
}
|
||||
|
||||
public function test_it_records_different_refund_types_for_tickets_from_the_same_purchase_item(): void
|
||||
|
||||
Reference in New Issue
Block a user