MC/website/tests/smuggler-bounty-evidence.test.mjs
2026-11-27 23:43:05 +00:00

27 lines
2.2 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {randomUUID} from 'node:crypto';
import {smugglerDeliveryReference,deriveSmugglerDeliveryObjectives} from '../node/smuggler-delivery-evidence.mjs';
import {bountyEvent,bountyReference,hasAcceptedBountyReceipt} from '../node/bounty-quest-evidence.mjs';
test('each successive smuggling objective consumes a distinct verified delivery',()=>{
const source=randomUUID(),destination=randomUUID();
const receipt=(occurredAt,distance=64,opposed=false)=>{const eventId=randomUUID();return {eventId,occurredAt,reference:smugglerDeliveryReference({eventId,source,destination,commodity:'spice',amount:1,distance,opposed})};};
const first=receipt(1,128,true),second=receipt(2),third=receipt(3),unopposed=receipt(4,256),opposed=receipt(5,64,true),short=receipt(6),long1=receipt(7,128),long2=receipt(8,256);
const initial=deriveSmugglerDeliveryObjectives([third,first,first,second,unopposed]);
assert.deepEqual([...initial],[['pol-sealed-cargo',1],['pol-restricted-delivery',1],['pol-alternate-route',1]]);
const complete=deriveSmugglerDeliveryObjectives([first,second,third,unopposed,opposed,short,long1,long1,long2]);
assert.equal(complete.get('pol-opposed-delivery'),1);
assert.equal(complete.get('pol-ghost-cargo'),2);
assert.throws(()=>smugglerDeliveryReference({eventId:randomUUID(),source,destination:source.toUpperCase(),commodity:'water',amount:1,distance:64,opposed:false}));
});
test('bounty acceptance and completion have separate deterministic identities and matching account scope',async()=>{
const source=randomUUID(),accountId=randomUUID(),minecraftUuid=randomUUID();
const acceptance=bountyEvent('bounty_accept',source),completion=bountyEvent('bounty_complete',source);
assert.notEqual(acceptance,completion);
assert.equal(acceptance,bountyEvent('bounty_accept',source));
const db={query:async(sql,params)=>{assert.match(sql,/k\.revoked_at IS NULL/); assert.deepEqual(params,[acceptance,accountId,minecraftUuid,'S01',bountyReference('bounty_accept',source)]);return [{key_id:randomUUID()}];}};
assert.equal(await hasAcceptedBountyReceipt(db,accountId,minecraftUuid,'S01',source),true);
assert.equal(await hasAcceptedBountyReceipt({query:async()=>[]},accountId,minecraftUuid,'S01',source),false);
});