48 lines
3.0 KiB
PHP
48 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Opportunity;
|
|
use App\Models\User;
|
|
use App\Services\CorridorAgribusinessOpportunities;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
final class CorridorAgribusinessBatchTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_batch_uses_normal_scoped_session_preview_and_idempotent_disclosure_without_touching_other_opportunities(): void
|
|
{
|
|
$target = DB::selectOne('select current_database() as name, inet_server_port() as port');
|
|
$this->assertSame('simulator_fiscal_delta_20261021_test', $target->name);
|
|
$this->assertSame(55441, (int) $target->port);
|
|
$this->withoutVite(); config(['portal.profile_access_enabled' => true]);
|
|
$entries = app(CorridorAgribusinessOpportunities::class)->entries();
|
|
$keys = array_column($entries, 'key');
|
|
$others = Opportunity::withTrashed()->whereNotIn('management_creation_key', $keys)->orWhereNull('management_creation_key')->orderBy('id')->get()->map(fn ($r) => $r->getRawOriginal())->all();
|
|
$count = Opportunity::withTrashed()->count();
|
|
$actor = User::findOrFail(295);
|
|
$this->actingAs($actor)->withSession(['portal.mfa_actor' => $actor->id, 'portal.mfa_at' => time(), 'portal.access_revision' => (int) $actor->portal_access_revision]);
|
|
$base = '/minhas-oportunidades/lotes/agronegocio';
|
|
$this->get($base)->assertOk();
|
|
$this->postJson($base.'/cadastrar', ['manifest_hash' => str_repeat('0', 64), 'confirm' => true])->assertConflict();
|
|
$this->postJson($base.'/cadastrar', ['manifest_hash' => hash('sha256', json_encode($entries, JSON_THROW_ON_ERROR)), 'confirm' => true])->assertOk();
|
|
$this->assertSame($count, Opportunity::withTrashed()->count());
|
|
$previews = $this->postJson($base.'/previa')->assertOk()->json('previews');
|
|
$this->assertCount(34, $previews);
|
|
$input = ['confirm' => true, 'reason' => 'QA: divulgação das fichas expressamente seleccionadas no lote de Agronegócio.',
|
|
'previews' => array_map(fn ($p) => ['id' => $p['id'], 'token' => $p['token'], 'operation_key' => (string) Str::uuid()], $previews)];
|
|
$bad = $input; array_pop($bad['previews']);
|
|
$this->postJson($base.'/divulgar', $bad)->assertUnprocessable();
|
|
$this->postJson($base.'/divulgar', $input)->assertOk();
|
|
$this->postJson($base.'/divulgar', $input)->assertOk();
|
|
$this->assertSame(34, Opportunity::whereIn('management_creation_key', $keys)->published()->count());
|
|
$this->assertSame($others, Opportunity::withTrashed()->whereNotIn('management_creation_key', $keys)->orWhereNull('management_creation_key')->orderBy('id')->get()->map(fn ($r) => $r->getRawOriginal())->all());
|
|
$this->withSession(['portal.mfa_at' => 0])->postJson($base.'/previa')->assertForbidden();
|
|
$this->actingAs(User::factory()->create())->get($base)->assertForbidden();
|
|
}
|
|
}
|