revise-listing.test.ts (2517B)
1 import { describe, expect, it } from 'vitest'; 2 import { 3 nextOwnedRevisionTime, 4 reviewOwnedRevision 5 } from '../../src/lib/publishing/revise-listing.ts'; 6 import { reviewMarkSold } from '../../src/lib/publishing/mark-sold.ts'; 7 import type { OwnedEditSource } from '../../src/lib/publishing/edit-source.ts'; 8 import type { PublicDraftController } from '../../src/lib/publishing/draft-controller.ts'; 9 10 describe('HCP119 owned revision clock and original custody', () => { 11 it('uses actual forward wall time and advances the same-second head once', () => { 12 expect(nextOwnedRevisionTime(100, 200)).toBe(200); 13 expect(nextOwnedRevisionTime(100, 100)).toBe(101); 14 }); 15 it('stops before advancing beyond the original future-clock allowance', () => { 16 expect(nextOwnedRevisionTime(399, 100)).toBe(400); 17 expect(nextOwnedRevisionTime(400, 100)).toBeUndefined(); 18 expect(nextOwnedRevisionTime(1000, 100)).toBeUndefined(); 19 }); 20 it('repeated updates cannot indefinitely beat a frozen/backward clock', () => { 21 let head = 100; 22 for (let index = 0; index < 300; index++) { 23 const next = nextOwnedRevisionTime(head, 100); 24 expect(next).toBe(head + 1); 25 if (next === undefined) throw Error('clock stopped before its limit'); 26 head = next; 27 } 28 expect(head).toBe(400); 29 expect(nextOwnedRevisionTime(head, 100)).toBeUndefined(); 30 expect(nextOwnedRevisionTime(head, 0)).toBeUndefined(); 31 }); 32 it.each([NaN, Infinity, -1, Number.MAX_SAFE_INTEGER + 1])( 33 'unavailable wall clock %s cannot prepare a revision', 34 (now) => expect(nextOwnedRevisionTime(100, now)).toBeUndefined() 35 ); 36 it.each([-1, 0.5, NaN, Infinity, Number.MAX_SAFE_INTEGER])( 37 'unsupported or overflowing head %s cannot advance', 38 (head) => expect(nextOwnedRevisionTime(head, 100)).toBeUndefined() 39 ); 40 it('copied source/controller and boolean review cannot mint revision custody', async () => { 41 expect( 42 await reviewOwnedRevision( 43 {} as OwnedEditSource, 44 {} as PublicDraftController, 45 '3d030bf5-901d-45e1-8251-41cbdf805e96', 46 true 47 ) 48 ).toEqual({ status: 'blocked', reason: 'invalid_scope' }); 49 }); 50 it('sold also requires original retained source and explicit reviewed consequence', async () => { 51 expect( 52 await reviewMarkSold( 53 {} as OwnedEditSource, 54 {} as PublicDraftController, 55 '3d030bf5-901d-45e1-8251-41cbdf805e96', 56 true 57 ) 58 ).toEqual({ status: 'blocked', reason: 'invalid_scope' }); 59 }); 60 });