deliver-listing.test.ts (1922B)
1 import { expect, it } from 'vitest'; 2 import { deliverListing } from '../../src/lib/publishing/deliver-listing.ts'; 3 import { 4 authorizeListingAttempt, 5 takeListingPublication, 6 withListingDeliveryOwnership, 7 type ListingDeliveryLease, 8 type ListingAttemptPermission 9 } from '../../src/lib/nostr/listing-publisher.ts'; 10 import type { ListingPublication } from '../../src/lib/publishing/sign-listing.ts'; 11 import type { PublicPool } from '../../src/lib/nostr/public-pool.ts'; 12 import { deploymentRelayPolicy } from '../../src/lib/config/deployment-relays.ts'; 13 14 it('HCP112 copied durable disclosure cannot authorize a network action during SSR', async () => { 15 expect( 16 await deliverListing( 17 {} as ListingPublication, 18 {} as PublicPool, 19 deploymentRelayPolicy, 20 'publish_stored_listing' 21 ) 22 ).toEqual({ status: 'invalid' }); 23 }); 24 it('HCP112 copied lease cannot grant an event or readback permission', async () => { 25 for (const mode of ['publish', 'readback'] as const) 26 expect( 27 await authorizeListingAttempt( 28 {} as ListingDeliveryLease, 29 'wss://discovery.example.org', 30 mode 31 ) 32 ).toBeUndefined(); 33 }); 34 it('HCP112 copied per-target permission exposes no raw SDK event form', () => { 35 for (const mode of ['publish', 'readback'] as const) 36 expect( 37 takeListingPublication( 38 {} as ListingAttemptPermission, 39 deploymentRelayPolicy, 40 'wss://discovery.example.org', 41 mode 42 ) 43 ).toBeUndefined(); 44 }); 45 it('HCP112 copied source cannot execute an arbitrary ownership callback', async () => { 46 let called = false; 47 expect( 48 await withListingDeliveryOwnership( 49 {} as ListingPublication, 50 deploymentRelayPolicy, 51 'publish_stored_listing', 52 () => { 53 called = true; 54 return Promise.resolve('unexpected'); 55 } 56 ) 57 ).toEqual({ status: 'invalid' }); 58 expect(called).toBe(false); 59 });