Files
zpan/server/bootstrap.test.ts
saltbo 3064403c92 fix(ids): make normalization optional
Keep historical identifiers readable and addressable while generating all new entity IDs with Base62. Reject unsafe external ID references and preserve API keys and device codes during optional normalization.
2026-08-05 13:06:41 -04:00

37 lines
1.3 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { Platform } from './platform/interface'
import type { Deps } from './usecases/deps'
const app = { fetch: vi.fn() }
const auth = { api: {} }
const createAppMock = vi.hoisted(() => vi.fn(() => app))
const createAuthMock = vi.hoisted(() => vi.fn(async () => auth))
vi.mock('./app', () => ({ createApp: createAppMock }))
vi.mock('./auth', () => ({ createAuth: createAuthMock }))
import { createBootstrap } from './bootstrap'
describe('Node bootstrap', () => {
beforeEach(() => {
createAppMock.mockClear()
createAuthMock.mockClear()
})
it('starts without inspecting optional ID-normalization state', async () => {
const db = { all: vi.fn(), run: vi.fn() }
const platform = {
db,
getEnv: (name: string) =>
name === 'BETTER_AUTH_SECRET' ? 'test-secret' : name === 'BETTER_AUTH_URL' ? 'https://zpan.test' : undefined,
} as unknown as Platform
const deps = {} as Deps
await expect(createBootstrap(platform, deps)).resolves.toBe(app)
expect(createAuthMock).toHaveBeenCalledWith(platform, 'test-secret', 'https://zpan.test', ['http://localhost:5185'])
expect(createAppMock).toHaveBeenCalledWith(platform, auth, deps)
expect(db.all).not.toHaveBeenCalled()
expect(db.run).not.toHaveBeenCalled()
})
})