fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -5,16 +5,19 @@ namespace Tests\Feature;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\User;
|
||||
use App\Services\CorridorAgribusinessOpportunities;
|
||||
use App\Services\InvestorContext;
|
||||
use App\Services\InvestmentCorridorContext;
|
||||
use App\Services\VirtualDesk;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
private User $investor;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -25,7 +28,8 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$this->assertSame(55441, (int) $target->port);
|
||||
config(['investor-path.enabled' => true, 'investor-path.private_preparation' => true, 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
|
||||
$this->withoutVite();
|
||||
$this->investor = User::factory()->create(); $this->actingAs($this->investor);
|
||||
$this->investor = User::factory()->create();
|
||||
$this->actingAs($this->investor);
|
||||
}
|
||||
|
||||
private function dossier(): string
|
||||
@@ -39,7 +43,7 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$id = $this->dossier();
|
||||
$before = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json('context');
|
||||
$this->get('/investimentos/'.$id.'/contexto/editar?source=opportunity:'.$record->id)->assertOk()
|
||||
->assertInertia(fn (\Inertia\Testing\AssertableInertia $page) => $page->component('investor-path/context')
|
||||
->assertInertia(fn (AssertableInertia $page) => $page->component('investor-path/context')
|
||||
->where('source.key', 'opportunity:'.$record->id)
|
||||
->where('requestedChoices.0.opportunity.key', 'opportunity:'.$record->id)
|
||||
->where('requestedChoices.0.opportunity.title', $record->title));
|
||||
@@ -51,7 +55,7 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
{
|
||||
$entries = array_slice(app(CorridorAgribusinessOpportunities::class)->entries(), 0, 2);
|
||||
$records = Opportunity::whereIn('management_creation_key', array_column($entries, 'key'))->orderBy('id')->get();
|
||||
$sites = collect(app(\App\Services\InvestmentCorridorContext::class)->provinces('pemba-lichinga'))->pluck('id');
|
||||
$sites = collect(app(InvestmentCorridorContext::class)->provinces('pemba-lichinga'))->pluck('id');
|
||||
$this->get('/investimentos/iniciar?opportunities[]='.$records[0]->id.'&opportunities[]='.$records[1]->id)->assertOk();
|
||||
$id = $this->dossier();
|
||||
$before = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json();
|
||||
@@ -76,12 +80,18 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$this->assertCount(2, $after['context']['opportunity_choices']);
|
||||
$snapshot = json_decode($after['prefill']['simulator']['context_applicability_snapshot'], true);
|
||||
$this->assertSame($after['context']['opportunity_choices'], $snapshot['opportunity_choices']);
|
||||
$this->assertSame('general', $snapshot['fields']['investment_regime']);
|
||||
// Multiple unselected opportunities must not supply a regime to the consumer.
|
||||
$this->assertArrayNotHasKey('investment_regime', $snapshot['fields']);
|
||||
foreach ($after['context']['opportunity_choices'] as $choice) {
|
||||
$this->getJson('/investimentos/'.$id.'/contexto?opportunity='.$choice['opportunity']['key'])->assertOk()->assertJsonPath('prefill.simulator.investment_regime', 'general');
|
||||
}
|
||||
$this->assertArrayNotHasKey('tax_benefit', $snapshot['fields']);
|
||||
$this->get('/investimentos/'.$id)->assertOk();
|
||||
|
||||
$desk = app(VirtualDesk::class); $case = $desk->case($this->investor, $id);
|
||||
$payload = $desk->decode($case->payload); $resultId = (string) Str::uuid();
|
||||
$desk = app(VirtualDesk::class);
|
||||
$case = $desk->case($this->investor, $id);
|
||||
$payload = $desk->decode($case->payload);
|
||||
$resultId = (string) Str::uuid();
|
||||
$payload['investor_path']['results'] = [['id' => $resultId, 'engine' => 'synthetic-qa-history', 'context_state' => 'current', 'value' => 'preserve']];
|
||||
DB::table('desk_cases')->where('id', $id)->update(['payload' => $desk->encode($payload)]);
|
||||
$next = ['version' => $after['case']['version'], 'selection' => [], 'opportunity_choices' => [
|
||||
@@ -98,9 +108,11 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
public function test_documented_location_cannot_change_silently_and_stale_source_cannot_be_confirmed(): void
|
||||
{
|
||||
$record = Opportunity::where('management_creation_key', app(CorridorAgribusinessOpportunities::class)->entries()[0]['key'])->firstOrFail();
|
||||
$sites = collect(app(\App\Services\InvestmentCorridorContext::class)->provinces('pemba-lichinga'))->pluck('id');
|
||||
$record->primary_territory_id = $sites[0]; $record->save();
|
||||
$id = $this->dossier(); $version = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$sites = collect(app(InvestmentCorridorContext::class)->provinces('pemba-lichinga'))->pluck('id');
|
||||
$record->primary_territory_id = $sites[0];
|
||||
$record->save();
|
||||
$id = $this->dossier();
|
||||
$version = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
$input = ['version' => $version, 'selection' => [], 'opportunity_choices' => [['source' => 'opportunity:'.$record->id, 'territory' => 'territory:'.$sites[1]]]];
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', $input)->assertUnprocessable();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', ['version' => $version, 'selection' => ['opportunity' => 'opportunity:'.$record->id, 'territory' => 'territory:'.$sites[1]]])->assertUnprocessable();
|
||||
@@ -112,7 +124,8 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$input['version'] = $this->getJson('/investimentos/'.$id.'/contexto')->json('case.version');
|
||||
unset($input['opportunity_choices'][0]['confirm_location_change']);
|
||||
$plan = $this->postJson('/investimentos/'.$id.'/contexto/previa', $input)->assertOk()->assertJsonPath('dependency_changed', false)->json();
|
||||
$record->title .= ' QA source changed'; $record->save();
|
||||
$record->title .= ' QA source changed';
|
||||
$record->save();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', [...$input, 'preview_hash' => $plan['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertConflict();
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->assertJsonPath('context.revision', 1);
|
||||
}
|
||||
@@ -132,11 +145,15 @@ final class InvestmentOpportunityChoicesTest extends TestCase
|
||||
$this->assertLessThan(1000000, strlen($snapshot));
|
||||
// Mirror the existing browser partition: labels are persisted under selection_labels.
|
||||
$economic = [...$view['prefill']['simulator'], 'purpose' => 'simulate_only', 'currency' => 'MZN'];
|
||||
foreach (array_keys($economic) as $field) if (str_ends_with($field, '_label')) {
|
||||
$economic['selection_labels'][substr($field, 0, -6)] = $economic[$field]; unset($economic[$field]);
|
||||
foreach (array_keys($economic) as $field) {
|
||||
if (str_ends_with($field, '_label')) {
|
||||
$economic['selection_labels'][substr($field, 0, -6)] = $economic[$field];
|
||||
unset($economic[$field]);
|
||||
}
|
||||
}
|
||||
$draft = $this->postJson('/api/v1/simulation-drafts', ['context' => $id, 'personal_snapshot' => [],
|
||||
'economic_snapshot' => $economic], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json();
|
||||
$personalKeys = ['email', 'phone', 'person_type', 'investor_origin', 'tax_residency_country', 'fiscal_residency_country', 'entity_stage'];
|
||||
$draft = $this->postJson('/api/v1/simulation-drafts', ['context' => $id, 'personal_snapshot' => Arr::only($economic, $personalKeys),
|
||||
'economic_snapshot' => Arr::except($economic, $personalKeys)], ['Idempotency-Key' => (string) Str::uuid()])->assertCreated()->json();
|
||||
$this->assertNotEmpty($draft);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->assertJsonPath('context.opportunity_choices.33.opportunity.key', 'opportunity:'.$records[33]->id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user