commit21
This commit is contained in:
@@ -9,12 +9,14 @@ use App\Models\SupplierImprovement;
|
||||
use App\Models\User;
|
||||
use App\Services\RequisitionWorkflow;
|
||||
use App\Services\SupplierImprovementWorkflow;
|
||||
use App\Services\WorkflowTaskInbox;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
|
||||
beforeEach(function () {
|
||||
$this->f = receiptFixture();
|
||||
@@ -154,3 +156,79 @@ test('audit failure rolls a measure and its progress back without changing the e
|
||||
expect(fn () => app(SupplierImprovementWorkflow::class)->execute($this->f['issuer'], $this->evaluation->id, $m->id, 'progress', ['version' => 1, ...$this->execution]))->toThrow(RuntimeException::class);
|
||||
expect($m->refresh()->version)->toBe(1)->and($m->result)->toBeNull()->and($this->evaluation->refresh()->status)->toBe('approved');
|
||||
});
|
||||
|
||||
function improvementTasks(object $test, User $actor): array
|
||||
{
|
||||
$test->actingAs($actor);
|
||||
|
||||
return array_values(array_filter(app(WorkflowTaskInbox::class)->build($actor, 'procurement'),
|
||||
fn ($row) => str_starts_with($row['id'], 'supplier-improvement:')));
|
||||
}
|
||||
|
||||
test('improvement tasks follow assignment independent review return and closure without changing the approved source', function () {
|
||||
$before = $this->evaluation->refresh()->getAttributes();
|
||||
$m = improvementDraft($this);
|
||||
expect(improvementTasks($this, $this->planner))->toBe([]);
|
||||
$tasks = improvementTasks($this, $this->f['issuer']);
|
||||
expect($tasks)->toHaveCount(1)->and($tasks[0]['due_on'])->toBe($this->data['due_on'])
|
||||
->and($tasks[0]['href'])->toBe('/fornecedores/avaliacoes/'.$this->evaluation->id.'#medida-'.$m->id);
|
||||
$this->post($this->url.'/'.$m->id.'/submit', ['version' => 1, ...$this->execution])->assertRedirect();
|
||||
expect(improvementTasks($this, $this->f['issuer']))->toBe([])
|
||||
->and(improvementTasks($this, $this->planner))->toBe([]);
|
||||
$tasks = improvementTasks($this, $this->closer);
|
||||
expect($tasks)->toHaveCount(1)->and($tasks[0]['task'])->toBe('supplier_improvement_review');
|
||||
$this->post($this->url.'/'.$m->id.'/return', ['version' => 2, 'reason' => 'Completar referência da evidência apresentada.'])->assertRedirect();
|
||||
expect(improvementTasks($this, $this->closer))->toBe([])->and(improvementTasks($this, $this->f['issuer']))->toHaveCount(1);
|
||||
$this->post($this->url.'/'.$m->id.'/submit', ['version' => 3, ...$this->execution])->assertRedirect();
|
||||
$this->actingAs($this->closer)->post($this->url.'/'.$m->id.'/close', ['version' => 4, 'reason' => 'Conferência independente da execução e evidência.'])->assertRedirect();
|
||||
expect(improvementTasks($this, $this->closer))->toBe([])->and(improvementTasks($this, $this->f['issuer']))->toBe([])
|
||||
->and($this->evaluation->refresh()->getAttributes())->toBe($before);
|
||||
});
|
||||
|
||||
test('improvement tasks exclude other companies departments and current conflicts', function () {
|
||||
improvementInReview($this);
|
||||
$other = receiptFixture();
|
||||
expect(improvementTasks($this, $other['issuer']))->toBe([]);
|
||||
$department = Department::query()->create(['tenant_id' => $this->f['tenant']->id, 'name' => 'Outro âmbito']);
|
||||
$head = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $department->id, 'purchasing_role' => PurchasingRole::DepartmentHead]);
|
||||
expect(improvementTasks($this, $head))->toBe([]);
|
||||
expect(improvementTasks($this, $this->closer))->toHaveCount(1);
|
||||
ConflictDeclaration::query()->create(['tenant_id' => $this->f['tenant']->id, 'user_id' => $this->closer->id, 'requisition_id' => $this->f['r']->id,
|
||||
'has_conflict' => true, 'known_since' => today()->toDateString(), 'declared_at' => now(), 'reason' => 'Conflito fictício para testar o encaminhamento.']);
|
||||
expect(improvementTasks($this, $this->closer))->toBe([]);
|
||||
});
|
||||
|
||||
test('improvement tasks retain old pending measures beyond the first hundred and disclose no evidence', function () {
|
||||
$m = improvementDraft($this);
|
||||
for ($i = 0; $i < 104; $i++) {
|
||||
$copy = $m->replicate();
|
||||
$copy->operation_key = (string) Str::uuid();
|
||||
$copy->save();
|
||||
}
|
||||
$before = AuditLog::query()->count();
|
||||
$tasks = improvementTasks($this, $this->f['issuer']);
|
||||
expect($tasks)->toHaveCount(105)->and($tasks[0]['id'])->toStartWith('supplier-improvement:'.$m->id.':')
|
||||
->and(array_key_exists('evidence', $tasks[0]))->toBeFalse()->and(AuditLog::query()->count())->toBe($before);
|
||||
});
|
||||
|
||||
test('improvement task eligibility and page actions share the current role and approved evaluation', function () {
|
||||
$m = improvementInReview($this);
|
||||
expect(improvementTasks($this, $this->closer))->toHaveCount(1);
|
||||
$this->get('/fornecedores/avaliacoes/'.$this->evaluation->id)->assertInertia(fn (Assert $p) => $p->where('improvements.records.0.canReview', true));
|
||||
DB::table('users')->where('id', $this->closer->id)->update(['purchasing_role' => 'requester']);
|
||||
expect(improvementTasks($this, $this->closer->fresh()))->toBe([]);
|
||||
$this->post($this->url.'/'.$m->id.'/close', ['version' => 2, 'reason' => 'Tentativa após revogação da função anterior.'])->assertForbidden();
|
||||
expect($m->refresh()->status)->toBe('review');
|
||||
});
|
||||
|
||||
test('improvement tasks keep maintenance accounts read only and expired memberships ineligible', function () {
|
||||
$m = improvementInReview($this);
|
||||
supplyGrant($this->closer, ['finance']);
|
||||
DB::table('organization_memberships')->where('user_id', $this->closer->id)->update(['maintenance' => true, 'expires_at' => now()->addHour()]);
|
||||
expect(improvementTasks($this, $this->closer))->toBe([]);
|
||||
$this->get('/fornecedores/avaliacoes/'.$this->evaluation->id)->assertInertia(fn (Assert $p) => $p->where('improvements.records.0.canReview', false));
|
||||
$this->post($this->url.'/'.$m->id.'/close', ['version' => 2, 'reason' => 'Tentativa de decisão com acesso de manutenção.'])->assertForbidden();
|
||||
DB::table('organization_memberships')->where('user_id', $this->closer->id)->update(['expires_at' => now()->subMinute()]);
|
||||
expect(improvementTasks($this, $this->closer))->toBe([]);
|
||||
expect($m->refresh()->status)->toBe('review');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user