commit compras3 2911
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-29 16:03:11 +02:00
parent 7da8d6c87a
commit 30bfb1a773
72 changed files with 10998 additions and 98 deletions
@@ -4,8 +4,10 @@ use App\Enums\PurchasingRole;
use App\Models\Budget;
use App\Models\Requisition;
use App\Models\SupplyRecord;
use App\Models\Tenant;
use App\Models\User;
use App\Services\CommonBudget;
use App\Services\CommonFinanceAdministration;
use App\Services\CommonPaymentFacts;
use App\Services\ExpenseAllocations;
use App\Services\GeneralLedger;
@@ -21,6 +23,7 @@ use App\Services\SupplierPayables;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Tempo\Finance\Budget\BudgetFailure;
require_once __DIR__.'/../Support/ReceiptFixture.php';
@@ -36,6 +39,7 @@ beforeEach(function () {
}
$settings = config('standalone-runtime');
$settings['enabled'] = true;
$settings['prepare_only'] = false;
$settings['features'] = array_fill_keys(StandaloneRuntime::FEATURES, true);
config(['standalone-runtime' => [...$settings, 'enabled' => false], 'common-payables.source_instance' => 'standalone-business-synthetic']);
$runtime = new StandaloneRuntime($settings, new StandaloneArtifact);
@@ -175,6 +179,9 @@ test('standalone financial pages use explicit read rights and refuse writes or d
'purchasing_role' => PurchasingRole::Finance]);
$this->actingAs($finance)->get('/api/supplier-payments')->assertForbidden();
$this->get('/api/general-ledger/cycle')->assertForbidden();
$this->withoutVite()->get('/dashboard')->assertOk()->assertInertia(fn ($page) => $page
->where('commonFinanceNavigation.payments', false)->where('commonFinanceNavigation.ledger', false)
->where('commonFinanceNavigation.configuration', false));
foreach (['view', 'payments_view', 'general_ledger.view'] as $action) {
DB::table('pa_access')->insert(['tenant_id' => $finance->tenant_id, 'company_id' => 0, 'unit_id' => 0,
'user_id' => $finance->id, 'person' => 'synthetic-financial-reader-'.$finance->id, 'action' => $action]);
@@ -187,6 +194,9 @@ test('standalone financial pages use explicit read rights and refuse writes or d
->assertJsonPath('permissions.payment_prepare', false);
$this->get('/supplier-payments')->assertOk()->assertHeader('Cache-Control', 'no-store, private');
$this->get('/api/general-ledger/cycle')->assertOk();
$this->get('/dashboard')->assertOk()->assertInertia(fn ($page) => $page
->where('commonFinanceNavigation.payments', true)->where('commonFinanceNavigation.ledger', true)
->where('commonFinanceNavigation.configuration', false));
$this->get('/general-ledger/cycle')->assertOk();
$this->withHeader('Idempotency-Key', (string) Str::uuid())->postJson('/api/supplier-payments/payment-prepare', [])->assertForbidden();
$this->withHeader('Idempotency-Key', (string) Str::uuid())->postJson('/api/general-ledger/prepare', [
@@ -205,11 +215,23 @@ test('standalone financial pages use explicit read rights and refuse writes or d
test('standalone candidate recognises one invoice and posts one balanced journal using explicitly configured own chart accounts', function () {
$f = paymentFixture();
$admin = User::factory()->create(['tenant_id' => $f['tenant']->id, 'purchasing_role' => PurchasingRole::Admin]);
$configuration = function (string $kind, array $data) use ($admin) {
$this->actingAs($admin);
$service = app(CommonFinanceAdministration::class);
$space = $service->workspace($admin, $data['user_id'] ?? null);
$basis = $space[match ($kind) {
'access' => 'selectedAccess', 'account' => 'accounts', 'period' => 'periods', 'rule' => 'rules'
}];
return $service->save($admin, $kind, $data + ['operation_key' => (string) Str::uuid(),
'basis_hash' => $basis['hash'], 'reason' => 'Explicit synthetic company setup for the real financial cycle']);
};
foreach ([$f['author'], $f['validator']] as $actor) {
foreach (['view', 'prepare', 'validate', 'general_ledger.view', 'general_ledger.prepare', 'general_ledger.validate', 'general_ledger.post'] as $action) {
DB::table('pa_access')->insert(['tenant_id' => $actor->tenant_id, 'company_id' => 0, 'unit_id' => 0,
'user_id' => $actor->id, 'person' => 'synthetic-independent-person-'.$actor->id, 'action' => $action]);
}
$configuration('access', ['user_id' => $actor->id, 'person' => 'synthetic-independent-person-'.$actor->id,
'actions' => ['view', 'prepare', 'validate', 'general_ledger.view', 'general_ledger.prepare', 'general_ledger.validate', 'general_ledger.post',
'general_ledger.correct_prepare', 'general_ledger.correct_validate', 'general_ledger.correct_post',
'general_ledger.period_prepare', 'general_ledger.period_validate', 'general_ledger.period_close']]);
}
$payables = app(SupplierPayables::class);
$this->actingAs($f['author']);
@@ -220,15 +242,13 @@ test('standalone candidate recognises one invoice and posts one balanced journal
$scope = ['tenant_id' => $f['author']->tenant_id, 'company_id' => 0, 'unit_id' => 0];
$accounts = [];
foreach (['630100' => 'Synthetic configured expense account', '420100' => 'Synthetic configured supplier account'] as $code => $label) {
$accounts[] = DB::table('gl_accounts')->insertGetId($scope + ['code' => $code, 'label' => $label, 'currency' => 'MZN', 'is_movement' => true]);
$accounts[] = $configuration('account', ['code' => (string) $code, 'label' => $label, 'currency' => 'MZN', 'is_movement' => true])['id'];
}
DB::table('gl_periods')->insert($scope + ['period_key' => 'EXPLICIT', 'version' => 1, 'starts_on' => today()->startOfYear()->toDateString(),
'ends_on' => today()->endOfYear()->toDateString(), 'status' => 'open', 'created_by' => $f['author']->id,
'reason' => 'Explicit synthetic accounting period', 'created_at' => now()]);
DB::table('gl_rules')->insert($scope + ['rule_key' => 'EXPLICIT-SUPPLIER', 'version' => 1, 'policy' => 'COMMON-PAYABLE-JOURNAL-v1',
'effect_type' => 'supplier_payable.recognised', 'currency' => 'MZN', 'valid_from' => today()->startOfYear()->toDateString(),
'valid_to' => today()->endOfYear()->toDateString(), 'debit_account_id' => $accounts[0], 'credit_account_id' => $accounts[1],
'created_by' => $f['author']->id, 'reason' => 'Explicit synthetic own chart accounting rule', 'created_at' => now()]);
$configuration('period', ['period_key' => 'EXPLICIT', 'starts_on' => today()->startOfYear()->toDateString(),
'ends_on' => today()->endOfYear()->toDateString()]);
$configuration('rule', ['rule_key' => 'EXPLICIT-SUPPLIER', 'effect_type' => 'supplier_payable.recognised',
'valid_from' => today()->startOfYear()->toDateString(), 'valid_to' => today()->endOfYear()->toDateString(),
'debit_account_id' => $accounts[0], 'credit_account_id' => $accounts[1]]);
$ledger = app(GeneralLedger::class);
$this->actingAs($f['author']);
$input = ['obligation_id' => $validated['obligation_id'], 'journal_on' => today()->toDateString(), 'period_key' => 'EXPLICIT',
@@ -244,6 +264,7 @@ test('standalone candidate recognises one invoice and posts one balanced journal
$post = ['proposal_id' => $proposal['proposal_id'], 'revision' => $proposal['revision'], 'reason' => 'Apply the independently reviewed synthetic journal'];
$ledger->engine($f['author'])->command('post', $post, $operation);
DB::statement('SET CONSTRAINTS ALL IMMEDIATE');
DB::statement('SET CONSTRAINTS ALL DEFERRED');
expect($ledger->engine($f['author'])->command('post', $post, $operation)['replayed'])->toBeTrue()
->and(DB::table('gl_journals')->count())->toBe(1)->and(DB::table('gl_lines')->count())->toBe(2)
->and((int) DB::table('gl_lines')->sum('debit_minor'))->toBe(6000)
@@ -252,6 +273,67 @@ test('standalone candidate recognises one invoice and posts one balanced journal
$snapshot = json_decode(DB::table('gl_journals')->value('snapshot'), true, 128, JSON_THROW_ON_ERROR);
expect($snapshot['contract'])->toBe('COMMON-LEDGER-PAYABLE-v1')
->and(array_column($snapshot['lines'], 'account_id'))->toBe($accounts);
$this->get('/general-ledger/cycle')->assertOk()->assertSee('EXPLICIT-SUPPLIER')->assertSee('EXPLICIT')
->assertDontSee('value="2026-10-29"', false)->assertDontSee('value="QA-PAYABLE-JOURNAL"', false);
$interval = http_build_query(['from_on' => today()->startOfYear()->toDateString(), 'to_on' => today()->toDateString()]);
$this->get('/general-ledger/trial-balance?'.$interval)->assertOk()
->assertSee('2 de 2 contas')->assertSee('60,00')->assertSee('print-context')
->assertSee('os totais abrangem todo o filtro');
$this->get('/general-ledger/account-ledger?'.$interval.'&account_id='.$accounts[0])->assertOk()
->assertSee('1 de 1 linhas')->assertSee('60,00')->assertSee(today()->toDateString());
$original = DB::table('gl_journals')->first();
$correctedAccount = DB::table('gl_accounts')->insertGetId($scope + ['code' => '630200',
'label' => 'Explicit synthetic corrected expense account', 'currency' => 'MZN', 'is_movement' => true]);
$baseRule = (array) DB::table('gl_rules')->first();
unset($baseRule['id']);
foreach ([['REVERSE', 'journal.reversal', $accounts[1], $accounts[0]],
['REPLACE', 'journal.replacement', $correctedAccount, $accounts[1]],
['BAD-REVERSE', 'journal.reversal', $accounts[0], $accounts[1]]] as [$key, $effect, $debit, $credit]) {
DB::table('gl_rules')->insert([...$baseRule, 'rule_key' => $key, 'effect_type' => $effect,
'debit_account_id' => $debit, 'credit_account_id' => $credit]);
}
$correctionInput = ['journal_id' => $original->id, 'journal_on' => today()->toDateString(), 'period_key' => 'EXPLICIT',
'reverse_rule_key' => 'REVERSE', 'replacement_rule_key' => 'REPLACE', 'reason' => 'Explicit synthetic correction of account classification'];
expect(fn () => $ledger->engine($f['author'])->command('correct-prepare', [...$correctionInput, 'reverse_rule_key' => 'BAD-REVERSE'], (string) Str::uuid()))
->toThrow(DomainException::class);
expect(DB::table('gl_proposals')->count())->toBe(1)->and(DB::table('gl_journals')->count())->toBe(1);
$correction = $ledger->engine($f['author'])->command('correct-prepare', $correctionInput, (string) Str::uuid());
$this->actingAs($f['validator']);
$ledger->engine($f['validator'])->command('correct-validate', ['correction_id' => $correction['correction_id'],
'revision' => $correction['revision'], 'decision' => 'approved', 'reason' => 'Independent review of both exact synthetic correction impacts'], (string) Str::uuid());
$this->actingAs($f['author']);
$correctionPost = ['correction_id' => $correction['correction_id'], 'revision' => $correction['revision'], 'reason' => 'Apply the independently reviewed synthetic pair'];
$correctionOperation = (string) Str::uuid();
$fault = function (string $checkpoint) {
if ($checkpoint === 'after_correction_first') {
throw new RuntimeException('SYNTHETIC_CORRECTION_INTERRUPTION');
}
};
expect(fn () => $ledger->engine($f['author'], $fault)->command('correct-post', $correctionPost, $correctionOperation))
->toThrow(RuntimeException::class, 'SYNTHETIC_CORRECTION_INTERRUPTION');
expect(DB::table('gl_journals')->count())->toBe(1)->and(DB::table('gl_correction_results')->count())->toBe(0);
$ledger->engine($f['author'])->command('correct-post', $correctionPost, $correctionOperation);
DB::statement('SET CONSTRAINTS ALL IMMEDIATE');
DB::statement('SET CONSTRAINTS ALL DEFERRED');
expect($ledger->engine($f['author'])->command('correct-post', $correctionPost, $correctionOperation)['replayed'])->toBeTrue()
->and((array) DB::table('gl_journals')->where('id', $original->id)->first())->toBe((array) $original)
->and(DB::table('gl_journals')->count())->toBe(3)->and(DB::table('gl_correction_results')->count())->toBe(1)
->and((int) DB::table('gl_lines')->where('account_id', $accounts[0])->sum('debit_minor')
- (int) DB::table('gl_lines')->where('account_id', $accounts[0])->sum('credit_minor'))->toBe(0)
->and((int) DB::table('gl_lines')->where('account_id', $correctedAccount)->sum('debit_minor'))->toBe(6000)
->and(DB::table('pa_obligations')->count())->toBe(1)->and((int) DB::table('pa_obligations')->sum('principal_minor'))->toBe(6000);
$check = $ledger->engine($f['author'])->command('period-prepare', ['period_key' => 'EXPLICIT', 'reason' => 'Synthetic close preparation after complete postings'], (string) Str::uuid());
$this->actingAs($f['validator']);
$ledger->engine($f['validator'])->command('period-validate', ['check_id' => $check['check_id'], 'revision' => $check['revision'],
'decision' => 'approved', 'reason' => 'Independent synthetic review of the closed-period evidence'], (string) Str::uuid());
$this->actingAs($f['author']);
$closeOperation = (string) Str::uuid();
$close = ['check_id' => $check['check_id'], 'revision' => $check['revision'], 'reason' => 'Apply the independently reviewed synthetic period closure'];
$ledger->engine($f['author'])->command('period-close', $close, $closeOperation);
expect($ledger->engine($f['author'])->command('period-close', $close, $closeOperation)['replayed'])->toBeTrue()
->and(DB::table('gl_period_closures')->count())->toBe(1)
->and(DB::table('gl_periods')->orderByDesc('version')->value('status'))->toBe('closed')
->and(DB::table('external_payments')->count())->toBe(0)->and(DB::table('ps_payments')->count())->toBe(0);
});
test('common partial payment attribution uses explicit Finance categories without duplicate native payments and preserves reversed history', function () {
@@ -270,16 +352,23 @@ test('common partial payment attribution uses explicit Finance categories withou
$run = function (User $actor, string $action, array $data) use ($payables): array {
$this->actingAs($actor);
return $payables->engine($actor)->settlements()->command($action, $data, (string) Str::uuid());
return $payables->settlements($actor)->command($action, $data, (string) Str::uuid());
};
$payment = $run($f['author'], 'payment-prepare', ['obligation_id' => $recognised['obligation_id'],
$paymentInput = ['obligation_id' => $recognised['obligation_id'],
'source_revision' => $recognised['source_revision'], 'amount' => '40.00', 'currency' => 'MZN', 'paid_on' => today()->toDateString(),
'fact_reference' => 'SIM-COMMON-PARTIAL', 'evidence_reference' => 'SIM-COMMON-EVIDENCE', 'reason' => 'Explicit synthetic confirmed payment fact']);
'fact_reference' => 'DOC-COMMON-PARTIAL', 'evidence_reference' => 'DOC-COMMON-EVIDENCE', 'reason' => 'Explicit synthetic confirmed payment fact'];
$this->actingAs($f['author']);
expect(fn () => $payables->engine($f['author'])->settlements()->command('payment-prepare', $paymentInput, (string) Str::uuid()))
->toThrow(InvalidArgumentException::class);
expect(DB::table('ps_payments')->count())->toBe(0);
$payment = $run($f['author'], 'payment-prepare', $paymentInput);
$paymentSnapshot = json_decode(DB::table('ps_payments')->where('id', $payment['payment_id'])->value('snapshot'), true, 32, JSON_THROW_ON_ERROR);
expect($paymentSnapshot['synthetic_only'])->toBeTrue();
$run($f['validator'], 'payment-decide', ['payment_id' => $payment['payment_id'], 'decision' => 'confirmed',
'evidence_reference' => 'SIM-COMMON-CONFIRMED', 'reason' => 'Independent synthetic payment confirmation']);
'evidence_reference' => 'DOC-COMMON-CONFIRMED', 'reason' => 'Independent synthetic payment confirmation']);
$report = fn () => app(ProcurementPaymentInsights::class)->build($f['validator'], Requisition::query()->whereKey($f['r']->id), null, null);
expect($report()['coverage']['indeterminate'])->toBe(1)->and($report()['currencies'])->toBe([]);
$allocation = $run($f['author'], 'allocation-prepare', ['payment_id' => $payment['payment_id'], 'reference' => 'SIM-ALLOCATION-EXPLICIT',
$allocation = $run($f['author'], 'allocation-prepare', ['payment_id' => $payment['payment_id'], 'reference' => 'DOC-ALLOCATION-EXPLICIT',
'allocations' => [['obligation_id' => $recognised['obligation_id'], 'source_revision' => $recognised['source_revision'], 'amount' => '40.00']],
'reason' => 'Explicit synthetic invoice allocation of the confirmed payment']);
$run($f['validator'], 'allocation-decide', ['proposal_id' => $allocation['proposal_id'], 'decision' => 'confirmed',
@@ -347,7 +436,7 @@ test('one common payment shared across two invoices is counted once while explic
$run = function (User $actor, string $action, array $data) use ($adapter): array {
$this->actingAs($actor);
return $adapter->engine($actor)->settlements()->command($action, $data, (string) Str::uuid());
return $adapter->settlements($actor)->command($action, $data, (string) Str::uuid());
};
$payment = $run($f['author'], 'payment-prepare', ['obligation_id' => $obligations[0]['obligation_id'], 'source_revision' => $obligations[0]['source_revision'],
'amount' => '70.00', 'currency' => 'MZN', 'paid_on' => today()->toDateString(), 'fact_reference' => 'SIM-TWO-INVOICES',
@@ -376,3 +465,100 @@ test('one common payment shared across two invoices is counted once while explic
->and(DB::table('ps_payments')->count())->toBe(1)->and(DB::table('ps_allocations')->count())->toBe(2)
->and(DB::table('external_payments')->count())->toBe(0);
});
test('company finance configuration requires an administrator and records explicit access with safe replay and revocation', function () {
$admin = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id,
'purchasing_role' => PurchasingRole::Admin]);
$finance = User::factory()->create(['tenant_id' => $admin->tenant_id, 'department_id' => $admin->department_id,
'purchasing_role' => PurchasingRole::Finance]);
$service = app(CommonFinanceAdministration::class);
$this->actingAs($finance)->get('/administracao/financeiro')->assertForbidden();
$before = DB::table('pa_access')->count();
$this->actingAs($admin);
$space = $service->workspace($admin, $finance->id);
expect($space['selectedAccess']['actions'])->toBe([])->and(DB::table('pa_access')->count())->toBe($before);
$payload = ['operation_key' => (string) Str::uuid(), 'basis_hash' => $space['selectedAccess']['hash'],
'reason' => 'Explicit synthetic company financial access', 'user_id' => $finance->id,
'person' => 'synthetic-person-finance', 'actions' => ['view', 'payments_view']];
$result = $service->save($admin, 'access', $payload);
expect($result['replayed'])->toBeFalse()->and($service->save($admin, 'access', $payload)['replayed'])->toBeTrue()
->and(DB::table('pa_access')->where('user_id', $finance->id)->count())->toBe(2)
->and(DB::table('gl_events')->where('kind', 'configuration.access')->count())->toBe(1);
expect(fn () => $service->save($admin, 'access', [...$payload, 'operation_key' => (string) Str::uuid(), 'actions' => ['view']]))
->toThrow(DomainException::class);
$finance->forceFill(['purchasing_role' => PurchasingRole::Warehouse])->save();
$fresh = $service->workspace($admin, $finance->id);
expect($fresh['selectedAccess']['eligible'])->toBeFalse();
expect(fn () => $service->save($admin, 'access', [...$payload, 'operation_key' => (string) Str::uuid(), 'basis_hash' => $fresh['selectedAccess']['hash']]))
->toThrow(ValidationException::class);
$service->save($admin, 'access', [...$payload, 'operation_key' => (string) Str::uuid(), 'basis_hash' => $fresh['selectedAccess']['hash'], 'actions' => [], 'person' => '']);
expect(DB::table('pa_access')->where('user_id', $finance->id)->count())->toBe(0)
->and(DB::table('gl_journals')->count())->toBe(0)->and(DB::table('ps_payments')->count())->toBe(0);
});
test('company finance configuration creates own chart periods and versioned rules without financial postings', function () {
$admin = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id,
'purchasing_role' => PurchasingRole::Admin]);
$service = app(CommonFinanceAdministration::class);
$this->actingAs($admin);
$save = function (string $kind, array $data) use ($service, $admin) {
$space = $service->workspace($admin);
return $service->save($admin, $kind, $data + ['operation_key' => (string) Str::uuid(),
'basis_hash' => $space[match ($kind) {
'account' => 'accounts', 'period' => 'periods', 'rule' => 'rules'
}]['hash'],
'reason' => 'Explicit synthetic own company financial configuration']);
};
$debit = $save('account', ['code' => '32001', 'label' => 'Synthetic inventory', 'currency' => 'MZN', 'is_movement' => true]);
$credit = $save('account', ['code' => '42001', 'label' => 'Synthetic suppliers', 'currency' => 'MZN', 'is_movement' => true]);
expect(fn () => $save('account', ['code' => '32001', 'label' => 'Duplicate', 'currency' => 'MZN', 'is_movement' => true]))->toThrow(DomainException::class);
$save('period', ['period_key' => 'OWN-2026', 'starts_on' => '2026-01-01', 'ends_on' => '2026-12-31']);
expect(fn () => $save('period', ['period_key' => 'OVERLAP', 'starts_on' => '2026-12-01', 'ends_on' => '2027-01-31']))->toThrow(DomainException::class);
$rule = ['rule_key' => 'OWN-SUPPLIER', 'effect_type' => 'supplier_payable.recognised', 'valid_from' => '2026-01-01',
'valid_to' => '2026-12-31', 'debit_account_id' => $debit['id'], 'credit_account_id' => $credit['id']];
$save('rule', $rule);
$save('rule', $rule);
expect(DB::table('gl_rules')->where('rule_key', 'OWN-SUPPLIER')->orderBy('version')->pluck('version')->all())->toBe([1, 2]);
expect(fn () => $save('rule', [...$rule, 'credit_account_id' => $debit['id']]))->toThrow(ValidationException::class);
expect(DB::table('gl_journals')->count())->toBe(0)->and(DB::table('ps_payments')->count())->toBe(0)
->and(DB::table('stock_movements')->count())->toBe(0);
$this->withoutVite()->actingAs($admin)->get('/administracao/financeiro')->assertOk()
->assertInertia(fn ($page) => $page->component('company/finance')->has('accounts.rows', 2)->has('rules.rows', 2)
->where('commonFinanceNavigation.configuration', true)->where('commonFinanceNavigation.payments', false)
->where('commonFinanceNavigation.ledger', false))
->assertHeader('Cache-Control', 'max-age=0, no-store, private');
});
test('financial configuration HTTP rejects foreign targets and preserves permissions belonging to another contract', function () {
$admin = User::factory()->create(['tenant_id' => $this->f['tenant']->id, 'department_id' => $this->f['department']->id,
'purchasing_role' => PurchasingRole::Admin]);
$finance = User::factory()->create(['tenant_id' => $admin->tenant_id, 'department_id' => $admin->department_id,
'purchasing_role' => PurchasingRole::Finance]);
$foreign = User::factory()->create(['tenant_id' => Tenant::query()->create(['name' => 'Other synthetic company'])->id,
'purchasing_role' => PurchasingRole::Finance]);
$this->actingAs($admin);
$service = app(CommonFinanceAdministration::class);
DB::table('pa_access')->insert(['tenant_id' => $admin->tenant_id, 'company_id' => 0, 'unit_id' => 0,
'user_id' => $finance->id, 'person' => 'shared-synthetic-person', 'action' => 'other-contract.read']);
$space = $service->workspace($admin, $finance->id);
$payload = ['operation_key' => (string) Str::uuid(), 'basis_hash' => $space['selectedAccess']['hash'],
'reason' => 'Explicit synthetic configuration HTTP test', 'user_id' => $finance->id,
'person' => 'shared-synthetic-person', 'actions' => ['view']];
$this->get('/administracao/financeiro?user='.$foreign->id)->assertNotFound();
$this->postJson('/administracao/financeiro/access', [...$payload, 'user_id' => $foreign->id])->assertNotFound();
$this->postJson('/administracao/financeiro/access', [...$payload, 'person' => 'changed-synthetic-person'])->assertConflict();
$this->from('/administracao/financeiro?user='.$finance->id)->post('/administracao/financeiro/access', $payload)->assertRedirect();
$events = DB::table('gl_events')->count();
$this->postJson('/administracao/financeiro/access', $payload)->assertRedirect();
expect(DB::table('gl_events')->count())->toBe($events);
$stale = [...$payload, 'operation_key' => (string) Str::uuid()];
$this->postJson('/administracao/financeiro/access', $stale)->assertConflict();
$this->withHeader('X-Inertia', 'true')->post('/administracao/financeiro/access', $stale)
->assertRedirect()->assertSessionHasErrors('configuration');
$fresh = $service->workspace($admin, $finance->id);
$service->save($admin, 'access', [...$payload, 'operation_key' => (string) Str::uuid(),
'basis_hash' => $fresh['selectedAccess']['hash'], 'actions' => [], 'person' => '']);
expect(DB::table('pa_access')->where('user_id', $finance->id)->pluck('action')->all())->toBe(['other-contract.read'])
->and(DB::table('gl_journals')->count())->toBe(0)->and(DB::table('ps_payments')->count())->toBe(0);
});