@@ -2,9 +2,14 @@
|
||||
|
||||
use App\Enums\PurchasingRole;
|
||||
use App\Models\Budget;
|
||||
use App\Models\CostCenter;
|
||||
use App\Models\Department;
|
||||
use App\Models\Requisition;
|
||||
use App\Models\User;
|
||||
use App\Services\CapitalAssignments;
|
||||
use App\Services\CapitalRegister;
|
||||
use App\Services\CommonBudget;
|
||||
use App\Services\EquipmentWorkflow;
|
||||
use App\Services\RequisitionApprovalLevels;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use App\Services\WorkflowNotices;
|
||||
@@ -111,6 +116,65 @@ function configuredDecision($test, User $actor, Requisition $record, string $dec
|
||||
$test->actingAs($actor)->postJson('/requisicoes/'.$record->id.'/decidir', ['operation_key' => (string) Str::uuid(), 'process_version' => $record->fresh()->process_version, 'decision' => $decision, 'comment' => 'Fundamento sintético da decisão.'])->assertRedirect();
|
||||
}
|
||||
|
||||
test('classified machinery follows an explicitly designated direction level at any value through the existing contract', function () {
|
||||
config(['capital-register.qa_enabled' => true]);
|
||||
$tenant = $this->f['tenant']->id;
|
||||
$this->f['tenant']->update(['first_limit_minor' => 100000000, 'second_limit_minor' => 200000000]);
|
||||
$direction = approvalLevelProfile($tenant, 'Direcção de maquinaria QA', ['requisition_approve']);
|
||||
approvalLevelMember($this->approvers[0], $direction);
|
||||
$this->plan['levels'] = [[...$this->plan['levels'][0], 'name' => 'Direcção para maquinaria', 'profile_ids' => [$direction],
|
||||
'procurement_categories' => ['capital_equipment']]];
|
||||
$this->postJson('/administracao/parametrizacao/approval_levels', $this->plan)->assertRedirect();
|
||||
$body = $this->body;
|
||||
$centre = CostCenter::query()->create(['tenant_id' => $tenant, 'department_id' => $this->admin->department_id,
|
||||
'code' => 'CAP-DIR-QA', 'name' => 'Centro sintético de investimento']);
|
||||
$this->actingAs($this->financier);
|
||||
$budget = app(CommonBudget::class)->for($this->financier)->create(['cost_center_id' => $centre->id,
|
||||
'year' => (int) now()->year, 'kind' => 'investment', 'amount_minor' => 1000000, 'includes_tax' => true,
|
||||
'reason' => 'Dotação exclusivamente sintética para circuito de capital']);
|
||||
$this->actingAs($this->admin);
|
||||
app(CommonBudget::class)->for($this->admin)->approve($budget);
|
||||
$body['cost_center_id'] = $centre->id;
|
||||
$body['items'][0] = [...$body['items'][0], 'purchase_type' => 'equipment', 'production_area' => 'Produção QA',
|
||||
'procurement_category' => 'capital_equipment', 'category_reason' => 'Investimento exclusivamente sintético para aprovação multinível'];
|
||||
$this->postJson('/requisicoes', $body)->assertRedirect();
|
||||
$request = Requisition::query()->latest('id')->firstOrFail();
|
||||
$project = app(CapitalRegister::class)->save($this->admin, ['operation_key' => (string) Str::uuid(), 'version' => 0,
|
||||
'type' => 'project', 'code' => 'PRJ-DIR-QA', 'name' => 'Projecto sintético de maquinaria', 'department_id' => $request->department_id,
|
||||
'reference' => 'Referência de ensaio sem projecto real', 'state' => 'active', 'reason' => 'Cadastro próprio para ensaio do circuito']);
|
||||
app(CapitalAssignments::class)->save($this->admin, $request, ['operation_key' => (string) Str::uuid(), 'version' => 0,
|
||||
'item_id' => $request->items()->sole()->id, 'capital_id' => $project->id, 'reason' => 'Destino expresso de investimento sintético']);
|
||||
expect(DB::table('budget_entries')->count())->toBe(0);
|
||||
$this->actingAs($this->head);
|
||||
$technical = app(EquipmentWorkflow::class);
|
||||
$technical->review($this->head, $request, $technical->basis($request), 'approved', 'Conferência técnica independente de maquinaria QA');
|
||||
$this->actingAs($this->admin);
|
||||
foreach ([0, 1000000000000] as $amount) {
|
||||
expect(app(RequisitionApprovalLevels::class)->policy($request, $amount)['additional_levels']['configured_1']['profile_ids'])->toBe([$direction]);
|
||||
}
|
||||
$this->postJson('/requisicoes/'.$request->id.'/submeter', ['operation_key' => (string) Str::uuid(), 'process_version' => $request->process_version])->assertRedirect();
|
||||
$request->refresh();
|
||||
expect($request->total_minor)->toBe(11600)->and($request->steps()->orderBy('position')->pluck('role')->all())
|
||||
->toBe(['department_head', 'finance', 'configured_1'])
|
||||
->and($request->approval_snapshot['additional_levels']['configured_1']['procurement_categories'])->toBe(['capital_equipment']);
|
||||
configuredDecision($this, $this->head, $request);
|
||||
configuredDecision($this, $this->financier, $request);
|
||||
$this->actingAs($this->admin)->postJson('/administracao/parametrizacao/approval_levels', [
|
||||
'version' => 2, 'enabled' => false, 'levels' => [], 'reason' => 'Alteração sintética só para pedidos futuros'])->assertRedirect();
|
||||
approvalLevelMember($this->admin, $direction);
|
||||
foreach ([$this->admin, $this->approvers[1]] as $ineligible) {
|
||||
$this->actingAs($ineligible)->postJson('/requisicoes/'.$request->id.'/decidir', ['operation_key' => (string) Str::uuid(),
|
||||
'process_version' => $request->fresh()->process_version, 'decision' => 'approved', 'comment' => 'Tentativa sintética sem elegibilidade'])->assertForbidden();
|
||||
}
|
||||
DB::table('organization_memberships')->where('user_id', $this->approvers[0]->id)->where('profile_id', $direction)->update(['expires_at' => now()->subSecond()]);
|
||||
expect($request->fresh()->canDecide($this->approvers[0]))->toBeFalse();
|
||||
DB::table('organization_memberships')->where('user_id', $this->approvers[0]->id)->where('profile_id', $direction)->update(['expires_at' => null]);
|
||||
configuredDecision($this, $this->approvers[0], $request);
|
||||
expect($request->fresh()->status)->toBe('approved')->and($request->steps()->where('role', 'configured_1')->sole()->approver_id)->toBe($this->approvers[0]->id)
|
||||
->and((int) DB::table('budget_entries')->where('requisition_id', $request->id)->sum('reserved_minor'))->toBe(11600)
|
||||
->and(DB::table('stock_movements')->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('native three controls and five configured levels progress sequentially with one eligible person per level', function () {
|
||||
$r = submitConfiguredRequest($this);
|
||||
expect($r->steps()->count())->toBe(8)->and($r->approval_snapshot['routing_quorum'])->toBe('one_eligible');
|
||||
|
||||
Reference in New Issue
Block a user