forked from unimatrix/web
6 lines
2.9 KiB
JavaScript
6 lines
2.9 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';import {randomUUID} from 'node:crypto';
|
|
import {BankFixture} from './postbank-fixture.mjs';import {RIHLA_SCHEMA,ensureRihlaAccount,provisionRihlaAccounts,createRihlaAPI,rihlaQuote} from '../node/rihla.mjs';
|
|
async function fixture(){const bank=new BankFixture();for(const sql of RIHLA_SCHEMA)await bank.query(sql.replace(/,INDEX \w+\([^)]*\)/g,'').replace(' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4',''));return bank;}
|
|
test('Rihla provisions one empty account per identity without creating a bank package and preserves existing funds',async()=>{const bank=await fixture(),ids=[randomUUID(),randomUUID()];try{const central={query:async(sql,[cursor])=>ids.filter(id=>id>cursor).sort().map(id=>({id}))};await provisionRihlaAccounts(central,bank);assert.equal((await bank.first('SELECT COUNT(*) n FROM ria_accounts')).n,2);assert.equal((await bank.first('SELECT COUNT(*) n FROM pb_accounts')).n,0);assert.equal((await bank.first('SELECT COUNT(*) n FROM pb_packages')).n,0);await bank.query('UPDATE ria_accounts SET balance_minor=1234 WHERE owner_id=?',[ids[0]]);await provisionRihlaAccounts(central,bank);assert.equal((await bank.first('SELECT balance_minor FROM ria_accounts WHERE owner_id=?',[ids[0]])).balance_minor,1234);}finally{bank.close();}});
|
|
test('Rihla taxes use the full amount at the strict 3000 DM boundary',()=>{assert.equal(rihlaQuote('3000').taxMinor,'3000');assert.equal(rihlaQuote('3000.01').ratePercent,5);assert.equal(rihlaQuote('4000').totalMinor,'420000');assert.equal(rihlaQuote('0.01').taxMinor,'1');assert.throws(()=>rihlaQuote('-1'));assert.throws(()=>rihlaQuote('92233720368547758.07'));});
|
|
test('website is owner-only and read-only, including for staff; history omits key material and tax details',async()=>{const bank=await fixture(),sender=randomUUID(),recipient=randomUUID(),staff=randomUUID();try{await ensureRihlaAccount(bank,sender);await bank.query("INSERT INTO ria_transfers VALUES(?,?,?,?,?,?,?,?,'created',?,1)",[randomUUID(),'RIA-2026-00000001',sender,recipient,'Sender','Recipient',10000,100,randomUUID()]);let actor={id:sender,role:'user'};const api=createRihlaAPI(null,bank,{authenticate:async()=>actor});const request=path=>api(new Request('https://cp.dunerealms.com/api/rihla'+path));const data=await(await request('')).json();assert.deepEqual(Object.keys(data.transactions[0]),['number','sender','recipient','amount','status']);assert.equal(data.transactions.length,1);assert.equal((await request('?ownerId='+recipient)).status,400);assert.equal((await api(new Request('https://cp.dunerealms.com/api/rihla',{method:'POST'}))).status,405);actor={id:staff,role:'owners'};assert.equal((await(await request('')).json()).transactions.length,0);actor={id:recipient};assert.equal((await(await request('')).json()).transactions.length,1);actor=null;assert.equal((await request('')).status,401);}finally{bank.close();}});
|

Staff