96 lines
6.3 KiB
PHP
96 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\InterestRequest;
|
|
use App\Models\Opportunity;
|
|
use App\Models\Sector;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Tests\TestCase;
|
|
|
|
class PortalServicesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_public_sections_render_and_desk_requires_login(): void
|
|
{
|
|
foreach (['sectores', 'como-investir', 'legislacao', 'documentos', 'apoio', 'parcerias', 'simulador-fiscal', 'formularios/investidor', 'formularios/empresa'] as $path) {
|
|
$this->get('/'.$path)->assertOk()->assertInertia(fn (Assert $page) => $page->component('portal/services'));
|
|
}
|
|
$this->get('/balcao-virtual')->assertRedirect('/login');
|
|
$this->get('/management/portal-services')->assertRedirect('/login');
|
|
}
|
|
|
|
public function test_support_receipt_is_idempotent_private_and_requires_consent(): void
|
|
{
|
|
$owner = User::factory()->create();
|
|
$payload = ['kind' => 'company', 'fullName' => 'Pessoa de Teste', 'email' => 'test@example.com', 'country' => 'Moçambique',
|
|
'company' => 'Empresa de teste', 'sectorInterest' => 'Agricultura', 'message' => 'Pretendo orientação sobre este investimento.',
|
|
'privacyConsent' => true, 'submission_key' => (string) Str::uuid()];
|
|
$this->actingAs($owner)->post('/apoio', [...$payload, 'privacyConsent' => false])->assertSessionHasErrors('privacyConsent');
|
|
$this->post('/apoio', $payload)->assertSessionHasNoErrors()->assertSessionHas('success');
|
|
$this->post('/apoio', $payload)->assertSessionHasNoErrors();
|
|
$this->assertSame(1, InterestRequest::count());
|
|
$this->assertDatabaseCount('outbox_events', 1);
|
|
$this->get('/balcao-virtual')->assertInertia(fn (Assert $page) => $page->has('requests', 1));
|
|
$this->actingAs(User::factory()->create())->get('/balcao-virtual')->assertInertia(fn (Assert $page) => $page->has('requests', 0));
|
|
$this->post('/apoio', $payload)->assertStatus(409);
|
|
}
|
|
|
|
public function test_partnership_requires_moderation_and_hides_owner_identity(): void
|
|
{
|
|
$owner = User::factory()->create();
|
|
$this->actingAs($owner)->post('/parcerias', ['title' => 'Parceria de teste', 'sector' => 'Agricultura', 'province' => 'Gaza',
|
|
'offer' => 'Capacidade de processamento de teste.', 'seeking' => 'Parceiro de logística para teste.', 'publication_consent' => true])->assertSessionHasNoErrors();
|
|
$id = DB::table('portal_partnerships')->value('id');
|
|
$this->get('/parcerias')->assertInertia(fn (Assert $page) => $page->has('partnerships.data', 0));
|
|
$this->post('/management/portal-services/partnerships/'.$id, ['published' => true])->assertForbidden();
|
|
config(['portal.managers' => [$owner->email]]);
|
|
$this->post('/management/portal-services/partnerships/'.$id, ['published' => true])->assertSessionHasNoErrors();
|
|
$this->get('/parcerias')->assertInertia(fn (Assert $page) => $page->has('partnerships.data', 1)->missing('partnerships.data.0.user_id'));
|
|
$this->post('/management/portal-services/partnerships/'.$id, ['published' => false])->assertSessionHasNoErrors();
|
|
$this->get('/parcerias')->assertInertia(fn (Assert $page) => $page->has('partnerships.data', 0));
|
|
}
|
|
|
|
public function test_document_download_rechecks_classification_checksum_and_publication(): void
|
|
{
|
|
Storage::fake('local');
|
|
$manager = User::factory()->create();
|
|
config(['portal.managers' => [$manager->email]]);
|
|
$this->actingAs($manager)->post('/management/portal-services/upload', ['file' => UploadedFile::fake()->createWithContent('exemplo.txt', 'Documento sintético de teste.'),
|
|
'publication_consent' => true])->assertSessionHasNoErrors();
|
|
$document = DB::table('documents')->first();
|
|
$this->post('/management/portal-services/resources', ['document_id' => $document->id, 'title' => 'Guia de teste', 'category' => 'Guia', 'topic' => 'Investimento',
|
|
'source_reference' => 'Fonte sintética apenas para testes', 'legislation' => true, 'essential' => true, 'published' => true])->assertSessionHasNoErrors();
|
|
$id = DB::table('portal_resources')->value('id');
|
|
$this->get('/documentos/'.$id.'/download')->assertOk()->assertDownload('exemplo.txt');
|
|
$this->get('/')->assertInertia(fn (Assert $page) => $page->has('essentialResources', 1));
|
|
$this->get('/legislacao')->assertInertia(fn (Assert $page) => $page->has('resources.data', 1)->missing('resources.data.0.storage_key'));
|
|
DB::table('documents')->where('id', $document->id)->update(['data_classification' => 'internal']);
|
|
$this->get('/documentos/'.$id.'/download')->assertNotFound();
|
|
$this->get('/documentos')->assertInertia(fn (Assert $page) => $page->has('resources.data', 0));
|
|
$this->get('/')->assertInertia(fn (Assert $page) => $page->has('essentialResources', 0));
|
|
DB::table('documents')->where('id', $document->id)->update(['data_classification' => 'public']);
|
|
Storage::disk('local')->put($document->storage_key, 'Conteúdo alterado');
|
|
$this->get('/documentos/'.$id.'/download')->assertNotFound();
|
|
}
|
|
|
|
public function test_amount_filters_do_not_mix_currencies_or_expose_drafts(): void
|
|
{
|
|
$sector = Sector::create(['name' => 'Sector de teste', 'slug' => 'sector-teste', 'is_active' => true]);
|
|
foreach ([['USD', 'published'], ['MZN', 'published'], ['USD', 'draft']] as [$currency, $status]) {
|
|
Opportunity::create(['sector_id' => $sector->id, 'reference' => (string) Str::uuid(), 'slug' => (string) Str::uuid(), 'title' => 'Teste de dimensão',
|
|
'status' => $status, 'published_at' => now(), 'estimated_investment_amount' => 500, 'estimated_investment_currency' => $currency]);
|
|
}
|
|
$this->getJson('/api/v1/opportunities/search?min_amount=100')->assertUnprocessable();
|
|
$this->getJson('/api/v1/opportunities/search?currency=USD&min_amount=100&max_amount=600')->assertOk()->assertJsonPath('total', 1);
|
|
$this->getJson('/api/v1/opportunities/search?currency=USD&min_amount=600&max_amount=100')->assertUnprocessable();
|
|
}
|
|
}
|