+49
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
// Run in its own kernel: development and published writers deliberately share one canonical class.
|
||||
|
||||
use App\Enums\PurchasingRole;
|
||||
use App\Models\GoodsReceipt;
|
||||
use App\Models\PurchaseAward;
|
||||
@@ -9,11 +11,13 @@ use App\Models\User;
|
||||
use App\Services\ConflictGuard;
|
||||
use App\Services\InventoryDispositions;
|
||||
use App\Services\InventoryLots;
|
||||
use App\Services\InventoryReversals;
|
||||
use App\Services\InvoiceWorkflow;
|
||||
use App\Services\ReceiptStockMovement;
|
||||
use App\Services\ReceiptWorkflow;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use App\Services\StockWorkflow;
|
||||
use App\Services\SupplyCoordination;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@@ -181,3 +185,48 @@ test('lot allocation and quality follow converted physical quantities rather tha
|
||||
expect($context['reconciled'])->toBeTrue()->and($context['lots'][0]['quantity_milli'])->toBe(24000)
|
||||
->and($context['usable_milli'])->toBe(0);
|
||||
});
|
||||
|
||||
test('confirmed delivery feeds replenishment in base units and supplies the same frozen factor to receipt', function () {
|
||||
supplyGrant($this->f['receiver'], ['warehouse', 'supply_delivery']);
|
||||
$this->actingAs($this->f['receiver']);
|
||||
$coordination = app(SupplyCoordination::class);
|
||||
$data = ['stock_item_id' => $this->f['stock']->id, 'warehouse_id' => $this->f['warehouse']->id, 'purchase_order_item_id' => $this->f['line']->id,
|
||||
'quantity_milli' => 2000, 'expected_on' => today()->addDay()->toDateString(), 'confirmed_on' => today()->toDateString(),
|
||||
'evidence' => 'Confirmação sintética de duas caixas.', 'conversion' => $this->conversion];
|
||||
$record = $coordination->save($this->f['receiver'], 'delivery', supplyInput($data));
|
||||
expect($coordination->remainingDelivery($record))->toBe(24000)
|
||||
->and($coordination->events($this->f['stock']->id, $this->f['warehouse']->id, today()->toDateString())['receipts'][0]['quantity'])->toBe(24000);
|
||||
$body = $this->body;
|
||||
unset($body['items'][0]['conversion']);
|
||||
$body['items'][0]['received_quantity'] = $body['items'][0]['accepted_quantity'] = '1.500';
|
||||
$this->postJson($this->url, $body)->assertCreated();
|
||||
expect($coordination->remainingDelivery($record))->toBe(6000)
|
||||
->and($coordination->events($this->f['stock']->id, $this->f['warehouse']->id, today()->toDateString())['receipts'][0]['quantity'])->toBe(6000)
|
||||
->and(StockMovement::query()->sole()->quantity_milli)->toBe(18000);
|
||||
$bad = $data;
|
||||
$bad['conversion']['numerator'] = '24';
|
||||
expect(fn () => $coordination->save($this->f['receiver'], 'delivery', supplyInput($bad, 'save', $record)))->toThrow(ValidationException::class);
|
||||
});
|
||||
|
||||
test('receipt reversal negates the physical movement and restores documentary pending quantity without rewriting originals', function () {
|
||||
$this->postJson($this->url, $this->body)->assertCreated();
|
||||
$line = GoodsReceipt::query()->sole()->items()->sole();
|
||||
$original = StockMovement::query()->sole();
|
||||
supplyGrant($this->f['receiver'], ['warehouse', 'inventory_reversal_prepare']);
|
||||
supplyGrant($this->f['issuer'], ['inventory_reversal_review']);
|
||||
$workflow = app(InventoryReversals::class);
|
||||
$this->actingAs($this->f['receiver']);
|
||||
$draft = $workflow->save($this->f['receiver'], supplyInput(['reference' => 'QA-BOX-REVERSAL', 'source_kind' => 'receipt', 'receipt_item_id' => $line->id]));
|
||||
$this->actingAs($this->f['issuer']);
|
||||
$approved = $workflow->save($this->f['issuer'], supplyInput([], 'approve', $draft));
|
||||
$this->actingAs($this->f['receiver']);
|
||||
$payload = supplyInput(['event_on' => today()->toDateString(), 'evidence' => 'Prova sintética de estorno das duas caixas.'], 'execute', $approved);
|
||||
$executed = $workflow->save($this->f['receiver'], $payload);
|
||||
expect($workflow->save($this->f['receiver'], $payload)->id)->toBe($executed->id)
|
||||
->and(StockMovement::query()->count())->toBe(2)
|
||||
->and(StockMovement::query()->where('stock_operation_id', $executed->data['stock_operation_id'])->sole()->quantity_milli)->toBe(-24000)
|
||||
->and($original->fresh()->quantity_milli)->toBe(24000)
|
||||
->and($line->fresh()->accepted_milli)->toBe(2000)
|
||||
->and(app(ReceiptWorkflow::class)->progress($this->f['order'])['lines'][0]['delivery_pending_milli'])->toBe(2000)
|
||||
->and(app(StockWorkflow::class)->balance($this->f['stock']->id, $this->f['warehouse']->id)['quantity'])->toBe(0);
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class ReceiptQuantityConversionIsolationTest extends TestCase
|
||||
{
|
||||
public function test_conversion_contract_in_an_isolated_kernel_without_replacing_the_published_writer(): void
|
||||
{
|
||||
// The normal Feature suite may already have loaded the published writer. Never replace it in process.
|
||||
$process = new Process([PHP_BINARY, 'vendor/bin/pest', '--compact', 'tests/Conversion/ReceiptQuantityConversionTest.php'], base_path(), [
|
||||
'APP_ENV' => 'testing', 'DB_CONNECTION' => 'sqlite', 'DB_DATABASE' => ':memory:', 'DB_URL' => false,
|
||||
'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array', 'MAIL_MAILER' => 'array', 'QUEUE_CONNECTION' => 'sync', 'BROADCAST_CONNECTION' => 'null',
|
||||
], timeout: 120);
|
||||
$process->run();
|
||||
$this->assertTrue($process->isSuccessful(), $process->getOutput().$process->getErrorOutput());
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@ pest()->extend(TestCase::class)
|
||||
->use(RefreshDatabase::class)
|
||||
->in('Feature');
|
||||
|
||||
// A separate invocation is required for the unpublished inventory contract; Feature has a process wrapper.
|
||||
pest()->extend(TestCase::class)->use(RefreshDatabase::class)->in('Conversion');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expectations
|
||||
|
||||
Reference in New Issue
Block a user