fix: added upload formular, reorganized some files and put them into a new folder misc
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\Backend\Transaction;
|
||||
use App\Models\Backend\TransactionOutput;
|
||||
|
||||
test('can connect to backend schema', function () {
|
||||
$count = Transaction::count();
|
||||
|
||||
expect($count)->toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
test('can read transactions from backend schema', function () {
|
||||
$transaction = Transaction::first();
|
||||
|
||||
if ($transaction) {
|
||||
expect($transaction)->toBeInstanceOf(Transaction::class);
|
||||
expect($transaction->corporate_entity)->toBeString();
|
||||
expect($transaction->corporate_counterparty)->toBeString();
|
||||
expect($transaction->tx_amount)->not->toBeNull();
|
||||
} else {
|
||||
expect(true)->toBeTrue(); // No transactions yet
|
||||
}
|
||||
});
|
||||
|
||||
test('can read transaction outputs', function () {
|
||||
$output = TransactionOutput::first();
|
||||
|
||||
if ($output) {
|
||||
expect($output)->toBeInstanceOf(TransactionOutput::class);
|
||||
expect($output->transaction_id)->toBeInt();
|
||||
expect($output->output_key)->toBeString();
|
||||
expect($output->content)->toBeArray();
|
||||
} else {
|
||||
expect(true)->toBeTrue(); // No outputs yet
|
||||
}
|
||||
});
|
||||
|
||||
test('transaction has outputs relationship', function () {
|
||||
$transaction = Transaction::with('outputs')->first();
|
||||
|
||||
if ($transaction) {
|
||||
expect($transaction->outputs)->toBeInstanceOf(\Illuminate\Database\Eloquent\Collection::class);
|
||||
} else {
|
||||
expect(true)->toBeTrue(); // No transactions yet
|
||||
}
|
||||
});
|
||||
|
||||
test('can get specific output by key', function () {
|
||||
$transaction = Transaction::with('outputs')->first();
|
||||
|
||||
if ($transaction && $transaction->outputs->isNotEmpty()) {
|
||||
$firstKey = $transaction->outputs->first()->output_key;
|
||||
$output = $transaction->getOutput($firstKey);
|
||||
|
||||
expect($output)->toBeArray();
|
||||
} else {
|
||||
expect(true)->toBeTrue(); // No transactions with outputs yet
|
||||
}
|
||||
});
|
||||
|
||||
test('can get company info from transaction', function () {
|
||||
$transaction = Transaction::with('outputs')->first();
|
||||
|
||||
if ($transaction) {
|
||||
$companyInfo = $transaction->getCompanyInfo();
|
||||
|
||||
// Kann null sein wenn kein company_info output existiert
|
||||
expect($companyInfo)->toBeIn([null, 'array']);
|
||||
} else {
|
||||
expect(true)->toBeTrue();
|
||||
}
|
||||
});
|
||||
|
||||
test('can get risk assessment from transaction', function () {
|
||||
$transaction = Transaction::with('outputs')->first();
|
||||
|
||||
if ($transaction) {
|
||||
$risk = $transaction->getRiskAssessment();
|
||||
|
||||
// Kann null sein wenn kein risk_assessment output existiert
|
||||
expect($risk)->toBeIn([null, 'array']);
|
||||
|
||||
if ($risk) {
|
||||
expect($risk)->toHaveKey('score');
|
||||
}
|
||||
} else {
|
||||
expect(true)->toBeTrue();
|
||||
}
|
||||
});
|
||||
|
||||
test('can check if transaction requires review', function () {
|
||||
$transaction = Transaction::with('outputs')->first();
|
||||
|
||||
if ($transaction) {
|
||||
$requiresReview = $transaction->requiresReview();
|
||||
|
||||
expect($requiresReview)->toBeBool();
|
||||
} else {
|
||||
expect(true)->toBeTrue();
|
||||
}
|
||||
});
|
||||
|
||||
test('transaction output keys constants exist', function () {
|
||||
expect(TransactionOutput::KEY_COMPANY_INFO)->toBe('company_info');
|
||||
expect(TransactionOutput::KEY_RISK_ASSESSMENT)->toBe('risk_assessment');
|
||||
expect(TransactionOutput::KEY_SANCTIONS)->toBe('sanctions');
|
||||
expect(TransactionOutput::KEY_PEP)->toBe('pep');
|
||||
});
|
||||
|
||||
test('can get all available output keys', function () {
|
||||
$keys = TransactionOutput::availableKeys();
|
||||
|
||||
expect($keys)->toBeArray();
|
||||
expect($keys)->toContain('company_info');
|
||||
expect($keys)->toContain('risk_assessment');
|
||||
});
|
||||
|
||||
test('can get label for output key', function () {
|
||||
$label = TransactionOutput::getKeyLabel('company_info');
|
||||
|
||||
expect($label)->toBe('Company Information');
|
||||
|
||||
$label = TransactionOutput::getKeyLabel('risk_assessment');
|
||||
|
||||
expect($label)->toBe('Risk Assessment');
|
||||
});
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Volt\Volt;
|
||||
|
||||
it('requires authentication to access upload page', function () {
|
||||
$response = $this->get('/upload');
|
||||
|
||||
$response->assertRedirect('/login');
|
||||
});
|
||||
|
||||
it('can render upload page when authenticated', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$component = Volt::test('upload.index');
|
||||
|
||||
$component
|
||||
->assertSee('File Upload')
|
||||
->assertSee('Select File')
|
||||
->assertSee('Maximum file size: 50 MB')
|
||||
->assertSee('https://upload.trai.mcs.local/api/upload');
|
||||
});
|
||||
|
||||
it('can upload file successfully', function () {
|
||||
Http::fake([
|
||||
'https://upload.trai.mcs.local/api/upload' => Http::response('Success', 200),
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Storage::fake('local');
|
||||
|
||||
$file = UploadedFile::fake()->create('document.pdf', 100);
|
||||
|
||||
Volt::test('upload.index')
|
||||
->set('file', $file)
|
||||
->call('upload')
|
||||
->assertSet('uploadStatus', 'success')
|
||||
->assertSet('uploadMessage', 'File uploaded successfully!')
|
||||
->assertSet('file', null);
|
||||
});
|
||||
|
||||
it('validates file is required', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Volt::test('upload.index')
|
||||
->set('file', null)
|
||||
->call('upload')
|
||||
->assertHasErrors(['file' => 'required']);
|
||||
});
|
||||
|
||||
it('validates file size limit', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Storage::fake('local');
|
||||
|
||||
$file = UploadedFile::fake()->create('large.pdf', 51201); // Exceeds 50MB
|
||||
|
||||
Volt::test('upload.index')
|
||||
->set('file', $file)
|
||||
->call('upload')
|
||||
->assertHasErrors('file');
|
||||
});
|
||||
|
||||
it('handles upload errors gracefully', function () {
|
||||
Http::fake([
|
||||
'https://upload.trai.mcs.local/api/upload' => Http::response('Server Error', 500),
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Storage::fake('local');
|
||||
|
||||
$file = UploadedFile::fake()->create('document.pdf', 100);
|
||||
|
||||
Volt::test('upload.index')
|
||||
->set('file', $file)
|
||||
->call('upload')
|
||||
->assertSet('uploadStatus', 'error')
|
||||
->assertSee('Upload failed');
|
||||
});
|
||||
|
||||
it('can clear selected file', function () {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Storage::fake('local');
|
||||
|
||||
$file = UploadedFile::fake()->create('document.pdf', 100);
|
||||
|
||||
Volt::test('upload.index')
|
||||
->set('file', $file)
|
||||
->assertSet('file', fn ($value) => $value !== null)
|
||||
->set('file', null)
|
||||
->assertSet('file', null);
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
it('displays upload link in navigation for authenticated users', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get('/dashboard')
|
||||
->assertSee('Datei-Upload')
|
||||
->assertSee(route('upload'));
|
||||
});
|
||||
Reference in New Issue
Block a user