mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-28 15:51:29 +08:00
310e4950b3
Replace pnpm workspace monorepo (packages/server, packages/web, packages/shared) with a flat single-package layout following Hono's pages-stack pattern. Switch from pnpm to npm and from Workers+Assets to CF Pages Functions deployment model. - Move source: packages/server/src/ → server/, packages/web/src/ → src/, packages/shared/src/ → shared/ - Add functions/api/[[route]].ts as CF Pages Functions entry (replaces entry-cloudflare.ts) - Update 22 import paths: server uses relative, web uses @shared/@server aliases - Merge three package.json into one, switch to npm - Update wrangler.toml: remove main/assets (Pages auto-detects functions/ dir) - Add per-directory tsconfig.json for VS Code type resolution - Simplify Dockerfile for flat layout - Fix react-pdf CSS import path (dist/esm/ → dist/) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
117 lines
3.3 KiB
TypeScript
117 lines
3.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
copyMatterSchema,
|
|
createMatterSchema,
|
|
createStorageSchema,
|
|
signInSchema,
|
|
signUpSchema,
|
|
updateMatterSchema,
|
|
} from './index.js'
|
|
|
|
describe('signInSchema', () => {
|
|
it('accepts valid input', () => {
|
|
const result = signInSchema.safeParse({ email: 'a@b.com', password: '123456' })
|
|
expect(result.success).toBe(true)
|
|
})
|
|
|
|
it('rejects invalid email', () => {
|
|
const result = signInSchema.safeParse({ email: 'bad', password: '123456' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
|
|
it('rejects short password', () => {
|
|
const result = signInSchema.safeParse({ email: 'a@b.com', password: '12345' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('signUpSchema', () => {
|
|
it('accepts valid input', () => {
|
|
const result = signUpSchema.safeParse({ name: 'Test', email: 'a@b.com', password: '123456' })
|
|
expect(result.success).toBe(true)
|
|
})
|
|
|
|
it('rejects empty name', () => {
|
|
const result = signUpSchema.safeParse({ name: '', email: 'a@b.com', password: '123456' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('createStorageSchema', () => {
|
|
const valid = {
|
|
title: 'My S3',
|
|
mode: 'private' as const,
|
|
bucket: 'my-bucket',
|
|
endpoint: 'https://s3.amazonaws.com',
|
|
accessKey: 'AK',
|
|
secretKey: 'SK',
|
|
}
|
|
|
|
it('accepts valid input with defaults', () => {
|
|
const result = createStorageSchema.safeParse(valid)
|
|
expect(result.success).toBe(true)
|
|
if (result.success) {
|
|
expect(result.data.region).toBe('auto')
|
|
expect(result.data.filePath).toBe('$UID/$RAW_NAME')
|
|
}
|
|
})
|
|
|
|
it('rejects invalid mode', () => {
|
|
const result = createStorageSchema.safeParse({ ...valid, mode: 'shared' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
|
|
it('rejects invalid endpoint URL', () => {
|
|
const result = createStorageSchema.safeParse({ ...valid, endpoint: 'not-a-url' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('createMatterSchema', () => {
|
|
it('accepts valid input with defaults', () => {
|
|
const result = createMatterSchema.safeParse({ name: 'file.txt', type: 'text/plain' })
|
|
expect(result.success).toBe(true)
|
|
if (result.success) {
|
|
expect(result.data.parent).toBe('')
|
|
expect(result.data.dirtype).toBe(0)
|
|
}
|
|
})
|
|
|
|
it('rejects empty name', () => {
|
|
const result = createMatterSchema.safeParse({ name: '', type: 'text/plain' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('updateMatterSchema', () => {
|
|
it('accepts partial update with name only', () => {
|
|
const result = updateMatterSchema.safeParse({ name: 'renamed.txt' })
|
|
expect(result.success).toBe(true)
|
|
})
|
|
|
|
it('accepts empty object (no fields)', () => {
|
|
const result = updateMatterSchema.safeParse({})
|
|
expect(result.success).toBe(true)
|
|
})
|
|
|
|
it('rejects empty name', () => {
|
|
const result = updateMatterSchema.safeParse({ name: '' })
|
|
expect(result.success).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('copyMatterSchema', () => {
|
|
it('accepts empty object with default parent', () => {
|
|
const result = copyMatterSchema.safeParse({})
|
|
expect(result.success).toBe(true)
|
|
if (result.success) {
|
|
expect(result.data.parent).toBe('')
|
|
}
|
|
})
|
|
|
|
it('accepts explicit parent', () => {
|
|
const result = copyMatterSchema.safeParse({ parent: 'folder-id' })
|
|
expect(result.success).toBe(true)
|
|
})
|
|
})
|