Something went wrong. Try again.
A Social Deduction / Deception Game
Something went wrong. Try again.
2.2 kB · 62 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// The thrift shop's safety guarantee: a malformed give or item record never reaches a PDS. shop.ts// runs exactly these generated validators on both records before any write, so we assert their// contract here — good records pass, records missing a required field (or with a bad format) fail.
import { describe, it, expect } from 'vitest'import { validateRecord as validateItem } from '../../lexgen/types/equipment/rpg/item.js'import { validateRecord as validateGive } from '../../lexgen/types/equipment/rpg/give.js'
const NOW = '2026-06-24T00:00:00.000Z'const DID = 'did:plc:examplerecipient000000000'const GIVE_URI = `at://${DID}/equipment.rpg.give/abc123`
const goodItem = { $type: 'equipment.rpg.item', item: 'pixel_hat', title: 'Pixel Hat', give: GIVE_URI, provider: DID, acceptedAt: NOW,}
const goodGive = { $type: 'equipment.rpg.give', recipient: DID, item: 'pixel_hat', title: 'Pixel Hat', givenAt: NOW,}
describe('equipment.rpg.item validation', () => { it('accepts a well-formed item', () => { expect(validateItem(goodItem).success).toBe(true) }) it('rejects an item missing provider', () => { const { provider, ...bad } = goodItem expect(validateItem(bad).success).toBe(false) }) it('rejects an item missing acceptedAt', () => { const { acceptedAt, ...bad } = goodItem expect(validateItem(bad).success).toBe(false) }) it('rejects an item whose give is not an at-uri', () => { expect(validateItem({ ...goodItem, give: 'not-a-uri' }).success).toBe(false) })})
describe('equipment.rpg.give validation', () => { it('accepts a well-formed give', () => { expect(validateGive(goodGive).success).toBe(true) }) it('rejects a give missing recipient', () => { const { recipient, ...bad } = goodGive expect(validateGive(bad).success).toBe(false) }) it('rejects a give missing givenAt', () => { const { givenAt, ...bad } = goodGive expect(validateGive(bad).success).toBe(false) }) it('rejects a give whose recipient is not a did', () => { expect(validateGive({ ...goodGive, recipient: 'alice.example.com' }).success).toBe(false) })})