import { describe, it, expect } from 'vitest' import { transformCan } from '../src/runtime/transformer/transform-can' const TEST_FILE = `${process.cwd()}/components/Test.vue` const buildSFC = (template: string) => `` const runTransform = (template: string) => { const result = transformCan({ code: buildSFC(template), id: TEST_FILE }) return result?.code ?? '' } describe('transformCan', () => { it('injects __can__ guards and a matching v-cannot block', () => { const code = runTransform(`

Refus

`) expect(code).toContain(`v-if="__can__('employee', 'view')"`) expect(code).toContain(`v-if="!(__can__('employee', 'view'))"`) }) it('merges existing v-if expressions with the generated guard', () => { const code = runTransform(`
`) expect(code).toContain(`v-if="__can__('contract', 'create') && (isReady)"`) }) it('throws when v-cannot is used without a preceding v-can', () => { const exec = () => transformCan({ code: buildSFC('

Denied

'), id: TEST_FILE, }) expect(exec).toThrow(/without an expression must immediately follow/) }) it('throws when the expression does not start with can.*', () => { const exec = () => transformCan({ code: buildSFC('