commit compras4 2911
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-29 16:56:53 +02:00
parent 30bfb1a773
commit a935499d64
22 changed files with 1134 additions and 31 deletions
@@ -21,6 +21,9 @@ use App\Services\StandaloneArtifact;
use App\Services\StandaloneRuntime;
use App\Services\SupplierPayables;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
@@ -106,12 +109,13 @@ test('standalone candidate closes an old reservation cycle and reserves a revise
->and(DB::table('stock_movements')->count())->toBe(0)->and(DB::table('gl_journals')->count())->toBe(0);
});
test('standalone candidate returns an expired request to its owner and requires new approvals and reservation on resubmission', function () {
test('standalone candidate returns an expired request to its owner and requires new approvals and reservation on resubmission', function (bool $scheduled) {
$staff = fn (PurchasingRole $role) => User::factory()->create(['tenant_id' => $this->f['tenant']->id,
'department_id' => $this->f['department']->id, 'purchasing_role' => $role]);
$admin = $staff(PurchasingRole::Admin);
$head = $staff(PurchasingRole::DepartmentHead);
$finance = $staff(PurchasingRole::Finance);
$reviewer = $scheduled ? $staff(PurchasingRole::Procurement) : null;
$owner = $this->f['issuer'];
$this->f['tenant']->update(['first_limit_minor' => 5000, 'second_limit_minor' => 20000]);
Budget::query()->create(['tenant_id' => $owner->tenant_id, 'cost_center_id' => $this->f['r']->cost_center_id,
@@ -120,7 +124,7 @@ test('standalone candidate returns an expired request to its owner and requires
$expiry = app(RequisitionExpiry::class);
$this->actingAs($admin);
$expiry->savePolicy($admin, ['operation_key' => (string) Str::uuid(), 'version' => 0, 'enabled' => true,
'levels' => array_map(fn ($role) => ['role' => $role, 'expire_minutes' => 30, 'reminder_minutes' => null,
'levels' => array_map(fn ($role) => ['role' => $role, 'expire_minutes' => 30, 'reminder_minutes' => $scheduled ? 10 : null,
'escalation_minutes' => null, 'profile_ids' => []], ['department_head', 'procurement']),
'reason' => 'Explicit synthetic elapsed deadlines for candidate verification']);
$this->actingAs($owner);
@@ -149,12 +153,41 @@ test('standalone candidate returns an expired request to its owner and requires
$workflow->decide($head, $request, 'approved', 'Independent synthetic first-stage decision', (string) Str::uuid(), $request->process_version);
$request->refresh();
$approved = $request->steps()->where('decision', 'approved')->sole()->toArray();
$this->travel(31)->minutes();
$tick = function () {
$previous = request();
Auth::forgetGuards();
$this->app->instance('request', Request::create('/'));
try {
expect(auth()->check())->toBeFalse()->and(request()->hasSession())->toBeFalse();
expect(Artisan::call('sgc:approval-deadlines-tick'))->toBe(0);
} finally {
$this->app->instance('request', $previous);
}
};
if ($scheduled) {
$this->travel(11)->minutes();
$tick();
expect($request->fresh()->status)->toBe('pending')
->and(DB::table('workflow_notices')->where('recipient_id', $reviewer->id)->where('event_kind', 'reminder')->count())->toBe(1);
$notices = DB::table('workflow_notices')->orderBy('id')->get()->toJson();
$tick();
expect(DB::table('workflow_notices')->orderBy('id')->get()->toJson())->toBe($notices);
$this->travel(20)->minutes();
} else {
$this->travel(31)->minutes();
}
$this->actingAs($owner);
$deadline = $expiry->deadline($request);
$this->actingAs($owner);
$body = ['basis_hash' => $deadline['basis_hash'], 'operation_key' => (string) Str::uuid(), 'process_version' => $request->process_version];
$this->postJson('/requisicoes/'.$request->id.'/expiracao', $body)->assertRedirect();
$this->postJson('/requisicoes/'.$request->id.'/expiracao', $body)->assertRedirect();
if ($scheduled) {
$tick();
$tick();
$this->actingAs($owner);
} else {
$this->postJson('/requisicoes/'.$request->id.'/expiracao', $body)->assertRedirect();
$this->postJson('/requisicoes/'.$request->id.'/expiracao', $body)->assertRedirect();
}
$request->refresh();
expect($request->status)->toBe('draft')->and($request->requester_id)->toBe($owner->id)->and($request->approval_cycle)->toBe(2)
->and($request->allSteps()->whereKey($approved['id'])->firstOrFail()->toArray())->toBe($approved)
@@ -172,7 +205,7 @@ test('standalone candidate returns an expired request to its owner and requires
->and($request->steps()->where('decision', 'approved')->count())->toBe(0)->and($request->allSteps()->count())->toBe(4)
->and((int) DB::table('budget_entries')->where('requisition_id', $request->id)->where('requisition_cycle', 2)->sum('reserved_minor'))->toBe(12000)
->and(DB::table('gl_journals')->count())->toBe(0)->and(DB::table('stock_movements')->count())->toBe(0);
});
})->with(['interactive' => false, 'scheduled-command' => true]);
test('standalone financial pages use explicit read rights and refuse writes or disabled modules', function () {
$finance = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id,