This commit is contained in:
2026-11-02 20:27:11 +02:00
parent b44378b899
commit badaada043
300 changed files with 17458 additions and 1056 deletions
+64
View File
@@ -45,6 +45,8 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Inertia\Testing\AssertableInertia as Assert;
require_once __DIR__.'/../Support/SupplyFixture.php';
function awardPrices(object $test, int $firstPrice, int $taxRate = 0): void
{
$test->r->items()->update(['tax_rate' => $taxRate]);
@@ -776,3 +778,65 @@ test('legacy award keeps null admission basis and refuses later adoption', funct
expect(AdmissionAdoption::query()->count())->toBe(0);
issuePurchaseOrder($this, $award);
});
test('task inbox follows every final award approval and hands approved issuance back to procurement', function () {
awardPrices($this, 30000000);
$award = selectPurchaseAward($this);
$this->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
foreach ([$this->head, $this->secondBuyer, $this->finance] as $reviewer) {
$this->actingAs($reviewer)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1)
->where('tasks.data.0.task', 'award_approve')->where('tasks.data.0.href', $this->awardUrl));
$this->post('/adjudicacoes/'.$award->id.'/decidir', ['decision' => 'approved'])->assertSessionHasNoErrors();
$this->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
}
$this->actingAs($this->buyer)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1)->where('tasks.data.0.task', 'order_issue_review'));
$this->get($this->awardUrl)->assertInertia(fn (Assert $page) => $page->where('canIssue', true));
$this->post('/adjudicacoes/'.$award->id.'/emitir')->assertSessionHasNoErrors();
expect(PurchaseOrder::query()->count())->toBe(1);
$this->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
});
test('task inbox respects pending cancellation and consultation leaves award budget and audit untouched', function () {
enablePurchaseCancellation($this);
$award = selectPurchaseAward($this);
$this->actingAs($this->head)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1));
$this->actingAs($this->buyer)->post('/adjudicacoes/'.$award->id.'/cancelamento', ['reason' => 'Necessidade fictícia em conferência'])->assertSessionHasNoErrors();
$before = [$award->fresh()->toArray(), $award->approvals()->get()->toArray(), BudgetEntry::query()->get()->toArray(), AuditLog::query()->count()];
$this->actingAs($this->head)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
$this->get($this->awardUrl)->assertInertia(fn (Assert $page) => $page->where('canDecide', false));
expect([$award->fresh()->toArray(), $award->approvals()->get()->toArray(), BudgetEntry::query()->get()->toArray(), AuditLog::query()->count()])->toEqual($before);
$cancel = AwardCancellation::query()->sole();
$this->actingAs($this->finance)->post('/cancelamentos/'.$cancel->id.'/decidir', ['decision' => 'rejected', 'reason' => 'Manter o processo sintético original'])->assertSessionHasNoErrors();
$this->actingAs($this->head)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1));
});
test('task inbox cannot grant an award decision to maintenance or a revoked department role', function () {
$award = selectPurchaseAward($this);
supplyGrant($this->head, ['department_head']);
DB::table('organization_memberships')->where('user_id', $this->head->id)->update(['maintenance' => true, 'expires_at' => now()->addHour()]);
$this->actingAs($this->head)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
$this->get($this->awardUrl)->assertInertia(fn (Assert $page) => $page->where('canDecide', false));
$this->post('/adjudicacoes/'.$award->id.'/decidir', ['decision' => 'approved'])->assertForbidden();
DB::table('organization_memberships')->where('user_id', $this->head->id)->update(['maintenance' => false, 'expires_at' => now()->subMinute()]);
$this->actingAs($this->head->fresh())->get('/requisicoes/tarefas?module=purchases')->assertForbidden();
expect($award->fresh()->status)->toBe('pending')->and(PurchaseOrder::query()->count())->toBe(0);
});
test('task inbox issuance review does not override a proposal that expired after approval', function () {
$award = selectPurchaseAward($this);
approvePurchaseAward($this, $award);
$this->quotes[0]->update(['valid_until' => today()->subDay()]);
$this->actingAs($this->buyer)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1)->where('tasks.data.0.task', 'order_issue_review'));
$this->post('/adjudicacoes/'.$award->id.'/emitir')->assertSessionHasErrors();
expect(PurchaseOrder::query()->count())->toBe(0)->and($award->fresh()->status)->toBe('approved');
});
test('quotation tasks hand a ready comparison to adjudication without reopening rejected awards', function () {
$this->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1)->where('tasks.data.0.task', 'comparison_review'));
$award = selectPurchaseAward($this);
$this->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
$this->actingAs($this->head)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1)->where('tasks.data.0.task', 'award_approve'));
$this->post('/adjudicacoes/'.$award->id.'/decidir', ['decision' => 'rejected', 'comment' => 'Devolver ao percurso autorizado de revisão.'])->assertSessionHasNoErrors();
$this->actingAs($this->buyer)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
$this->get('/requisicoes/'.$this->r->id.'/cotacoes')->assertInertia(fn (Assert $page) => $page->where('canCreate', false)->where('canEvaluate', false));
});