MC/website/tests/seal-entitlements.test.mjs
2026-11-27 23:43:05 +00:00

24 lines
3.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {SHOP_SEALS,sealForPurchasedTier,purchaseSealDecision,manualSealDecision,isShowcaseSeal} from '../node/seal-entitlements.mjs';
test('all canonical donor tiers map to distinct existing artwork',()=>{assert.equal(Object.keys(SHOP_SEALS).length,5);assert.equal(new Set(Object.values(SHOP_SEALS)).size,5);assert.equal(sealForPurchasedTier('unknown'),null);});
test('unverified and incomplete payments never award seals',()=>{for(const status of ['pending','failed','refunded','chargeback'])assert.equal(purchaseSealDecision({tier:'vip',paymentStatus:status,verified:true,accountId:'a',orderId:'o'}),null);assert.equal(purchaseSealDecision({tier:'vip',paymentStatus:'completed',verified:false,accountId:'a',orderId:'o'}),null);});
test('verified purchases have stable idempotency keys',()=>{const args={tier:'patron_grand',paymentStatus:'completed',verified:true,accountId:'a',orderId:'o'};assert.deepEqual(purchaseSealDecision(args),purchaseSealDecision(args));assert.equal(purchaseSealDecision(args).idempotencyKey,'purchase:o:supporter-patron-grand-v1');});
test('staff decisions require authorization and reject self-awards',()=>{assert.equal(manualSealDecision({seal:'alpha-tester',actorAuthorized:false,targetId:'a',actorId:'b',action:'grant'}),null);assert.equal(manualSealDecision({seal:'alpha-tester',actorAuthorized:true,targetId:'a',actorId:'a',action:'grant'}),null);assert.equal(manualSealDecision({seal:'crysknife',actorAuthorized:true,targetId:'a',actorId:'b',action:'grant'}),null);assert.equal(manualSealDecision({seal:'beta-tester',actorAuthorized:true,targetId:'a',actorId:'b',action:'grant'}).action,'grant');});
test('showcase excludes personal seals and Crysknife',()=>{assert.equal(isShowcaseSeal('owner-unimatrix999'),false);assert.equal(isShowcaseSeal('order-crysknife-v1'),false);assert.equal(isShowcaseSeal('personal-department-support-somebody'),false);assert.equal(isShowcaseSeal('custom-recognition',{personal:true}),false);assert.equal(isShowcaseSeal('alpha-tester'),true);assert.equal(isShowcaseSeal('supporter-vip-v1'),true);});
import {crysknifeGrantDecision,CRYSKNIFE_FOUNDERS} from '../node/seal-entitlements.mjs';
test('founders can grant without possessing Crysknife',()=>{
for(const name of CRYSKNIFE_FOUNDERS)assert.equal(crysknifeGrantDecision({actorId:name,actorUsername:name,actorRanks:[],recipientId:'other',recipientUsername:'other'}).action,'grant');
});
test('verified recipients can grant to others, but never themselves',()=>{
const a={actorId:'blueray-id',actorUsername:'mr_blueray',actorRanks:['crysknife'],recipientId:'patrick-id',recipientUsername:'patrick'};
assert.equal(crysknifeGrantDecision(a).action,'grant');
assert.equal(crysknifeGrantDecision({...a,recipientId:a.actorId,recipientUsername:a.actorUsername}),null);
assert.equal(crysknifeGrantDecision({...a,actorRanks:[]}),null);
assert.equal(crysknifeGrantDecision({...a,recipientHasOrder:true}).action,'already-member');
});
test('unrelated staff and self-granting founders are rejected',()=>{
assert.equal(crysknifeGrantDecision({actorId:'staff',actorUsername:'admin',actorRanks:['staff'],recipientId:'other',recipientUsername:'other'}),null);
assert.equal(crysknifeGrantDecision({actorId:'owner',actorUsername:'unimatrix',actorRanks:[],recipientId:'owner',recipientUsername:'unimatrix'}),null);
});