@@ -10,11 +10,43 @@ use App\Services\PrivateAuditExporter;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
require_once __DIR__.'/../Support/ReceiptFixture.php';
|
||||
require_once __DIR__.'/../Support/SupplyFixture.php';
|
||||
|
||||
test('context activation preserves only explicitly pinned own legacy archives and keeps original bytes and family authority', function () {
|
||||
$service = app(PrivateAuditExporter::class);
|
||||
$export = $service->generate($this->actor, ['operation_key' => (string) Str::uuid(), 'families' => ['purchasing'], 'purpose' => 'Synthetic transition regression']);
|
||||
$before = DB::table('private_audit_exports')->where('id', $export->id)->first();
|
||||
$this->f['tenant']->update(['work_context_policy' => ['revision' => 1, 'enabled' => ['procurement.internal']]]);
|
||||
config(['work_context.entitlements.'.$this->actor->tenant_id => ['procurement.internal']]);
|
||||
DB::table('organization_profiles')->where('tenant_id', $this->actor->tenant_id)->update(['work_contexts' => json_encode(['procurement.internal'])]);
|
||||
$this->post('/contexto', ['area' => 'procurement', 'option' => 'procurement.internal'])->assertRedirect('/dashboard');
|
||||
$this->get('/auditoria/privada')->assertOk()->assertInertia(fn (AssertableInertia $page) => $page->where('exports.total', 0));
|
||||
$this->get('/auditoria/privada/'.$export->id.'/download')->assertStatus(409);
|
||||
config(['private-audit.legacy_export_transitions.'.$this->actor->tenant_id => [$export->id => str_repeat('0', 64)]]);
|
||||
$this->get('/auditoria/privada/'.$export->id.'/download')->assertStatus(409);
|
||||
config(['private-audit.legacy_export_transitions.'.$this->actor->tenant_id => [$export->id => $export->sha256]]);
|
||||
$this->get('/auditoria/privada')->assertOk()->assertInertia(fn (AssertableInertia $page) => $page->where('exports.total', 1));
|
||||
$this->get('/auditoria/privada/'.$export->id.'/download')->assertOk();
|
||||
expect(DB::table('private_audit_exports')->where('id', $export->id)->first())->toEqual($before)
|
||||
->and(hash_file('sha256', Storage::disk('local')->path($export->path)))->toBe($export->sha256)
|
||||
->and(app(PrivateAuditAccess::class)->legacyExportIds($this->actor, 'people.internal'))->toBe([]);
|
||||
$other = User::factory()->create(['tenant_id' => $this->actor->tenant_id, 'department_id' => $this->actor->department_id, 'purchasing_role' => PurchasingRole::Configured]);
|
||||
supplyGrant($other, ['audit_private_purchasing_read']);
|
||||
$otherProfiles = DB::table('organization_memberships')->where('user_id', $other->id)->pluck('profile_id');
|
||||
DB::table('organization_profiles')->whereIn('id', $otherProfiles)->update(['work_contexts' => json_encode(['procurement.internal'])]);
|
||||
$this->actingAs($other)->post('/contexto', ['area' => 'procurement', 'option' => 'procurement.internal'])->assertRedirect('/dashboard');
|
||||
$this->get('/auditoria/privada')->assertOk()->assertInertia(fn (AssertableInertia $page) => $page->where('exports.total', 0));
|
||||
$this->get('/auditoria/privada/'.$export->id.'/download')->assertNotFound();
|
||||
$this->actingAs($this->actor)->post('/contexto', ['area' => 'procurement', 'option' => 'procurement.internal'])->assertRedirect('/dashboard');
|
||||
$profiles = DB::table('organization_memberships')->where('user_id', $this->actor->id)->pluck('profile_id');
|
||||
DB::table('organization_profiles')->whereIn('id', $profiles)->update(['permissions' => json_encode(['audit_private_stock_read'])]);
|
||||
$this->get('/auditoria/privada/'.$export->id.'/download')->assertForbidden();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
config(['private-audit.qa_enabled' => true]);
|
||||
Storage::fake('local');
|
||||
|
||||
Reference in New Issue
Block a user