6 lines
3.4 KiB
PHP
6 lines
3.4 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true,64,JSON_THROW_ON_ERROR);$out=$s['root'].'/sourcing-demo-smoke.json';if(file_exists($out))throw new LogicException('Smoke proof preserved');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true);config(['database.connections.sourcing_smoke'=>$s['nativeConnection']]);$db=DB::connection('sourcing_smoke');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$fingerprint=function()use($db){$h=hash_init('sha256');foreach(['quotations','quotation_items','proposal_evaluations','purchase_awards','purchase_award_approvals','purchase_orders','goods_receipts','stock_movements','budget_entries','audit_logs']as$table){hash_update($h,$table);foreach($db->table($table)->orderBy('id')->get()as$row)hash_update($h,json_encode((array)$row,JSON_THROW_ON_ERROR));}return hash_final($h);};$before=$fingerprint();$empty=true;foreach(['quotations','proposal_evaluations','purchase_awards','purchase_orders','goods_receipts','stock_movements']as$table)$empty=$empty&&$db->table($table)->count()===0;$ok($empty,'demo starts without proposals evaluations awards orders receipts or movements');$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8066','http_errors'=>false,'timeout'=>25]);
|
|
foreach(['actor','issuer','validator']as$role){$jar=new GuzzleHttp\Cookie\CookieJar;$r=$client->get('/qa/enter/'.$role,['cookies'=>$jar]);$v=json_decode((string)$r->getBody(),true);$options=['cookies'=>$jar,'headers'=>['Accept'=>'application/json','X-SGF-Context'=>$v['context']]];$r=$client->get('/api/purchasing-sourcing/requests/'.$n['requisition'],$options);$d=json_decode((string)$r->getBody(),true);if($role==='actor'){$ok($r->getStatusCode()===200&&$d['capabilities']['quote']===true&&$d['capabilities']['select']===false&&count($d['quotes'])===0,'buyer can prepare but cannot select an incomplete comparison');$r=$client->get('/purchasing/sourcing',$options);$ok($r->getStatusCode()===200&&str_contains((string)$r->getBody(),'sourcing-workspace.mjs'),'sourcing workspace is live');}elseif($role==='issuer')$ok($r->getStatusCode()===200&&$d['capabilities']['quote']===false&&$d['capabilities']['decide']===false,'head can inspect without preparing proposals or deciding a nonexistent award');else{$ok($r->getStatusCode()===403,'warehouse cannot inspect economic sourcing');$r=$client->get('/api/purchasing-receipts',$options);$p=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&count($p['data'])===0,'warehouse waits for an actual issued order');}}
|
|
$r=$client->get('/sourcing-workspace.mjs');$ok($r->getStatusCode()===200&&hash('sha256',(string)$r->getBody())===hash_file('sha256',$s['app'].'/public/sourcing-workspace.mjs'),'served sourcing script matches delivered source');$ok($db->table('budget_entries')->where('kind','commit')->count()===0,'no initial commitment was created');$ok($fingerprint()===$before,'read-only smoke leaves all business evidence intact');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$fingerprint(),'quotes'=>0,'evaluations'=>0,'awards'=>0,'orders'=>0,'receipts'=>0,'movements'=>0,'visual_review'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
|