@@ -39,7 +39,8 @@ class InvestmentPortfolioTest extends TestCase
|
||||
{
|
||||
$this->seed(InvestmentPortfolioSeeder::class);
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$reviewer = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email, $reviewer->email]]);
|
||||
$dossier = InvestmentDossier::firstOrFail();
|
||||
$url = '/management/portfolio/'.$dossier->id;
|
||||
$payload = ['version_no' => $dossier->version_no, 'title' => 'Revisao mais recente', 'source' => $dossier->source, 'content' => $dossier->content];
|
||||
@@ -50,7 +51,8 @@ class InvestmentPortfolioTest extends TestCase
|
||||
$this->assertSame('Revisao mais recente', $dossier->fresh()->title);
|
||||
$this->assertSame('draft', $dossier->fresh()->publication_status);
|
||||
$this->assertSame(2, $dossier->fresh()->version_no);
|
||||
$this->post($url.'/publish', [...$approval, 'version_no' => 2])->assertRedirect()->assertSessionHasNoErrors();
|
||||
$this->post($url.'/publish', [...$approval, 'version_no' => 2])->assertForbidden();
|
||||
$this->actingAs($reviewer)->post($url.'/publish', [...$approval, 'version_no' => 2])->assertRedirect()->assertSessionHasNoErrors();
|
||||
$this->assertSame(3, $dossier->fresh()->version_no);
|
||||
$this->assertSame('published', $dossier->fresh()->publication_status);
|
||||
$this->postJson($url.'/publish', [...$approval, 'version_no' => 2])->assertStatus(409);
|
||||
@@ -71,9 +73,9 @@ class InvestmentPortfolioTest extends TestCase
|
||||
$this->actingAs($editor)->put('/management/portfolio/'.$dossier->id,
|
||||
['version_no' => $dossier->version_no, 'title' => $dossier->title, 'source' => $dossier->source, 'content' => $dossier->content])->assertSessionHasNoErrors();
|
||||
$evidence = ['approval_evidence' => 'Autorização fictícia apenas para teste'];
|
||||
$this->post('/management/portfolio/'.$dossier->id.'/publish', [...$evidence, 'version_no' => $dossier->fresh()->version_no])->assertSessionHasNoErrors()->assertRedirect();
|
||||
$this->assertSame($editor->id, $dossier->fresh()->reviewer_id);
|
||||
$this->post('/management/portfolio/'.$dossier->id.'/publish', [...$evidence, 'version_no' => $dossier->fresh()->version_no])->assertForbidden();
|
||||
$this->actingAs($reviewer)->post('/management/portfolio/'.$dossier->id.'/publish', [...$evidence, 'version_no' => $dossier->fresh()->version_no])->assertSessionHasNoErrors()->assertRedirect();
|
||||
$this->assertSame($reviewer->id, $dossier->fresh()->reviewer_id);
|
||||
|
||||
return $dossier->fresh();
|
||||
}
|
||||
@@ -89,23 +91,28 @@ class InvestmentPortfolioTest extends TestCase
|
||||
$this->post('/management/portfolio/'.$dossier->id.'/publish', ['approval_evidence' => 'Tentativa sem privilégios de gestão'])->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_owner_approval_publishes_document_once_and_preserves_later_edits(): void
|
||||
public function test_import_keeps_documentary_dossiers_private_and_preserves_later_edits(): void
|
||||
{
|
||||
$approval = 'Aprovação expressa do proprietário para executar a carteira v4.';
|
||||
$this->artisan('portfolio:import', ['--approval' => $approval])->assertSuccessful();
|
||||
$this->assertSame(29, InvestmentDossier::where('publication_status', 'published')->count());
|
||||
$this->assertSame(29, DB::table('audit_events')->where('action', 'owner_approved')->count());
|
||||
$this->artisan('portfolio:import')->assertSuccessful();
|
||||
$this->assertSame(0, InvestmentDossier::where('publication_status', 'published')->count());
|
||||
$this->assertSame(29, InvestmentDossier::where('publication_status', 'draft')->count());
|
||||
$this->assertSame(0, DB::table('audit_events')->where('action', 'owner_approved')->count());
|
||||
$dossier = InvestmentDossier::firstOrFail();
|
||||
$this->get('/carteira/'.$dossier->id)->assertInertia(fn (Assert $page) => $page
|
||||
->missing('record.approval_evidence')->missing('record.approval_basis'));
|
||||
$this->artisan('portfolio:import', ['--approval' => $approval])->assertSuccessful();
|
||||
$this->assertSame(29, DB::table('audit_events')->where('action', 'owner_approved')->count());
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager)->post('/management/portfolio/'.$dossier->id.'/publish', [
|
||||
'version_no' => $dossier->version_no, 'approval_evidence' => 'Synthetic owner approval is not an editor assignment',
|
||||
])->assertStatus(422);
|
||||
$this->get('/carteira/'.$dossier->id)->assertNotFound();
|
||||
$this->artisan('portfolio:import')->assertSuccessful();
|
||||
$this->assertSame(0, DB::table('audit_events')->where('action', 'owner_approved')->count());
|
||||
$editor = User::factory()->create();
|
||||
config(['portal.managers' => [$editor->email]]);
|
||||
$this->actingAs($editor)->put('/management/portfolio/'.$dossier->id, [
|
||||
'version_no' => $dossier->version_no, 'title' => 'Alteração posterior', 'source' => $dossier->source, 'content' => $dossier->content,
|
||||
])->assertSessionHasNoErrors();
|
||||
$this->artisan('portfolio:import', ['--approval' => $approval])->assertSuccessful();
|
||||
$this->artisan('portfolio:import')->assertSuccessful();
|
||||
$this->assertSame('draft', $dossier->fresh()->publication_status);
|
||||
$this->assertSame('Alteração posterior', $dossier->fresh()->title);
|
||||
$this->get('/carteira/'.$dossier->id)->assertNotFound();
|
||||
@@ -147,6 +154,36 @@ class InvestmentPortfolioTest extends TestCase
|
||||
$this->assertDatabaseCount('investors', 1);
|
||||
}
|
||||
|
||||
public function test_private_manifestation_link_requires_authentication_and_preserves_the_public_dossier(): void
|
||||
{
|
||||
$dossier = $this->publish();
|
||||
$this->app['auth']->forgetGuards();
|
||||
$dossierId = $dossier->id;
|
||||
$owner = User::factory()->create();
|
||||
$other = User::factory()->create();
|
||||
|
||||
$this->postJson('/api/v1/investment/submissions', ['dossier_id' => $dossierId])->assertUnauthorized();
|
||||
$this->assertDatabaseCount('investment_submissions', 0);
|
||||
|
||||
$this->actingAs($owner)->get('/carteira/'.$dossierId)
|
||||
->assertInertia(fn (Assert $page) => $page->component('portfolio/show')->has('existingSubmissions', 0));
|
||||
$submissionId = $this->postJson('/api/v1/investment/submissions', ['dossier_id' => $dossierId])
|
||||
->assertCreated()->json('id');
|
||||
|
||||
$this->assertDatabaseHas('investment_submissions', [
|
||||
'id' => $submissionId,
|
||||
'user_id' => $owner->id,
|
||||
'dossier_id' => $dossierId,
|
||||
'status' => 'draft',
|
||||
]);
|
||||
$this->assertSame('published', $dossier->fresh()->publication_status);
|
||||
$this->actingAs($owner)->get('/carteira/'.$dossierId)
|
||||
->assertInertia(fn (Assert $page) => $page->has('existingSubmissions', 1)->where('existingSubmissions.0.id', $submissionId));
|
||||
$this->actingAs($other)->get('/investidor/manifestacoes/'.$submissionId)->assertNotFound();
|
||||
$this->assertDatabaseCount('investment_submissions', 1);
|
||||
$this->assertDatabaseCount('investment_dossiers', 29);
|
||||
}
|
||||
|
||||
public function test_unpublished_and_deleted_entities_cannot_start_journeys(): void
|
||||
{
|
||||
$dossier = $this->publish();
|
||||
@@ -163,6 +200,11 @@ class InvestmentPortfolioTest extends TestCase
|
||||
$origin = InvestmentDossier::where('corridor_id', $corridorId)->firstOrFail();
|
||||
$origin->update(['editor_id' => $project->editor_id, 'reviewer_id' => $project->reviewer_id,
|
||||
'publication_status' => 'published', 'published_at' => now(), 'approval_evidence' => 'Teste de contexto autorizado']);
|
||||
$this->actingAs(User::factory()->create())->post('/investidor/guardar/'.$project->id, ['origin_id' => $origin->id])->assertStatus(422);
|
||||
DB::table('corridor_projects')->where('project_id', $project->project_id)->where('corridor_id', $corridorId)->update([
|
||||
'validation_status' => 'validated', 'source_reference' => 'Fixture de teste com fonte identificada',
|
||||
'evidence_reference' => 'fixture:test:association', 'valid_from' => today()->toDateString(),
|
||||
]);
|
||||
$other = InvestmentDossier::whereNotNull('project_id')->where('id', '!=', $project->id)->firstOrFail();
|
||||
$other->update(['editor_id' => $project->editor_id, 'reviewer_id' => $project->reviewer_id,
|
||||
'publication_status' => 'published', 'published_at' => now(), 'approval_evidence' => 'Teste de contexto autorizado']);
|
||||
|
||||
Reference in New Issue
Block a user