vrsao 2
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-08 14:02:01 +02:00
parent bdd766c68a
commit 1106509116
354 changed files with 48275 additions and 24635 deletions
+10 -8
View File
@@ -2,13 +2,15 @@
namespace Tests\Feature;
use App\Jobs\ScanDocumentForMalware;
use App\Console\Commands\ImportDocumentBatch;
use App\Jobs\ScanDocumentForMalware;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Tests\TestCase;
class ImportDocumentBatchTest extends TestCase
@@ -22,7 +24,7 @@ class ImportDocumentBatchTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->batchName = 'test-'.\Illuminate\Support\Str::uuid();
$this->batchName = 'test-'.Str::uuid();
$this->staging = storage_path('app/private/document-import-staging/'.$this->batchName);
File::ensureDirectoryExists($this->staging);
Storage::fake('local');
@@ -47,14 +49,14 @@ class ImportDocumentBatchTest extends TestCase
'version_label' => 'edição de teste', 'category' => 'general', 'topic' => 'test', 'document_type' => 'guide',
];
file_put_contents($this->staging.'/manifest.json', json_encode(['documents' => [$record, $record]], JSON_THROW_ON_ERROR));
$actor = \App\Models\User::factory()->create();
$actor = User::factory()->create();
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json'])->assertSuccessful();
$this->artisan(new ImportDocumentBatch, ['manifest' => $this->batchName.'/manifest.json'])->assertSuccessful();
$this->assertDatabaseCount('documents', 0);
$this->assertDatabaseCount('portal_resources', 0);
$this->assertSame([], Storage::disk('local')->allFiles('portal-documents'));
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json', '--apply' => true, '--actor' => (string) $actor->id])->assertSuccessful();
$this->artisan(new ImportDocumentBatch, ['manifest' => $this->batchName.'/manifest.json', '--apply' => true, '--actor' => (string) $actor->id])->assertSuccessful();
$this->assertDatabaseCount('documents', 1);
$this->assertDatabaseCount('portal_resources', 1);
$document = DB::table('documents')->firstOrFail();
@@ -66,7 +68,7 @@ class ImportDocumentBatchTest extends TestCase
$this->assertDatabaseHas('audit_events', ['actor_user_id' => $actor->id, 'action' => 'private_document_batch_imported']);
Bus::assertDispatchedTimes(ScanDocumentForMalware::class, 1);
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json', '--apply' => true, '--actor' => (string) $actor->id])->assertSuccessful();
$this->artisan(new ImportDocumentBatch, ['manifest' => $this->batchName.'/manifest.json', '--apply' => true, '--actor' => (string) $actor->id])->assertSuccessful();
$this->assertDatabaseCount('documents', 1);
$this->assertDatabaseCount('portal_resources', 1);
$this->assertDatabaseCount('audit_events', 1);
@@ -79,10 +81,10 @@ class ImportDocumentBatchTest extends TestCase
$record = ['external_id' => 'test-document', 'relative_path' => '..\\..\\..\\..\\.env', 'title' => 'Test', 'issuer' => 'Test'];
file_put_contents($this->staging.'/manifest.json', json_encode(['documents' => [$record]], JSON_THROW_ON_ERROR));
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json', '--apply' => true])->assertFailed();
$this->artisan(new ImportDocumentBatch, ['manifest' => $this->batchName.'/manifest.json', '--apply' => true])->assertFailed();
$this->assertDatabaseCount('documents', 0);
$this->artisan(new ImportDocumentBatch(), ['manifest' => $this->batchName.'/manifest.json'])->assertFailed();
$this->artisan(new ImportDocumentBatch, ['manifest' => $this->batchName.'/manifest.json'])->assertFailed();
$this->assertDatabaseCount('documents', 0);
}
}