feat: consolidar desenvolvimentos do portal InvestMoz
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Services\OpportunityCanonicalValue;
|
||||
use App\Services\OpportunityCategoryFields;
|
||||
use App\Services\OpportunityCompleteness;
|
||||
use App\Services\OpportunityManagement;
|
||||
use App\Services\OpportunityMaturity;
|
||||
use App\Services\OpportunityModularProfiles;
|
||||
use App\Services\OpportunityReviewMateriality;
|
||||
use App\Services\PortalProfileAccess;
|
||||
@@ -23,6 +24,7 @@ use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
class OpportunityCanonicalWorkflowTest extends TestCase
|
||||
@@ -424,6 +426,124 @@ class OpportunityCanonicalWorkflowTest extends TestCase
|
||||
$this->assertNotSame($before['approval']['review_cycle'], $published['approval']['review_cycle']);
|
||||
}
|
||||
|
||||
/** @return array<string,array{string,int,string}> */
|
||||
public static function maturityStages(): array
|
||||
{
|
||||
$cases = [];
|
||||
foreach (OpportunityMaturity::STAGES as $stage => $label) {
|
||||
$cases[$stage] = [$stage, count($cases) + 1, $label];
|
||||
}
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $payload */
|
||||
private function maturityLocation(array $payload): void
|
||||
{
|
||||
$location = json_decode(DB::table('opportunity_location_drafts')->where('id', $payload['locations'][0])->value('payload'), true);
|
||||
$country = (string) Str::uuid();
|
||||
DB::table('geo_locations')->insert(['id' => $country, 'code' => $country, 'name' => 'Synthetic QA maturity country', 'location_type' => 'country',
|
||||
'data_classification' => 'public', 'source_system' => 'cartografia-workbook',
|
||||
'external_id' => '964a187ad32ea553b9e112cd159caa90b900050c42b7329594a75bcd798a96ff:'.$country]);
|
||||
DB::table('geo_locations')->where('id', $location['province_id'])->update(['parent_id' => $country]);
|
||||
foreach ([$location['province_id'], $location['district_id']] as $territory) {
|
||||
DB::table('geo_locations')->where('id', $territory)->update(['data_classification' => 'public', 'source_system' => 'cartografia-workbook',
|
||||
'external_id' => '964a187ad32ea553b9e112cd159caa90b900050c42b7329594a75bcd798a96ff:'.$territory]);
|
||||
}
|
||||
}
|
||||
|
||||
#[DataProvider('maturityStages')]
|
||||
public function test_clearing_an_optional_stage_does_not_reinterpret_its_published_number_as_historical(string $stage, int $position, string $label): void
|
||||
{
|
||||
[$id, $promoter, $validator, $publisher, $payload, $document] = $this->fixture();
|
||||
$this->maturityLocation($payload);
|
||||
$payload['maturity_stage'] = $stage;
|
||||
if ($position >= 4) {
|
||||
$payload['financial_indicators'] = ['npv' => 123, 'irr' => 6, 'payback_years' => 5, 'horizon_years' => 10,
|
||||
'discount_rate' => 7, 'currency' => 'MZN', 'scenario' => 'SYNTHETIC policy fixture, not a real financial model', 'model_document_id' => $document];
|
||||
}
|
||||
foreach ([1, 2] as $cycle) {
|
||||
$this->loginFixture($promoter)->putJson('/minhas-oportunidades/'.$id.'/draft', [
|
||||
'etag' => app(OpportunityManagement::class)->etag(Opportunity::findOrFail($id)),
|
||||
'canonical' => $payload, 'reason' => self::REASON,
|
||||
])->assertOk();
|
||||
$this->assertSame($payload['maturity_stage'], app(OpportunityManagement::class)->values(Opportunity::findOrFail($id))['canonical']['maturity_stage']);
|
||||
$this->action($promoter, $id, 'submit');
|
||||
$this->action($validator, $id, 'start_review');
|
||||
foreach (['property_review', 'registry_urban_review', 'building_compliance_review'] as $gate) {
|
||||
$this->action($validator, $id, 'review_gate', ['gate' => $gate, 'gate_decision' => 'approved', 'evidence_document_ids' => [$document]]);
|
||||
}
|
||||
$this->action($validator, $id, 'approve');
|
||||
$this->action($publisher, $id, 'publish');
|
||||
$record = Opportunity::findOrFail($id);
|
||||
$this->assertSame($cycle === 1 ? $position : null, $record->maturity_level);
|
||||
$this->assertSame($cycle === 1 ? $label : null, $record->maturity_label);
|
||||
$this->assertEquals(['catalogue_version' => OpportunityMaturity::VERSION, 'stage' => $cycle === 1 ? $stage : null,
|
||||
'level' => $cycle === 1 ? $position : null, 'label' => $cycle === 1 ? $label : null], data_get($record->workflow_context, 'publication.maturity'));
|
||||
$query = Opportunity::whereKey($id);
|
||||
OpportunityMaturity::constrainSearch($query, 'historical:'.$position);
|
||||
$this->assertSame(0, $query->count());
|
||||
$query = Opportunity::whereKey($id);
|
||||
OpportunityMaturity::constrainSearch($query, 'stage:'.$stage);
|
||||
$this->assertSame($cycle === 1 ? 1 : 0, $query->count());
|
||||
$this->assertSame(0, Opportunity::published()->whereKey($id)->count());
|
||||
if ($cycle === 1) {
|
||||
$this->action($publisher, $id, 'suspend');
|
||||
$this->action($promoter, $id, 'request_revision');
|
||||
$payload['maturity_stage'] = null;
|
||||
}
|
||||
}
|
||||
$this->assertSame($stage, data_get($record->workflow_context, 'publication_history.0.maturity.stage'));
|
||||
}
|
||||
|
||||
public function test_unknown_optional_maturity_stage_is_reported_before_review(): void
|
||||
{
|
||||
[$id, $promoter, , , $payload] = $this->fixture();
|
||||
$payload['maturity_stage'] = 'SYNTHETIC-NOT-A-CATALOGUE-STAGE';
|
||||
$this->loginFixture($promoter)->putJson('/minhas-oportunidades/'.$id.'/draft', [
|
||||
'etag' => app(OpportunityManagement::class)->etag(Opportunity::findOrFail($id)),
|
||||
'canonical' => $payload, 'reason' => self::REASON,
|
||||
])->assertUnprocessable()->assertJsonValidationErrors('canonical.maturity_stage');
|
||||
$this->assertSame('draft', Opportunity::findOrFail($id)->status);
|
||||
$this->assertArrayNotHasKey('maturity_stage', app(OpportunityManagement::class)->values(Opportunity::findOrFail($id))['canonical']);
|
||||
}
|
||||
|
||||
/** @return array<int,array{int,string}> */
|
||||
public static function historicalMaturityLevels(): array
|
||||
{
|
||||
$cases = [];
|
||||
foreach (OpportunityMaturity::LEGACY_LABELS as $level => $label) {
|
||||
$cases[] = [$level, $label];
|
||||
}
|
||||
|
||||
return $cases;
|
||||
}
|
||||
|
||||
#[DataProvider('historicalMaturityLevels')]
|
||||
public function test_publication_without_a_maturity_stage_retains_its_legacy_level(int $level, string $label): void
|
||||
{
|
||||
[$id, $promoter, $validator, $publisher, $payload, $document] = $this->fixture();
|
||||
$this->maturityLocation($payload);
|
||||
Opportunity::findOrFail($id)->forceFill(['maturity_level' => $level, 'maturity_label' => $label])->save();
|
||||
$this->action($promoter, $id, 'submit');
|
||||
$this->action($validator, $id, 'start_review');
|
||||
foreach (['property_review', 'registry_urban_review', 'building_compliance_review'] as $gate) {
|
||||
$this->action($validator, $id, 'review_gate', ['gate' => $gate, 'gate_decision' => 'approved', 'evidence_document_ids' => [$document]]);
|
||||
}
|
||||
$this->action($validator, $id, 'approve');
|
||||
$this->action($publisher, $id, 'publish');
|
||||
$record = Opportunity::findOrFail($id);
|
||||
$this->assertSame($level, $record->maturity_level);
|
||||
$this->assertSame($label, $record->maturity_label);
|
||||
$query = Opportunity::whereKey($id);
|
||||
OpportunityMaturity::constrainSearch($query, 'historical:'.$level);
|
||||
$this->assertSame(1, $query->count());
|
||||
$query = Opportunity::whereKey($id);
|
||||
OpportunityMaturity::constrainSearch($query, 'stage:'.array_keys(OpportunityMaturity::STAGES)[$level - 1]);
|
||||
$this->assertSame(0, $query->count());
|
||||
$this->assertSame(0, Opportunity::published()->whereKey($id)->count());
|
||||
}
|
||||
|
||||
public function test_semantic_errors_are_keyed_to_fields_and_incomplete_drafts_remain_recoverable(): void
|
||||
{
|
||||
[$id,$promoter,$validator,$publisher,$payload,$document] = $this->fixture();
|
||||
|
||||
Reference in New Issue
Block a user