app

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

withdraw-listing.test.ts (2293B)


      1 import { expect, test } from 'vitest';
      2 import { reviewOwnedWithdrawal } from '../../src/lib/publishing/withdraw-listing.ts';
      3 import type { OwnedEditSource } from '../../src/lib/publishing/edit-source.ts';
      4 import type { PublicDraftController } from '../../src/lib/publishing/draft-controller.ts';
      5 import { makeFixture } from '../e2e/harness/approved-signing.ts';
      6 import { runCapturedPublicEffect } from '../../src/lib/runtime/effect-ownership.ts';
      7 import type { PublicQuotaRepository } from '../../src/lib/persistence/quota.ts';
      8 
      9 for (const source of [undefined, null, {}, { owner: 'copied' }])
     10   test(`withdrawal cannot acquire source custody from ${JSON.stringify(source)}`, async () => {
     11     const result = await reviewOwnedWithdrawal(
     12       source as OwnedEditSource,
     13       {} as PublicDraftController,
     14       '00000000-0000-4000-8000-000000000120',
     15       'reviewed_owned_withdrawal'
     16     );
     17     expect(result).toEqual({ status: 'blocked', reason: 'invalid_scope' });
     18   });
     19 
     20 for (const kind of [30402, 5, 10050] as const)
     21   test(`withdrawal signing mode admits only linked kind5 and never invokes SSR effects (${kind})`, async () => {
     22     const fixture = makeFixture(kind);
     23     let calls = 0;
     24     try {
     25       const result = await runCapturedPublicEffect(
     26         {} as PublicQuotaRepository,
     27         fixture.record,
     28         fixture.id,
     29         { owner: fixture.owner, session: Symbol(), current: () => true },
     30         'reviewed_prepared_withdrawal_operation',
     31         () => {
     32           calls++;
     33           return Promise.resolve();
     34         }
     35       );
     36       expect(result.status).toBe(kind === 5 ? 'unavailable' : 'invalid');
     37       expect(calls).toBe(0);
     38     } finally {
     39       fixture.close();
     40     }
     41   });
     42 
     43 test('linked removal cannot enter the prepared ordinary-listing signing mode', async () => {
     44   const fixture = makeFixture(5);
     45   let calls = 0;
     46   try {
     47     const result = await runCapturedPublicEffect(
     48       {} as PublicQuotaRepository,
     49       fixture.record,
     50       fixture.id,
     51       { owner: fixture.owner, session: Symbol(), current: () => true },
     52       'reviewed_prepared_listing_operation',
     53       () => {
     54         calls++;
     55         return Promise.resolve();
     56       }
     57     );
     58     expect(result.status).toBe('invalid');
     59     expect(calls).toBe(0);
     60   } finally {
     61     fixture.close();
     62   }
     63 });