fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\Sector;
|
||||
use App\Models\User;
|
||||
use App\Services\InvestmentCatalogue;
|
||||
use App\Services\InvestmentGeography;
|
||||
use App\Services\OpportunityClassification;
|
||||
use App\Services\OpportunityManagement;
|
||||
use Database\Seeders\InvestmentAreaSeeder;
|
||||
use Illuminate\Database\QueryException;
|
||||
@@ -17,10 +18,12 @@ use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Tests\Support\AuthenticatesQaActors;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvestmentTerritoryTest extends TestCase
|
||||
{
|
||||
use AuthenticatesQaActors;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_confirmed_coordinates_create_a_marker_without_hiding_missing_records(): void
|
||||
@@ -33,7 +36,7 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$this->get('/oportunidades')->assertInertia(fn (AssertableInertia $page) => $page->where('results.total', 1)->where('results.data.0.id', $record->id));
|
||||
$this->getJson('/api/v1/investment/map')->assertOk()->assertJsonPath('matched_count', 1)
|
||||
->assertJsonPath('georeferenced_count', 0)->assertJsonPath('complete', false)->assertJsonCount(1, 'unlocated');
|
||||
$this->actingAs($manager);
|
||||
$this->actingAsWithMfa($manager);
|
||||
$url = '/management/opportunities/'.$record->id.'/coordinates';
|
||||
$payload = ['version' => 0, 'latitude' => -25.9, 'longitude' => 32.5, 'source_reference' => 'Synthetic coordinates for automated tests only', 'confirmed_site' => true];
|
||||
$this->postJson($url, [...$payload, 'latitude' => 91])->assertUnprocessable();
|
||||
@@ -73,13 +76,15 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$this->getJson('/oportunidades?province_id='.$private)->assertUnprocessable();
|
||||
$this->get('/oportunidades?province_id='.$province)->assertOk();
|
||||
$this->assertCount(2, $service->context($opportunity->id)['primary_territory_path']);
|
||||
$this->assertEqualsCanonicalizing([$country, $province, $district, $other], app(OpportunityClassification::class)->targets('location')->pluck('id')->all());
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$created = $this->actingAs($manager)->postJson('/management/opportunities/drafts', ['sector_id' => $sector->id, 'creation_key' => (string) Str::uuid(), 'reason' => 'Cadastro territorial de rascunho apenas em QA', 'title' => 'Synthetic create',
|
||||
$created = $this->actingAsWithMfa($manager)->postJson('/management/opportunities/drafts', ['sector_id' => $sector->id, 'creation_key' => (string) Str::uuid(), 'reason' => 'Cadastro territorial de rascunho apenas em QA', 'title' => 'Synthetic create',
|
||||
'estimated_investment_currency' => 'USD', 'province_id' => $province, 'district_id' => $district])->assertCreated()->json();
|
||||
$this->assertDatabaseHas('opportunities', ['id' => $created['id'], 'primary_territory_id' => $district]);
|
||||
$this->post('/management/clusters', ['code' => 'GEO-CREATE', 'name' => 'Synthetic cluster', 'sector' => 'Synthetic', 'status' => 'planned', 'province_id' => $province, 'district_id' => $district])->assertRedirect();
|
||||
$this->assertDatabaseHas('economic_clusters', ['code' => 'GEO-CREATE', 'primary_territory_id' => $district]);
|
||||
$this->actingAsWithMfa($manager);
|
||||
$manager->forceFill(['two_factor_secret' => Crypt::encryptString('SYNTHETIC'), 'two_factor_confirmed_at' => now()])->save();
|
||||
$zone = $this->postJson('/api/v2/investment/admin/zones', ['code' => 'GEO-ZEE', 'name' => 'Synthetic ZEE', 'category' => 'zee', 'province_id' => $province, 'district_id' => $district])->assertCreated()->json('id');
|
||||
$this->assertDatabaseHas('investment_zones', ['id' => $zone, 'primary_territory_id' => $district]);
|
||||
@@ -250,6 +255,7 @@ class InvestmentTerritoryTest extends TestCase
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$this->actingAsWithMfa($user);
|
||||
$this->actingAs($user);
|
||||
$province = $this->location('province');
|
||||
$other = $this->location('province');
|
||||
@@ -284,9 +290,9 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$province = $this->location('province', $country);
|
||||
$sector = Sector::create(['name' => 'Synthetic edit', 'slug' => 'synthetic-edit', 'is_active' => true]);
|
||||
$record = Opportunity::create(['sector_id' => $sector->id, 'reference' => 'EDIT-GEO', 'slug' => 'edit-geo', 'title' => 'Synthetic edit', 'status' => 'draft']);
|
||||
$this->actingAs($manager)->putJson('/management/opportunities/'.$record->id.'/draft', [
|
||||
$this->actingAsWithMfa($manager)->putJson('/management/opportunities/'.$record->id.'/draft', [
|
||||
'sector_id' => $sector->id, 'reference' => 'EDIT-GEO', 'slug' => 'edit-geo', 'title' => 'Synthetic edit',
|
||||
'status' => 'draft', 'is_featured' => false, 'estimated_investment_currency' => 'USD',
|
||||
'is_featured' => false, 'estimated_investment_currency' => 'USD',
|
||||
'province_id' => $province, 'territory_version' => 0,
|
||||
'etag' => app(OpportunityManagement::class)->etag($record->fresh()), 'reason' => 'Atualização territorial do rascunho em QA',
|
||||
])->assertOk();
|
||||
@@ -299,7 +305,7 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$other = $this->location('province', $country);
|
||||
$district = $this->location('district', $other);
|
||||
$payload = ['sector_id' => $sector->id, 'reference' => 'EDIT-GEO', 'slug' => 'edit-geo', 'title' => 'Must not persist',
|
||||
'status' => 'draft', 'is_featured' => false, 'estimated_investment_currency' => 'USD',
|
||||
'is_featured' => false, 'estimated_investment_currency' => 'USD',
|
||||
'province_id' => $province, 'district_id' => $district, 'territory_version' => 1];
|
||||
$etag = app(OpportunityManagement::class)->etag($record->fresh());
|
||||
$this->putJson('/management/opportunities/'.$record->id.'/draft', [...$payload, 'etag' => $etag, 'reason' => 'Validação de hierarquia no rascunho QA'])->assertUnprocessable()->assertJsonValidationErrors('district_id');
|
||||
@@ -350,7 +356,7 @@ class InvestmentTerritoryTest extends TestCase
|
||||
{
|
||||
$manager = User::factory()->create();
|
||||
config(['portal.managers' => [$manager->email]]);
|
||||
$this->actingAs($manager)->from('/management/opportunities/create')
|
||||
$this->actingAsWithMfa($manager)->from('/management/opportunities/create')
|
||||
->post('/management/opportunities', [])->assertSessionHasErrors('status');
|
||||
$this->withCookie(config('session.cookie'), session()->getId())->withCredentials();
|
||||
$this->getJson('/management/territory-options?type=province')->assertOk()->assertSessionHasErrors('status');
|
||||
|
||||
Reference in New Issue
Block a user