25 lines
1.6 KiB
PHP
25 lines
1.6 KiB
PHP
<?php
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use App\Services\{ConflictGuard,ReceiptStockMovement};
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
final class ReceiptAdapterReplayTest extends TestCase
|
|
{
|
|
public function test_final_adapter_reuses_existing_movement_without_a_second_effect(): void
|
|
{
|
|
$i=DB::selectOne("SELECT current_database() AS name,current_user AS role,current_setting('cluster_name') AS cluster");
|
|
$this->assertMatchesRegularExpression('/^compras_receipts_test_([a-f0-9]{12})$/D',$i->name);
|
|
$this->assertSame('stock_receipt_qa_'.substr($i->name,-12),$i->role);$this->assertSame('sgf_modular_regression_'.getenv('SGF_ISOLATED_REGRESSION_RUN'),$i->cluster);
|
|
$root=realpath((string)getenv('STOCK_RECEIPT_ROOT'));$this->assertNotFalse($root);
|
|
$proof=json_decode(file_get_contents($root.'/receipt-results.json'),true,512,JSON_THROW_ON_ERROR);
|
|
$row=DB::table('stock_movements')->where('tenant_id',$proof['link']['tenant'])->where('id',$proof['link']['movement'])->first();$this->assertNotNull($row);
|
|
$actor=User::findOrFail($row->moved_by);$this->actingAs($actor);$count=DB::table('stock_movements')->count();
|
|
$hash=json_decode($row->snapshot,true)['inventory_source_hash'];
|
|
$result=DB::transaction(function()use($actor,$row,$hash){app(ConflictGuard::class)->lockCompany($actor);return app(ReceiptStockMovement::class)->for($actor)->write($row->goods_receipt_item_id,$hash);});
|
|
$this->assertTrue($result['replayed']);$this->assertSame((int)$row->id,$result['movement_id']);$this->assertSame($count,DB::table('stock_movements')->count());
|
|
}
|
|
}
|