import { Hono } from 'hono' import { testClient } from 'hono/testing' import { expectTypeOf } from 'vite-plus/test' import { App, Auth } from 'tapimo' describe('Auth', () => { test('exports the external route-authoring surface', () => { expectTypeOf(Auth.policy).toBeFunction() expectTypeOf(Auth.ensureOrg).toBeFunction() expectTypeOf(Auth.ensureProject).toBeFunction() expectTypeOf().toMatchTypeOf<{ apiKey?: { scopes?: readonly string[] | undefined } | boolean | undefined }>() expectTypeOf().toEqualTypeOf< 'api_key' | 'public' | 'session' | 'super_admin' >() }) test('preserves route response unions', async () => { const app = new Hono().get( '/v1/projects/:projectId', Auth.policy({ apiKey: true }), Auth.ensureProject(), (c) => { if (Auth.narrowAccess) return Auth.accessError(c) if (Auth.narrowScope) return Auth.ensureProjectError(c) return c.json({ id: Auth.project(c).id }, 200) }, ) const response = await testClient(app).v1.projects[':projectId'].$get({ param: { projectId: 'prj_test' }, }) expectTypeOf(response.status).toEqualTypeOf<200 | 400 | 401 | 403 | 404 | 429>() }) })