app

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

cited-product.test.ts (2064B)


      1 import { describe, expect, it } from 'vitest';
      2 import {
      3   captureCitedProduct,
      4   citedProductSnapshot,
      5   closeCitedProduct,
      6   conversationOptionsSnapshot,
      7   requestConversationOption,
      8   type CitedProduct
      9 } from '../../src/lib/messaging/cited-product.ts';
     10 import type { InboxView } from '../../src/lib/messaging/inbox-view.ts';
     11 import type { PublicRuntime } from '../../src/lib/runtime/public-runtime.ts';
     12 
     13 const id = '12345678-1234-4234-8234-123456789abc';
     14 describe('private citation and conversation options reject detached authority', () => {
     15   it('SSR cannot allocate a citation query from arbitrary scalar hints', () => {
     16     expect(
     17       captureCitedProduct(
     18         {} as InboxView,
     19         id,
     20         'a'.repeat(64),
     21         'naddr1invalid',
     22         {} as PublicRuntime,
     23         'reviewed_product_citation'
     24       )
     25     ).toBeUndefined();
     26   });
     27   it('copied citation tokens do not expose verified context', () => {
     28     expect(citedProductSnapshot({} as CitedProduct)).toBeUndefined();
     29   });
     30   it('closing a fake citation never creates query authority', () => {
     31     const fake = {} as CitedProduct;
     32     closeCitedProduct(fake);
     33     expect(citedProductSnapshot(fake)).toBeUndefined();
     34   });
     35   it('fake views do not expose an authenticated conversation identity', () => {
     36     expect(conversationOptionsSnapshot({} as InboxView, id)).toBeUndefined();
     37   });
     38   it('fake local options cannot invoke a block or private report hook', () => {
     39     const peers: string[] = [];
     40     for (const action of ['block', 'report'] as const)
     41       expect(
     42         requestConversationOption(
     43           {} as InboxView,
     44           id,
     45           action,
     46           (peer) => peers.push(peer),
     47           'reviewed_conversation_option'
     48         )
     49       ).toBe(false);
     50     expect(peers).toEqual([]);
     51   });
     52   it('unreviewed citation capture cannot become an effect', () => {
     53     expect(
     54       captureCitedProduct(
     55         {} as InboxView,
     56         id,
     57         'a'.repeat(64),
     58         'naddr1invalid',
     59         {} as PublicRuntime,
     60         undefined
     61       )
     62     ).toBeUndefined();
     63   });
     64 });