@@ -7,10 +7,12 @@ use App\Models\Requisition;
|
||||
use App\Models\SupplyRecord;
|
||||
use App\Models\User;
|
||||
use App\Services\CommonBudget;
|
||||
use App\Services\ProcurementOperationalInsights;
|
||||
use App\Services\RequisitionBudgetDistributions;
|
||||
use App\Services\RequisitionExpiry;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use App\Services\WorkflowNotices;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
@@ -193,7 +195,7 @@ test('configured escalation alerts respect current membership and never delegate
|
||||
$this->travelBack();
|
||||
});
|
||||
|
||||
test('native expiry returns the same request and preserves the approved stage before a fresh revised submission and reservation', function () {
|
||||
test('native expiry returns the same request and preserves the approved stage before a fresh revised submission and reservation', function (string $secondOutcome) {
|
||||
$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]);
|
||||
$buyer = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id, 'purchasing_role' => PurchasingRole::Procurement]);
|
||||
@@ -257,6 +259,32 @@ 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);
|
||||
if ($secondOutcome === 'approved') {
|
||||
$this->travel(2)->minutes();
|
||||
$this->actingAs($head);
|
||||
$workflow->decide($head, $request, 'approved', 'Conferência sintética do novo ciclo', (string) Str::uuid(), $request->process_version);
|
||||
$request->refresh();
|
||||
$this->travel(3)->minutes();
|
||||
$this->actingAs($buyer);
|
||||
$workflow->decide($buyer, $request, 'approved', 'Conferência final sintética do novo ciclo', (string) Str::uuid(), $request->process_version);
|
||||
$insights = app(ProcurementOperationalInsights::class)->build(Requisition::query()->whereKey($request->id), CarbonImmutable::now());
|
||||
expect($request->fresh()->status)->toBe('approved')->and($insights['approval_times'])->toMatchArray([
|
||||
'measured' => 1, 'unknown' => 0, 'total_seconds' => 300, 'min_seconds' => 300, 'max_seconds' => 300]);
|
||||
$this->travelBack();
|
||||
|
||||
return;
|
||||
}
|
||||
if ($secondOutcome === 'rejected') {
|
||||
$this->actingAs($head);
|
||||
$workflow->decide($head, $request, 'rejected', 'Rejeição sintética da revisão no novo ciclo', (string) Str::uuid(), $request->process_version);
|
||||
expect($request->fresh()->status)->toBe('rejected')
|
||||
->and((int) DB::table('budget_entries')->where('requisition_id', $request->id)->sum('reserved_minor'))->toBe(0)
|
||||
->and($request->allSteps()->whereKey($approved['id'])->firstOrFail()->toArray())->toBe($approved)
|
||||
->and(SupplyRecord::query()->where('kind', 'req_expiration')->count())->toBe(1);
|
||||
$this->travelBack();
|
||||
|
||||
return;
|
||||
}
|
||||
$this->travel(31)->minutes();
|
||||
$check = ['operation_key' => (string) Str::uuid(), 'process_version' => $request->process_version];
|
||||
$this->postJson('/requisicoes/'.$request->id.'/prazos/verificar', $check)->assertRedirect();
|
||||
@@ -266,4 +294,4 @@ test('native expiry returns the same request and preserves the approved stage be
|
||||
->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();
|
||||
});
|
||||
})->with(['expired', 'rejected', 'approved']);
|
||||
|
||||
Reference in New Issue
Block a user