@@ -2,6 +2,33 @@
|
||||
|
||||
require_once __DIR__.'/../Support/LandedQaReceipts.php';
|
||||
|
||||
test('estimate contention receipts require all native uniqueness races and explicit estimate effects', function () {
|
||||
$command = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'race-estimate'];
|
||||
$rows = [['old_runtime_rejected_before_balance' => true, 'old_estimate_runtime_rejected' => true,
|
||||
'runtime_landed_version' => 'COMMON-BUDGET-LANDED-COST-QA-v2', 'status' => 503]];
|
||||
foreach (['same_operation', 'conflicting_plan_version', 'same_source_different_plan'] as $scenario) {
|
||||
$rows[] = ['scenario' => $scenario, 'estimate' => true, 'statuses' => $scenario === 'same_operation' ? [200, 200] : [200, 409],
|
||||
'blocked_writers_observed' => 2, 'commands' => 1, 'audits' => 1, 'reserved_minor' => 2000];
|
||||
}
|
||||
$encode = fn ($records) => implode("\n", array_map(fn ($row) => json_encode($row, JSON_THROW_ON_ERROR), $records));
|
||||
expect(landedQaReceiptsVerified($command, $encode($rows)))->toBeTrue();
|
||||
$reconciliation = $rows;
|
||||
foreach ($reconciliation as &$row) {
|
||||
if (isset($row['scenario'])) {
|
||||
$row['reconciliation'] = true;
|
||||
$row['commands'] = 3;
|
||||
$row['reserved_minor'] = 3000;
|
||||
}
|
||||
}
|
||||
unset($row);
|
||||
$reconcileCommand = [...array_slice($command, 0, 3), 'race-estimate-reconcile'];
|
||||
expect(landedQaReceiptsVerified($reconcileCommand, $encode($reconciliation)))->toBeTrue();
|
||||
$reconciliation[1]['reserved_minor'] = 2000;
|
||||
expect(landedQaReceiptsVerified($reconcileCommand, $encode($reconciliation)))->toBeFalse();
|
||||
unset($rows[2]['estimate']);
|
||||
expect(landedQaReceiptsVerified($command, $encode($rows)))->toBeFalse();
|
||||
});
|
||||
|
||||
test('separate Pest kernels cannot reuse one disposable database with persistent migration functions', function () {
|
||||
$pest = ['php', 'vendor/bin/pest', 'tests/Feature/ImportTariffCodesTest.php'];
|
||||
expect(landedQaCommandIsolationVerified([$pest]))->toBeTrue();
|
||||
@@ -38,8 +65,42 @@ test('restore completion requires the restored replay original snapshot and data
|
||||
expect(landedQaReceiptsVerified($command, $proof))->toBeFalse();
|
||||
$databaseOnly = $proof."\n".json_encode(['isolated_restore_removed' => true], JSON_THROW_ON_ERROR);
|
||||
expect(landedQaReceiptsVerified($command, $databaseOnly))->toBeFalse();
|
||||
$privateFiles = ['private_original_versions_restored' => 2, 'source_loss_detected' => true,
|
||||
$privateFiles = ['private_original_versions_restored' => 6, 'typed_dossier_versions_restored' => 4, 'selected_party_versions_restored' => 2, 'source_loss_detected' => true,
|
||||
'separate_private_root_restored' => true, 'native_authorized_evidence_resolved' => true];
|
||||
expect(landedQaReceiptsVerified($command, $databaseOnly."\n".json_encode($privateFiles, JSON_THROW_ON_ERROR)))->toBeTrue();
|
||||
$estimateCommand = [...array_slice($command, 0, 3), 'import-estimates'];
|
||||
$existingRecovery = $databaseOnly."\n".json_encode($privateFiles, JSON_THROW_ON_ERROR);
|
||||
expect(landedQaReceiptsVerified($estimateCommand, $existingRecovery))->toBeFalse();
|
||||
expect(landedQaReceiptsVerified($estimateCommand, $existingRecovery."\n".json_encode([
|
||||
'estimate_source_remainder_restored' => 1000, 'estimate_original_replay_without_effects' => true,
|
||||
], JSON_THROW_ON_ERROR)))->toBeTrue();
|
||||
$missingTyped = $privateFiles;
|
||||
unset($missingTyped['typed_dossier_versions_restored']);
|
||||
expect(landedQaReceiptsVerified($command, $databaseOnly."\n".json_encode($missingTyped, JSON_THROW_ON_ERROR)))->toBeFalse();
|
||||
$missingParty = $privateFiles;
|
||||
unset($missingParty['selected_party_versions_restored']);
|
||||
expect(landedQaReceiptsVerified($command, $databaseOnly."\n".json_encode($missingParty, JSON_THROW_ON_ERROR)))->toBeFalse();
|
||||
expect(landedQaReceiptsVerified(['php', 'vendor/bin/pest', '--compact'], '{"tool":"pest","result":"passed","tests":1,"passed":0,"skipped":1}'))->toBeFalse();
|
||||
});
|
||||
|
||||
test('dossier contention requires both races one original and verified bytes', function () {
|
||||
$command = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'race-dossier'];
|
||||
$rows = [];
|
||||
foreach (['same_operation', 'same_version'] as $scenario) {
|
||||
$rows[] = ['scenario' => $scenario, 'statuses' => $scenario === 'same_operation' ? [200, 200] : [200, 409],
|
||||
'blocked_writers_observed' => 2, 'documents_created' => 1, 'audits' => 1, 'files_created' => 1, 'all_originals_verified' => true];
|
||||
}
|
||||
$encode = fn ($records) => implode("\n", array_map(fn ($row) => json_encode($row, JSON_THROW_ON_ERROR), $records));
|
||||
expect(landedQaReceiptsVerified($command, $encode($rows)))->toBeTrue();
|
||||
expect(landedQaReceiptsVerified($command, $encode([$rows[0]])))->toBeFalse();
|
||||
$rows[1]['files_created'] = 2;
|
||||
expect(landedQaReceiptsVerified($command, $encode($rows)))->toBeFalse();
|
||||
$partyCommand = ['php', 'worker.php', 'compras_receipts_test_000000000001', 'race-party'];
|
||||
foreach ($rows as &$row) {
|
||||
$row['files_created'] = 0;
|
||||
}
|
||||
unset($row);
|
||||
expect(landedQaReceiptsVerified($partyCommand, $encode($rows)))->toBeTrue();
|
||||
$rows[1]['files_created'] = 1;
|
||||
expect(landedQaReceiptsVerified($partyCommand, $encode($rows)))->toBeFalse();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use App\Services\OrderPartsReference;
|
||||
|
||||
test('foreign partial orders retain the original origin rate and cumulative cent remainder', function () {
|
||||
$first = OrderPartsReference::portion(0, 0, 1, 1, '1.5');
|
||||
$second = OrderPartsReference::portion(1, 1, 1, 1, '1.5');
|
||||
expect($first)->toBe(['subtotal_minor' => 2, 'tax_minor' => 2, 'total_minor' => 4])
|
||||
->and($second)->toBe(['subtotal_minor' => 1, 'tax_minor' => 1, 'total_minor' => 2])
|
||||
->and($first['total_minor'] + $second['total_minor'])->toBe(6);
|
||||
});
|
||||
|
||||
test('consolidation preserves separate origin rates instead of averaging them', function () {
|
||||
$a = OrderPartsReference::portion(0, 0, 100, 16, '63.25');
|
||||
$b = OrderPartsReference::portion(0, 0, 200, 32, '64.75');
|
||||
expect($a)->toBe(['subtotal_minor' => 6325, 'tax_minor' => 1012, 'total_minor' => 7337])
|
||||
->and($b)->toBe(['subtotal_minor' => 12950, 'tax_minor' => 2072, 'total_minor' => 15022])
|
||||
->and($a['total_minor'] + $b['total_minor'])->toBe(22359);
|
||||
});
|
||||
|
||||
test('partial invoices within a partial order preserve the source offset', function () {
|
||||
$order = OrderPartsReference::portion(1, 1, 3, 2, '1.5');
|
||||
$first = OrderPartsReference::portion(1, 1, 1, 1, '1.5');
|
||||
$second = OrderPartsReference::portion(2, 2, 2, 1, '1.5');
|
||||
foreach (['subtotal_minor', 'tax_minor', 'total_minor'] as $field) {
|
||||
expect($first[$field] + $second[$field])->toBe($order[$field]);
|
||||
}
|
||||
});
|
||||
|
||||
test('invalid reference bases are refused before arithmetic', function (int $before, int $net, string $rate) {
|
||||
expect(fn () => OrderPartsReference::portion($before, 0, $net, 0, $rate))->toThrow(InvalidArgumentException::class);
|
||||
})->with([[-1, 1, '1'], [0, -1, '1'], [PHP_INT_MAX, 1, '1'], [0, 1, '0'], [0, 1, '-1'], [0, 100000000000000, '2']]);
|
||||
Reference in New Issue
Block a user