8 lines
4.5 KiB
PHP
8 lines
4.5 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/geography-demo-smoke.json';if(is_file($out))throw new LogicException('Proof preserved');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$f=json_decode(file_get_contents($s['root'].'/fixture.json'),true);$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true);$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$fp=fn()=>hash('sha256',json_encode([DB::table('geo_locations')->get(),DB::table('geo_location_history')->get(),DB::table('geo_commands')->get()]));$before=$fp();$ok(DB::table('geo_locations')->count()===0&&DB::table('geo_location_history')->count()===0,'demo begins without locations or geographic decisions');$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8069','http_errors'=>false,'timeout'=>25]);
|
|
$enter=function($role,$module='purchasing')use($client){$jar=new GuzzleHttp\Cookie\CookieJar;$r=$client->get('/qa/enter/'.$role,['cookies'=>$jar,'query'=>['module'=>$module]]);return ['jar'=>$jar]+json_decode((string)$r->getBody(),true);};$options=fn($v)=>['cookies'=>$v['jar'],'headers'=>['Accept'=>'application/json','X-SGF-Context'=>$v['context'],'X-CSRF-TOKEN'=>$v['csrf']]];
|
|
foreach(['actor','issuer','validator']as$role){$v=$enter($role);$r=$client->get('/api/geography/entities/company/'.$f['company'],$options($v));$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$d['location']===null&&$d['entity']['editable']===($role!=='validator'),'company location capability matches '.$role);}
|
|
$v=$enter('actor');$r=$client->get('/geography/company/'.$f['company'],$options($v));$ok($r->getStatusCode()===200&&str_contains((string)$r->getBody(),'geography-workspace.mjs'),'shared geography screen is live');$r=$client->get('/api/geography/catalogue',$options($v));$catalogue=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&count($catalogue['records']['data'])===11,'live reference exposes11 source provinces');$r=$client->get('/api/geography/entities/company/'.$f['company'],$options($v));$d=json_decode((string)$r->getBody(),true);$r=$client->post('/api/geography/entities/company/'.$f['company'].'/preview',$options($v)+['json'=>['operation_key'=>(string)Illuminate\Support\Str::uuid(),'revision'=>$d['revision'],'catalogue_version'=>$d['catalogue_version'],'territory_key'=>$catalogue['records']['data'][0]['key'],'reason'=>'Prévia de ensaio sem atribuir localização.']]);$p=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$p['impact']['after']['country_code']==='MZ'&&$p['impact']['before']===null&&$p['impact']['after']['version']===$catalogue['version'],'read-only preview carries country and exact source version');$r=$client->get('/api/purchasing-suppliers/'.$n['supplier_ids'][0],$options($v));$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$d['geography_enabled']===true,'supplier record advertises shared geographic selector');
|
|
$v=$enter('actor','commercial');$r=$client->get('/api/geography/entities/client/'.$f['client'],$options($v));$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$d['entity']['editable']===true&&$d['location']===null,'synthetic associated client can open selector without an initial location');$r=$client->get('/api/geography/segments/client',$options($v));$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$d['data']===[],'segmentation demo begins with no assigned client locations');$r=$client->get('/api/geography/entities/client/'.$f['pending_client'],$options($v));$ok($r->getStatusCode()===403,'pending synthetic client stays outside the selected module');$r=$client->get('/geography/client/'.$f['client'],$options($v));$ok($r->getStatusCode()===200,'client reaches the same live selector');$r=$client->get('/geography-workspace.mjs');$ok($r->getStatusCode()===200&&hash('sha256',(string)$r->getBody())===hash_file('sha256',$s['app'].'/public/geography-workspace.mjs'),'served selector script matches delivered source');$ok($fp()===$before,'smoke and preview persist no geographic location history or command');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$fp(),'visual_review'=>false,'locations'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." geography demo checks passed.\n";
|