commit14
This commit is contained in:
@@ -23,6 +23,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
|
||||
require_once __DIR__.'/../Support/RecommendationFixture.php';
|
||||
require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
|
||||
beforeEach(function () {
|
||||
$this->f = recommendationFixture();
|
||||
@@ -80,6 +81,68 @@ test('recommendation retries count one person once and returned attempt cannot a
|
||||
$this->actingAs($this->f['buyer'])->post($this->awardUrl, $this->f['selection'])->assertSessionHasErrors('recommendation');
|
||||
});
|
||||
|
||||
test('formal task recommendation keeps the adopted quorum and forwards only unfinished personal reviews', function () {
|
||||
$attempt = recommendationAttempt($this);
|
||||
$path = '/requisicoes/tarefas?module=purchases&search=recomendação';
|
||||
$this->actingAs($this->f['reviewer'])->get($path)->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1)
|
||||
->where('tasks.data.0.href', $this->url.'?version='.$this->f['adoption']->id.'&attempt_id='.$attempt->id.'#recommendation-'.$attempt->id)
|
||||
->missing('tasks.data.0.snapshot')->missing('tasks.data.0.basis_hash'));
|
||||
$this->get($this->url.'?attempt_id='.$attempt->id)->assertInertia(fn (Assert $page) => $page->where('focusAttemptId', $attempt->id)->where('history.data.0.canReview', true));
|
||||
$this->actingAs($this->f['admin']);
|
||||
app(FormalRecommendation::class)->policy($this->f['admin'], [...$this->f['policy_data'], 'previous_id' => $this->f['policy']->id, 'roles' => ['finance'], 'required_count' => 5]);
|
||||
recommendationConfer($this, $attempt);
|
||||
$this->get($path)->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
|
||||
$this->actingAs($this->f['head'])->get($path)->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1));
|
||||
recommendationConfer($this, $attempt, $this->f['head']);
|
||||
$this->actingAs($this->f['other_reviewer'])->get($path)->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
|
||||
expect(app(FormalRecommendation::class)->status($attempt, $this->f['adoption']))->toBe('confirmed')
|
||||
->and(RecommendationReview::query()->count())->toBe(2)->and(PurchaseAward::query()->count())->toBe(0)->and(BudgetEntry::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('formal task recommendation never turns a historical focused attempt into the current pending one', function () {
|
||||
$first = recommendationAttempt($this);
|
||||
$previous = $first;
|
||||
for ($index = 0; $index < 10; $index++) {
|
||||
$previous = recommendationAttempt($this, ['previous_id' => $previous->id]);
|
||||
}
|
||||
$this->actingAs($this->f['reviewer'])->get('/requisicoes/tarefas?module=purchases&search=recomendação')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 1)->where('tasks.data.0.id', 'recommendation:'.$previous->id.':review'));
|
||||
$this->get($this->url.'?attempt_id='.$first->id)->assertInertia(fn (Assert $page) => $page->where('history.total', 1)->where('history.data.0.id', $first->id)
|
||||
->where('history.data.0.current', false)->where('history.data.0.canReview', false));
|
||||
$this->get($this->url.'?attempt_id='.$previous->id)->assertInertia(fn (Assert $page) => $page->where('history.data.0.current', true)->where('history.data.0.canReview', true));
|
||||
$this->getJson($this->url.'?attempt_id=999999')->assertUnprocessable();
|
||||
});
|
||||
|
||||
test('formal task recommendation respects matrix changes without mutating the attempt or recording decisions', function () {
|
||||
$attempt = recommendationAttempt($this);
|
||||
$this->actingAs($this->f['reviewer']);
|
||||
$before = [DB::table('recommendation_attempts')->get()->toArray(), RecommendationReview::query()->count(), AuditLog::query()->count()];
|
||||
$this->get('/requisicoes/tarefas?module=purchases&search=recomendação')->assertOk();
|
||||
$this->get($this->url.'?attempt_id='.$attempt->id)->assertOk();
|
||||
expect([DB::table('recommendation_attempts')->get()->toArray(), RecommendationReview::query()->count(), AuditLog::query()->count()])->toEqual($before);
|
||||
ProposalEvaluation::query()->where('quotation_id', $this->f['quotes'][0]->id)->update(['quality' => '1']);
|
||||
$this->get('/requisicoes/tarefas?module=purchases&search=recomendação')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
|
||||
$this->get($this->url.'?attempt_id='.$attempt->id)->assertInertia(fn (Assert $page) => $page->where('history.data.0.canReview', false));
|
||||
$this->post('/recomendacoes/'.$attempt->id.'/conferir', ['verdict' => 'approved', 'reason' => 'Base alterada exige nova tentativa.'])->assertSessionHasErrors('recommendation');
|
||||
expect(RecommendationReview::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('formal task recommendation respects department company maintenance and current reviewer authority', function () {
|
||||
$attempt = recommendationAttempt($this);
|
||||
$department = Department::query()->create(['tenant_id' => $this->f['tenant']->id, 'name' => 'Outra unidade sintética']);
|
||||
$head = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $department->id, 'purchasing_role' => PurchasingRole::DepartmentHead]);
|
||||
$this->actingAs($head)->get('/requisicoes/tarefas?module=purchases&search=recomendação')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
|
||||
$this->get($this->url.'?attempt_id='.$attempt->id)->assertNotFound();
|
||||
$tenant = Tenant::query()->create(['name' => 'Outra empresa sintética']);
|
||||
$foreign = User::factory()->create(['tenant_id' => $tenant->id, 'purchasing_role' => PurchasingRole::Finance]);
|
||||
$this->actingAs($foreign)->get($this->url.'?attempt_id='.$attempt->id)->assertNotFound();
|
||||
supplyGrant($this->f['reviewer'], ['finance']);
|
||||
DB::table('organization_memberships')->where('user_id', $this->f['reviewer']->id)->update(['maintenance' => true, 'expires_at' => now()->addHour()]);
|
||||
$this->actingAs($this->f['reviewer'])->get('/requisicoes/tarefas?module=purchases&search=recomendação')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
|
||||
$this->get($this->url.'?attempt_id='.$attempt->id)->assertInertia(fn (Assert $page) => $page->where('history.data.0.canReview', false)->where('canPropose', false)->where('canAdopt', false));
|
||||
$this->post('/recomendacoes/'.$attempt->id.'/conferir', ['verdict' => 'approved', 'reason' => 'Não decidir em manutenção.'])->assertForbidden();
|
||||
expect(RecommendationReview::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('recommendation rejects lower score incomplete matrix and stale admission', function (string $case) {
|
||||
if ($case === 'incomplete') {
|
||||
ProposalEvaluation::query()->where('quotation_id', $this->f['quotes'][0]->id)->where('evaluator_id', $this->f['analyst']->id)->delete();
|
||||
|
||||
Reference in New Issue
Block a user