// Unit test with `@voltro/testing` — no database, no running server. The base // `documents.create` mutation is a plain tenant()-scoped insert, so it's fully // unit-runnable. The row-HISTORY / as-of reads are populated by the row-history // plugin's post-commit tap (not wired into the unit store), so those are // integration-tested elsewhere; here we cover the write + tenant isolation that // every version-1 snapshot is built from. Run with `voltro test` (vitest). import { describe, it, expect } from 'vitest' import { makeTestContext, mockStore } from '@voltro/testing' import { database } from '../database/schema' // registers documents / actors / tenants import createDocument from '../mutations/documents.create.mutation.server' describe('documents.create', () => { it('inserts a document, auto-stamped to the caller tenant', async () => { const ctx = makeTestContext({ subject: { type: 'user', id: 'user_1', tenantId: 'acme' }, store: mockStore({ documents: [] }), }) const row = await createDocument({ title: 'Spec', content: 'v1 body' }, ctx) expect(row['title']).toBe('Spec') expect(row['content']).toBe('v1 body') expect(row['tenantId']).toBe('acme') // tenant() stamped it expect(row['id'] as string).toMatch(/^doc_/) // TypeID auto-injected }) it('isolates tenants — t2 never sees t1 documents (REAL tenant scoping)', async () => { const ctx = makeTestContext({ subject: { type: 'user', id: 'u1', tenantId: 't1' }, store: mockStore({ documents: [] }), }) await createDocument({ title: 'secret', content: '' }, ctx) const seenByT2 = await ctx.withTenant('t2', (c) => c.store.query(database.documents.descriptor)) expect(seenByT2).toHaveLength(0) }) })