Preserve the current Alpha source and artwork snapshot. See handoff/alpha-1.0.0.3 for actual deployed hashes, checks, staged follow-ups and the production pause. This checkpoint does not claim every source feature is deployed.
8 lines
2.3 KiB
JavaScript
8 lines
2.3 KiB
JavaScript
import test from 'node:test';import assert from 'node:assert/strict';import{createKitCart}from'../control-panel/public/kit-cart.mjs';
|
|
function fixture(){let n=1;const values=new Map(),storage={getItem:k=>values.get(k)||null,setItem:(k,v)=>values.set(k,v)},uuid=()=>String(n++).padStart(8,'0')+'-1111-1111-1111-111111111111';const options={uuid,storage,key:'account-a'};return{options,cart:createKitCart(options)}}
|
|
const listing={listingId:'99999999-1111-1111-1111-111111111111',listingVersion:2,blueprintVersion:3,priceCents:10000,name:'Desert kit'};
|
|
test('checkout sends immutable revisions and integer cents, never client identity',async()=>{const{cart}=fixture();cart.add(listing);let sent;await cart.checkout(async p=>{sent=p;return{ok:true,cartId:p.cartId}});assert.equal(sent.lines[0].priceCents,10000);assert.deepEqual(Object.keys(sent).sort(),['cartId','lines']);assert.equal(cart.snapshot().lines.length,0)});
|
|
test('lost response and reload preserve both cart and order IDs',async()=>{const{cart,options}=fixture();cart.add(listing);const before=cart.snapshot();await assert.rejects(cart.checkout(async()=>{throw Error('timeout')}));const restored=createKitCart(options);assert.deepEqual(restored.snapshot(),before);await restored.checkout(async p=>{assert.equal(p.cartId,before.cartId);assert.equal(p.lines[0].orderLineId,before.lines[0].orderLineId);return{ok:true,cartId:p.cartId}})});
|
|
test('editing after a failed response retains the original cart identity',async()=>{const{cart}=fixture();cart.add(listing);const id=cart.snapshot().cartId;await assert.rejects(cart.checkout(async()=>{throw Error('timeout')}));cart.remove(cart.snapshot().lines[0].orderLineId);cart.add(listing);assert.equal(cart.snapshot().cartId,id)});
|
|
test('concurrent checkout and edits cannot alter an in-flight payment',async()=>{const{cart}=fixture();cart.add(listing);let resolve;const pending=cart.checkout(p=>new Promise(r=>{resolve=()=>r({ok:true,cartId:p.cartId})}));await assert.rejects(cart.checkout(async()=>({})));assert.throws(()=>cart.add(listing));resolve();await pending});
|
|
test('invalid listings and mismatched receipts never clear the cart',async()=>{const{cart}=fixture();assert.throws(()=>cart.add({...listing,priceCents:1.5}));cart.add(listing);await assert.rejects(cart.checkout(async()=>({ok:true,cartId:'wrong'})));assert.equal(cart.snapshot().lines.length,1)});
|

Staff