app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

inbox-profile.test.ts (1719B)


      1 import { expect, it } from 'vitest';
      2 import { finalizeEvent } from 'applesauce-core/helpers';
      3 import {
      4   readInboxPreference,
      5   inboxPreferenceSnapshot,
      6   inboxPreferenceWire,
      7   type InboxPreference
      8 } from '../../src/lib/nostr/inbox-preferences.ts';
      9 import { inboxProfileSnapshot } from '../../src/lib/messaging/inbox-profile.ts';
     10 
     11 it('forged preference handles grant no profile, wire, provider or SSR authority', () => {
     12   expect(typeof window).toBe('undefined');
     13   const forged = {} as InboxPreference;
     14   expect(inboxPreferenceSnapshot(forged)).toBeUndefined();
     15   expect(inboxPreferenceWire(forged)).toBeUndefined();
     16   expect(inboxProfileSnapshot(forged)).toBeUndefined();
     17   expect(readInboxPreference({}, 'not-a-key').status).toBe('rejected');
     18 });
     19 it('detached profile mutation never changes proof-owned original or advertised entries', () => {
     20   const key = crypto.getRandomValues(new Uint8Array(32));
     21   try {
     22     const event = finalizeEvent(
     23       {
     24         kind: 10050,
     25         created_at: 100,
     26         tags: [
     27           ['relay', 'wss://one.example.org'],
     28           ['unknown', 'keep']
     29         ],
     30         content: ''
     31       },
     32       key
     33     );
     34     const wire = JSON.stringify(event);
     35     const parsed = readInboxPreference(wire, event.pubkey);
     36     expect(parsed.status).toBe('supported');
     37     if (parsed.status !== 'supported') throw new Error('fixture not admitted');
     38     const view = inboxProfileSnapshot(parsed.value)!;
     39     view.advertised.length = 0;
     40     expect(inboxProfileSnapshot(parsed.value)?.advertised).toEqual([
     41       'wss://one.example.org'
     42     ]);
     43     expect(inboxPreferenceWire(parsed.value)).toBe(wire);
     44     expect(Object.isFrozen(parsed.value)).toBe(true);
     45   } finally {
     46     key.fill(0);
     47   }
     48 });