commit compras2 3011
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-30 23:04:25 +02:00
parent 318b62f458
commit c9bd6db90b
39 changed files with 2235 additions and 42 deletions
+35
View File
@@ -382,3 +382,38 @@ test('guests cannot consult or submit declarations', function () {
$this->get('/conflitos')->assertRedirect('/login');
$this->post('/conflitos', personalConflict($this->supplier->id))->assertRedirect('/login');
});
test('composed conflict authority is scoped and never inferred from the environment', function () {
require_once dirname(__DIR__, 2).'/packages/purchasing/src/ExecutionContext.php';
$execution = new \Tempo\Purchasing\Composition\ExecutionContext;
app()->instance(\Tempo\Purchasing\Composition\ExecutionContext::class, $execution);
config(['conflict-releases.qa_enabled' => true]);
$service = app(\App\Services\ConflictReleases::class);
expect($service->ready())->toBeFalse();
$this->post('/conflitos', personalConflict($this->supplier->id, $this->r->id))->assertSessionHasNoErrors();
$declaration = ConflictDeclaration::query()->firstOrFail();
configureConflictDirection($this->admin);
$this->actingAs($this->admin);
app()->instance('env', 'budget-testing');
$metadata = ['contract' => $execution::CONTRACT, 'composition' => 'b4093c6f6707', 'operation' => 'purchasing_conflicts.authorise',
'scope' => ['tenant_id' => 1, 'company_id' => 2, 'unit_id' => 2],
'actor' => ['host_id' => 15, 'native_id' => $this->admin->id],
'generation' => str_repeat('a', 64), 'schema_sha256' => str_repeat('b', 64),
'workflow_sha256' => str_repeat('c', 64), 'features' => ['conflict-release' => []]];
$input = ['operation_key' => (string) Str::uuid(), 'reason' => 'Autorização sintética de direcção no contexto composto.'];
$before = $declaration->getAttributes();
try {
$execution->within($metadata, DB::connection(), fn () => null, function () use ($service, $input, $declaration) {
expect($service->ready())->toBeTrue();
$first = $service->authorise($this->admin, $declaration, $input);
expect($service->authorise($this->admin, $declaration, $input)->id)->toBe($first->id)
->and(ConflictRelease::query()->count())->toBe(1);
DB::table('organization_memberships')->where('user_id', $this->admin->id)->delete();
expect(fn () => $service->authorise($this->admin, $declaration, $input))->toThrow(\Symfony\Component\HttpKernel\Exception\HttpException::class);
});
expect($service->ready())->toBeFalse()->and($declaration->fresh()->getAttributes())->toBe($before);
} finally {
app()->instance('env', 'testing');
app()->forgetInstance(\Tempo\Purchasing\Composition\ExecutionContext::class);
}
});