6 lines
2.4 KiB
PHP
6 lines
2.4 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/receipt-documents-demo.json';if(!($s['receiptDocuments']??false)||is_file($out))throw new LogicException('New receipt document demo required');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.document_demo'=>$s['nativeConnection']]);$db=DB::connection('document_demo');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$fingerprint=fn()=>hash('sha256',json_encode(array_map(fn($t)=>$db->table($t)->orderBy('id')->get(),['suppliers','goods_receipts','receipt_documents','supplier_documents','audit_logs'])));$before=$fingerprint();$ok($db->table('receipt_documents')->count()===0&&$db->table('goods_receipts')->count()===0&&$db->table('requisitions')->where('tenant_id',$n['tenant'])->count()===0,'new integrated demo starts without main requests receipts or documents');$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8077','http_errors'=>false,'timeout'=>25]);
|
|
foreach(['actor','validator','requester']as$role){$jar=new GuzzleHttp\Cookie\CookieJar;$r=$client->get('/qa/enter/'.$role,['cookies'=>$jar]);$v=json_decode((string)$r->getBody(),true);$o=['cookies'=>$jar,'headers'=>['Accept'=>'application/json','X-SGF-Context'=>$v['context']]];$r=$client->get('/purchasing/receipts',$o);$ok($r->getStatusCode()===($role==='requester'?403:200),'receipt screen respects '.$role.' permission');if($role==='validator'){$r=$client->get('/api/purchasing-receipts/history/1/documents',$o);$ok($r->getStatusCode()===404,'empty demo invents no receipt attachment owner');}}
|
|
foreach(['receipt-workspace.mjs','supplier-documents.mjs']as$file){$r=$client->get('/'.$file);$ok($r->getStatusCode()===200&&hash('sha256',(string)$r->getBody())===hash_file('sha256',$s['app'].'/public/'.$file),'served receipt evidence source matches '.$file);}$ok($fingerprint()===$before,'demonstration metadata probes preserve supplier receipt document and audit book');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$fingerprint(),'visual_review'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." receipt document demonstration checks passed.\n";
|