import { describe, it, expect } from 'vitest'; import { canModifyPost } from '../src/lib/posts'; describe('canModifyPost', () => { const own = { author_id: 7 }; const other = { author_id: 8 }; const orphan = { author_id: null }; it('admin e superuser modificano qualsiasi post', () => { for (const role of ['admin', 'superuser']) { expect(canModifyPost(role, 7, other)).toBe(true); expect(canModifyPost(role, 7, orphan)).toBe(true); } }); it('user modifica solo i propri', () => { expect(canModifyPost('user', 7, own)).toBe(true); expect(canModifyPost('user', 7, other)).toBe(false); expect(canModifyPost('user', 7, orphan)).toBe(false); }); });