commit compras4 2711
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-27 19:13:31 +02:00
parent 9cf9764710
commit 7486007fcf
41 changed files with 1270 additions and 66 deletions
@@ -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();
});