@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use App\Services\StandaloneSchema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\SQLiteConnection;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->standaloneDb = new SQLiteConnection(new PDO('sqlite::memory:'), ':memory:', '', ['driver' => 'sqlite']);
|
||||
$this->standaloneSchema = $this->standaloneDb->getSchemaBuilder();
|
||||
foreach (['supply_records' => ['id', 'tenant_id', 'kind', 'record_key', 'version', 'data', 'snapshot', 'operation_key'],
|
||||
'requisitions' => ['id', 'tenant_id', 'status'], 'users' => ['id', 'tenant_id']] as $table => $columns) {
|
||||
$this->standaloneSchema->create($table, function (Blueprint $definition) use ($columns) {
|
||||
foreach ($columns as $column) {
|
||||
$definition->text($column)->nullable();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('standalone preflight does not create optional structures when no feature is selected', function () {
|
||||
StandaloneSchema::verify($this->standaloneSchema, ['private-audit' => false]);
|
||||
expect($this->standaloneSchema->hasTable('private_audit_exports'))->toBeFalse()
|
||||
->and($this->standaloneDb->table('supply_records')->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('standalone preflight rejects an incomplete own chart instead of activating account attribution', function () {
|
||||
$this->standaloneSchema->create('gl_accounts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('code');
|
||||
$table->string('label');
|
||||
});
|
||||
expect(fn () => StandaloneSchema::verify($this->standaloneSchema, ['requisition-accounts' => true]))
|
||||
->toThrow(LogicException::class, 'COMPRAS_RUNTIME_SCHEMA_INCOMPLETE:gl_accounts');
|
||||
expect($this->standaloneSchema->hasColumn('gl_accounts', 'tenant_id'))->toBeFalse();
|
||||
});
|
||||
|
||||
test('standalone preflight preserves documented import module dependencies', function (string $feature, string $dependency) {
|
||||
expect(fn () => StandaloneSchema::verify($this->standaloneSchema, [$feature => true, $dependency => false]))
|
||||
->toThrow(LogicException::class, 'COMPRAS_RUNTIME_FEATURE_DEPENDENCY:'.$feature.':'.$dependency);
|
||||
})->with([['import-legal', 'import-tariffs'], ['import-bank-support', 'import-dossier'], ['import-readiness', 'import-dossier']]);
|
||||
|
||||
test('standalone preflight rejects an incomplete cycle schema without repairing it', function () {
|
||||
$this->standaloneSchema->create('budget_requisition_cycles', fn (Blueprint $table) => $table->id());
|
||||
expect(fn () => StandaloneSchema::verify($this->standaloneSchema, ['requisition-expiry' => true]))
|
||||
->toThrow(LogicException::class, 'COMPRAS_RUNTIME_SCHEMA_INCOMPLETE:requisitions');
|
||||
expect($this->standaloneSchema->hasColumn('requisitions', 'approval_cycle'))->toBeFalse();
|
||||
});
|
||||
Reference in New Issue
Block a user