commit9
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-30 20:02:30 +02:00
parent 6d14b4e6f0
commit c6373365bf
225 changed files with 15365 additions and 285 deletions
+22 -3
View File
@@ -6,6 +6,7 @@ use App\Models\Department;
use App\Models\Requisition;
use App\Models\User;
use App\Services\ExternalPaymentWorkflow;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\DB;
use Inertia\Testing\AssertableInertia as Assert;
@@ -51,7 +52,7 @@ test('report counts and CSV use all filtered requests rather than the displayed
foreach (range(1, 206) as $index) {
reportCopy($this->f['r'], 'REPORT-'.$index);
}
$this->get('/relatorios')->assertInertia(fn (Assert $page) => $page->has('records.data', 25)->where('records.total', 207)->where('counts.approved', 207));
$this->get('/relatorios')->assertInertia(fn (Assert $page) => $page->has('records.data', 25)->where('records.total', 207)->where('counts.approved', 207)->where('insights.processes', 207)->where('insights.approved.without_registered_quotes', 206)->where('insights.approved.without_visible_order', 206));
$csv = $this->get('/relatorios/compras.csv?page=2')->assertOk()->streamedContent();
expect($csv)->toContain($this->f['r']->number)->toContain('REPORT-206');
$this->get('/relatorios?search=REPORT-2')->assertInertia(fn (Assert $page) => $page->where('records.total', 18));
@@ -65,8 +66,8 @@ test('report filters and CSV cannot expose another department or company', funct
$department = Department::query()->create(['tenant_id' => $own['tenant']->id, 'name' => 'Other department']);
reportCopy($own['r'], 'OTHER-DEPARTMENT-SECRET', ['department_id' => $department->id]);
$head = User::factory()->create(['tenant_id' => $own['tenant']->id, 'department_id' => $own['r']->department_id, 'purchasing_role' => PurchasingRole::DepartmentHead]);
$this->actingAs($head)->get('/relatorios')->assertInertia(fn (Assert $page) => $page->where('records.total', 1)->has('departments', 1));
$this->get('/relatorios?department_id='.$department->id)->assertInertia(fn (Assert $page) => $page->where('records.total', 0));
$this->actingAs($head)->get('/relatorios')->assertInertia(fn (Assert $page) => $page->where('records.total', 1)->where('insights.processes', 1)->has('departments', 1));
$this->get('/relatorios?department_id='.$department->id)->assertInertia(fn (Assert $page) => $page->where('records.total', 0)->where('insights.processes', 0)->where('insights.pending.oldest', []));
$csv = $this->get('/relatorios/compras.csv')->assertOk()->streamedContent();
expect($csv)->not->toContain('OTHER-DEPARTMENT-SECRET')->not->toContain('OTHER-COMPANY-SECRET');
});
@@ -83,6 +84,24 @@ test('reports reload current access and protect both HTML and CSV from unauthori
$this->get('/relatorios/compras.csv')->assertRedirect('/login');
});
test('procurement reading distinguishes submission age need dates and incomplete evidence without business writes', function () {
$this->travelTo(CarbonImmutable::parse('2026-10-30 12:00:00'));
$audits = AuditLog::query()->count();
foreach (range(1, 7) as $day) {
reportCopy($this->f['r'], 'PENDING-'.$day, ['status' => 'pending', 'submitted_at' => '2026-10-'.(30 - $day).' 12:00:00', 'needed_by' => '2026-10-29']);
}
reportCopy($this->f['r'], 'UNKNOWN-AGE', ['status' => 'pending', 'submitted_at' => null, 'needed_by' => '2026-10-30']);
reportCopy($this->f['r'], 'FUTURE-AGE', ['status' => 'pending', 'submitted_at' => '2026-11-01 12:00:00', 'needed_by' => '2026-10-30']);
reportCopy($this->f['r'], 'CANCELLED-PAST', ['status' => 'cancelled', 'needed_by' => '2026-01-01']);
$this->get('/relatorios')->assertInertia(fn (Assert $page) => $page
->where('insights.processes', 11)->where('insights.pending.count', 9)->where('insights.pending.unknown_submission_age', 2)
->where('insights.unapproved_past_needed_date', 7)->has('insights.pending.oldest', 5)
->where('insights.pending.oldest.0.number', 'PENDING-7')->where('insights.pending.oldest.0.days_since_submission', 7)
->where('insights.approved.count', 1)->where('insights.approved.without_registered_quotes', 0)->where('insights.approved.without_visible_order', 0));
$this->get('/relatorios?search=PENDING-1')->assertInertia(fn (Assert $page) => $page->where('insights.processes', 1)->where('insights.pending.count', 1));
expect(AuditLog::query()->count())->toBe($audits);
});
test('reports reject invalid filters on both the screen and export', function () {
foreach (['status=unknown', 'from=invalid', 'from=2026-02-02&to=2026-01-01', 'department_id=-1'] as $filter) {
$this->getJson('/relatorios?'.$filter)->assertUnprocessable();