@@ -1794,12 +1794,32 @@ test('native partial-order Finance amendment exposes a recoverable form and pres
|
||||
$this->post('/ordens/'.$order->id.'/reafectacao', $data)->assertConflict();
|
||||
});
|
||||
|
||||
test('native partial-order issuance commits only forty then sixty and preserves replay and quantity caps', function () {
|
||||
test('native partial-order issuance commits only forty then sixty and preserves replay and quantity caps', function (int $cycle) {
|
||||
if (! method_exists(BudgetControl::class, 'commitOrderParts')) {
|
||||
$this->markTestSkipped('Explicit unpublished common source required.');
|
||||
}
|
||||
(new PurchaseOrder)->fill(['number' => 'Unpersisted legacy metadata warmup']);
|
||||
(new PurchaseOrderItem)->fill(['description' => 'Unpersisted legacy metadata warmup']);
|
||||
if ($cycle === 2) {
|
||||
if (! method_exists(BudgetControl::class, 'beginRequisitionCycle')) {
|
||||
$this->markTestSkipped('Explicit cycle-capable common QA source required.');
|
||||
}
|
||||
budgetDistributionFixtureSchema();
|
||||
(require __DIR__.'/../../database/qa-migrations/2026_11_22_000007_create_budget_order_parts.php')->up();
|
||||
(require __DIR__.'/../../database/qa-migrations/2026_11_22_000008_create_purchase_order_sources.php')->up();
|
||||
(require __DIR__.'/../../database/qa-migrations/2026_11_27_000001_add_requisition_cycles.php')->up();
|
||||
config(['requisition-expiry.qa_enabled' => true]);
|
||||
$engine = app(CommonBudget::class)->for($this->buyer, [$this->r->id => 1]);
|
||||
$engine->beginRequisitionCycle($this->r->id, 1, (string) Str::uuid());
|
||||
$engine->closeRequisitionCycle($this->r->id, 1, (string) Str::uuid());
|
||||
$this->r->setAttribute('approval_cycle', 2);
|
||||
$this->r->save();
|
||||
$step = $this->r->steps()->make(['tenant_id' => $this->tenant->id, 'position' => 1, 'role' => 'department_head',
|
||||
'decision' => 'approved', 'approver_id' => $this->head->id, 'decided_at' => now()]);
|
||||
$step->setAttribute('approval_cycle', 2);
|
||||
$step->save();
|
||||
app(CommonBudget::class)->for($this->buyer, [$this->r->id => 2])->beginRequisitionCycle($this->r->id, 2, (string) Str::uuid());
|
||||
}
|
||||
$award = nativeOrderPartsAward($this);
|
||||
$input = nativeOrderPartsInput($this, $award, '0.400', 0);
|
||||
$workflow = app(OrderPartsWorkflow::class);
|
||||
@@ -1824,7 +1844,7 @@ test('native partial-order issuance commits only forty then sixty and preserves
|
||||
$this->withoutVite();
|
||||
$this->get('/ordens/preparar')->assertOk()->assertViewHas('page', fn (array $page) => $page['props']['candidates']['data'] === []);
|
||||
$this->post('/adjudicacoes/'.$award->id.'/emitir')->assertConflict();
|
||||
});
|
||||
})->with([1, 2]);
|
||||
|
||||
test('native partial-order issuance rolls back the document and all financial effects when its audit fails', function () {
|
||||
if (! method_exists(BudgetControl::class, 'commitOrderParts')) {
|
||||
|
||||
@@ -159,6 +159,40 @@ test('import assumptions release in the old cycle before a separately identified
|
||||
->and(DB::table('budget_landed_entries')->orderBy('id')->limit(2)->get()->toJson())->toBe($old);
|
||||
});
|
||||
|
||||
test('configured escalation alerts respect current membership and never delegate the pending approval', function () {
|
||||
$owner = $this->f['issuer'];
|
||||
$head = User::factory()->create(['tenant_id' => $owner->tenant_id, 'department_id' => $owner->department_id, 'purchasing_role' => PurchasingRole::Configured]);
|
||||
$viewer = User::factory()->create(['tenant_id' => $owner->tenant_id, 'department_id' => $owner->department_id, 'purchasing_role' => PurchasingRole::Configured]);
|
||||
$profiles = [];
|
||||
foreach ([[$owner, ['admin', 'requester']], [$head, ['department_head']], [$viewer, ['procurement']]] as [$person, $permissions]) {
|
||||
$profile = DB::table('organization_profiles')->insertGetId(['tenant_id' => $owner->tenant_id, 'name' => 'Synthetic profile '.$person->id,
|
||||
'permissions' => json_encode($permissions), 'work_contexts' => json_encode(['procurement.internal']), 'version' => 1]);
|
||||
DB::table('organization_memberships')->insert(['tenant_id' => $owner->tenant_id, 'user_id' => $person->id, 'profile_id' => $profile, 'maintenance' => false]);
|
||||
$profiles[$person->id] = $profile;
|
||||
}
|
||||
DB::table('organization_access')->insert(['tenant_id' => $owner->tenant_id, 'active' => true, 'version' => 1]);
|
||||
$this->actingAs($owner);
|
||||
$expiry = app(RequisitionExpiry::class);
|
||||
$expiry->savePolicy($owner, ['operation_key' => (string) Str::uuid(), 'version' => 0, 'enabled' => true,
|
||||
'levels' => [['role' => 'department_head', 'expire_minutes' => 30, 'reminder_minutes' => 10, 'escalation_minutes' => 20, 'profile_ids' => [$profiles[$viewer->id]]]],
|
||||
'reason' => 'Explicit synthetic escalation to an existing viewer profile']);
|
||||
$workflow = app(RequisitionWorkflow::class);
|
||||
$request = $workflow->save($owner, ['operation_key' => (string) Str::uuid(), 'cost_center_id' => $this->f['r']->cost_center_id,
|
||||
'priority' => 'normal', 'needed_by' => today()->addWeek()->toDateString(), 'justification' => 'Synthetic configured deadline and notification recipients',
|
||||
'items' => [['description' => 'Synthetic item', 'category' => 'Material', 'purchase_type' => 'consumable', 'quantity' => '1.000', 'unit' => 'un', 'unit_price' => '100.00', 'tax_rate' => '0.00']]]);
|
||||
$workflow->submit($owner, $request, (string) Str::uuid(), $request->process_version);
|
||||
$request->refresh();
|
||||
$this->travel(20)->minutes();
|
||||
$result = $expiry->check($owner, $request, ['operation_key' => (string) Str::uuid(), 'process_version' => $request->process_version]);
|
||||
expect($result['escalation_eligible'])->toBe(1)->and($result['notices_created'])->toBe(2);
|
||||
$this->actingAs($viewer);
|
||||
expect(array_column(app(WorkflowNotices::class)->visible($viewer), 'kind'))->toContain('escalation')
|
||||
->and($request->canDecide($viewer))->toBeFalse();
|
||||
DB::table('organization_memberships')->where('user_id', $viewer->id)->update(['expires_at' => now()->subSecond()]);
|
||||
expect(app(WorkflowNotices::class)->visible($viewer))->toBe([]);
|
||||
$this->travelBack();
|
||||
});
|
||||
|
||||
test('native expiry returns the same request and preserves the approved stage before a fresh revised submission and reservation', function () {
|
||||
$admin = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id, 'purchasing_role' => PurchasingRole::Admin]);
|
||||
$head = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id, 'purchasing_role' => PurchasingRole::DepartmentHead]);
|
||||
@@ -179,6 +213,13 @@ test('native expiry returns the same request and preserves the approved stage be
|
||||
$workflow->submit($owner, $request, (string) Str::uuid(), $request->process_version);
|
||||
$request->refresh();
|
||||
$this->actingAs($head);
|
||||
$this->travel(10)->minutes();
|
||||
$check = ['operation_key' => (string) Str::uuid(), 'process_version' => $request->process_version];
|
||||
$firstCheck = $expiry->check($head, $request, $check);
|
||||
expect($firstCheck['notices_created'])->toBe(1)
|
||||
->and($expiry->check($head, $request, $check))->toBe($firstCheck)
|
||||
->and($expiry->check($head, $request, ['operation_key' => (string) Str::uuid(), 'process_version' => $request->process_version])['notices_created'])->toBe(0)
|
||||
->and(array_column(app(WorkflowNotices::class)->visible($head), 'kind'))->toContain('reminder');
|
||||
$workflow->decide($head, $request, 'approved', 'Conferência sintética do primeiro nível', (string) Str::uuid(), $request->process_version);
|
||||
$request->refresh();
|
||||
$approved = $request->steps()->where('decision', 'approved')->sole()->toArray();
|
||||
@@ -216,5 +257,13 @@ test('native expiry returns the same request and preserves the approved stage be
|
||||
$notices = app(WorkflowNotices::class)->visible($owner);
|
||||
expect(array_column($notices, 'outcome'))->toContain('expired')
|
||||
->and(DB::table('workflow_notices')->where('requisition_id', $request->id)->where('recipient_id', $owner->id)->count())->toBe(1);
|
||||
$this->travel(31)->minutes();
|
||||
$check = ['operation_key' => (string) Str::uuid(), 'process_version' => $request->process_version];
|
||||
$this->postJson('/requisicoes/'.$request->id.'/prazos/verificar', $check)->assertRedirect();
|
||||
$this->postJson('/requisicoes/'.$request->id.'/prazos/verificar', $check)->assertRedirect();
|
||||
$request->refresh();
|
||||
expect($request->status)->toBe('draft')->and($request->approval_cycle)->toBe(3)
|
||||
->and((int) DB::table('budget_entries')->where('requisition_id', $request->id)->sum('reserved_minor'))->toBe(0)
|
||||
->and(SupplyRecord::query()->where('kind', 'req_expiration')->count())->toBe(2);
|
||||
$this->travelBack();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user