// Unit test with `@voltro/testing`. `session.me` returns the caller's resolved // identity — the proof the auth loop threads the Subject through to handlers. // `makeTestContext({ subject })` sets `ctx.request.subject` to exactly what the // AuthMiddleware would resolve at runtime, so the executor is fully runnable // with no cookie, no session store, no running server. // // (This template has no DB-write primitive — the identity read IS the runnable // unit here.) Run with `voltro test` (vitest). import { describe, it, expect } from 'vitest' import { makeTestContext } from '@voltro/testing' import '../database/schema' // registers actors / tenants import me from '../actions/me.action.server' describe('session.me', () => { it('reflects a signed-in user Subject', async () => { const ctx = makeTestContext({ subject: { type: 'user', id: 'user_1', tenantId: 'acme' }, }) const identity = await me({}, ctx) expect(identity.type).toBe('user') expect(identity.id).toBe('user_1') expect(identity.tenantId).toBe('acme') }) it('returns an anonymous identity with null id/tenant when no session is present', async () => { // Default `makeTestContext()` subject is the anonymous Subject // ({ type: 'anonymous', id: null, tenantId: null }). const ctx = makeTestContext() const identity = await me({}, ctx) expect(identity.type).toBe('anonymous') expect(identity.id).toBeNull() expect(identity.tenantId).toBeNull() }) })