inbox-view.test.ts (3080B)
1 import { describe, expect, it } from 'vitest'; 2 import { 3 createInboxView, 4 inboxViewSnapshot, 5 unlockInboxView, 6 checkInboxView, 7 readNewInboxView, 8 inboxViewSetup, 9 closeInboxView, 10 blockInboxConversation, 11 inboxConversationBlocked, 12 type InboxView 13 } from '../../src/lib/messaging/inbox-view.ts'; 14 import { createIdentitySession } from '../../src/lib/runtime/identity-session.ts'; 15 import type { InboxSetupView } from '../../src/lib/messaging/inbox-setup-view.ts'; 16 describe('inbox page requires original browser owners', () => { 17 it('SSR capture cannot create effects from a copied setup', () => { 18 expect( 19 createInboxView({ 20 identity: createIdentitySession(), 21 setup: {} as InboxSetupView 22 }) 23 ).toBeUndefined(); 24 }); 25 it('forged scalar tokens never return an owner, checked time or empty inbox', () => { 26 const value = inboxViewSnapshot({} as InboxView); 27 expect(value.state).toBe('unavailable'); 28 expect(value.lastCheckedAt).toBeNull(); 29 expect(value.owner).toBeUndefined(); 30 expect(value.count).toBe(0); 31 }); 32 it('copied observations are not an inbox controller', () => { 33 const value = inboxViewSnapshot(undefined); 34 expect(inboxViewSnapshot({ ...value } as unknown as InboxView).state).toBe( 35 'unavailable' 36 ); 37 expect( 38 inboxViewSetup({ ...value } as unknown as InboxView) 39 ).toBeUndefined(); 40 }); 41 it('a forged unlock cannot acquire extension or native database effects', async () => { 42 expect( 43 await unlockInboxView({} as InboxView, 'reviewed_messages_unlock') 44 ).toBe(false); 45 }); 46 it('a forged check cannot issue a relay request or checked timestamp', async () => { 47 expect( 48 await checkInboxView({} as InboxView, 'reviewed_foreground_inbox') 49 ).toBe(false); 50 expect(inboxViewSnapshot({} as InboxView).lastCheckedAt).toBeNull(); 51 }); 52 it('forged continuation cannot approve any decrypt batch', async () => { 53 expect( 54 await readNewInboxView({} as InboxView, 'reviewed_decrypt_batch') 55 ).toBe(false); 56 }); 57 it('copied controllers cannot import a peer block or a private block inventory', async () => { 58 const copied = { ...inboxViewSnapshot(undefined) } as unknown as InboxView; 59 expect( 60 await blockInboxConversation( 61 copied, 62 '12345678-1234-4234-8234-123456789abc', 63 'reviewed_local_private_block' 64 ) 65 ).toEqual({ status: 'invalid' }); 66 expect( 67 inboxConversationBlocked(copied, '12345678-1234-4234-8234-123456789abc') 68 ).toBe(false); 69 expect( 70 inboxConversationBlocked( 71 undefined, 72 '12345678-1234-4234-8234-123456789abc' 73 ) 74 ).toBe(false); 75 }); 76 it('copied or absent owners cannot expose the shared setup token', () => { 77 expect(inboxViewSetup(undefined)).toBeUndefined(); 78 expect(inboxViewSetup({} as InboxView)).toBeUndefined(); 79 }); 80 it('closing an unknown owner is inert and cannot turn it into a ready inbox', () => { 81 closeInboxView({} as InboxView); 82 expect(inboxViewSnapshot({} as InboxView).state).toBe('unavailable'); 83 }); 84 });