Files
photo-live/services/api/jest.config.ts
T
浅念 a2a3ccd340 feat(api): idempotent upload session init with presigned credential
POST /v1/uploads (Task 18, A03): @@unique(userId, clientTaskId) idempotency
anchor — same params return the original session (201, no duplicate photo);
param drift (album/bytes/contentType/extension) -> 409 UPLOAD_SESSION_CONFLICT.
photos.objectKey is set to the FINAL originals key at init while the session
holds the staging key; IDs come from an app-side cuid-like generator so both
self-referencing keys are written in one transaction. Credential is a real
MinIO presigned PUT (SIGNED_URL_TTL_SECONDS, lazily read). Permission order:
album invisible 404 -> member 403 -> uploadEnabled 409 -> size/ext 400 ->
category ownership 400. No audit on init (audit anchors on complete).

Pre-step for Task 19: QUEUE_PHOTO_PROCESS contract constant + lazy-safe
BullMQ queue producer (Redis down at boot must not crash the app; enqueue
failure only logs — sweep compensates). e2e reset now also wipes the MinIO
photo-live/dev prefix; jest maps @photo/storage to TS source.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-17 22:42:13 +08:00

43 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// services/api/jest.config.ts —— 单测(src/*.spec.ts + test/*.spec.ts,排除 e2e)。
// ts-jest 保持类型检查模式(非 isolatedModules),@ts-expect-error 负向断言可生效;
// 编译选项复用包级 tsconfig.json(Task 7 遗留项:不再内联重复一份 compilerOptions)。
// env 约定:setupFiles 经 test/load-env.ts 载入仓库根 .env(全仓库唯一 env 文件)。
// ESM 互操作:@photo/contracts 为 ESM 包(NodeNext + .js 后缀导入),测试经
// moduleNameMapper 直接指向其 TS 源码,由 ts-jest 以 CJS 编译(同
// packages/contracts/jest.config.cjs 的 .js -> $1 映射模式);运行时(node dist)
// 则经 require(esm) 消费其 dist(Node >= 22.12 支持)。
// @photo/db-cn 为 CJS 包(含 @prisma/client 再导出),同样映射到 TS 源码,
// 免依赖先 build dist;@prisma/client 及其生成的 .prisma/client 由 Node
// 解析规则从 packages/db-cn/node_modules 向上命中。
import type { Config } from 'jest';
const config: Config = {
// 单进程串行:test/ 下的 DB 型 spec(seed.spec.ts、permissions.spec.ts)
// 共享同一 MySQL 库且在 beforeAll 以 reset.ts TRUNCATE 全库重置,jest 默认
// 按文件并行会在 spec 间互相清掉对方刚种的数据(seed.spec 断言全库用户数);
// 串行后纯函数 spec 一并排队,代价可忽略。e2e 配置继承本文件同样受益
// (此前多个 e2e spec 并行 reset 仅靠启动时序侥幸不冲突)。
maxWorkers: 1,
testEnvironment: 'node',
rootDir: '.',
setupFiles: ['./test/load-env.ts'],
transform: {
'^.+\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.json' }],
},
moduleNameMapper: {
'^@photo/contracts$': '<rootDir>/../../packages/contracts/src/index.ts',
'^@photo/db-cn$': '<rootDir>/../../packages/db-cn/src/index.ts',
// Task 18 起:@photo/storage 同样映射到 TS 源码(其依赖 @aws-sdk/* 与
// @photo/contracts 分别从 storage 包 node_modules / 上面的映射解析)。
'^@photo/storage$': '<rootDir>/../../packages/storage/src/index.ts',
'^(\\.{1,2}/.*)\\.js$': '$1',
},
// test/ 下的 *.spec.ts 为直连真实 DB 的集成型单测(seed.spec.ts、
// permissions.spec.ts,各自经 reset.ts 隔离);纯 HTTP e2e 仍由
// jest.e2e.config.ts 的 testMatch 接管。
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/test/**/*.spec.ts'],
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
};
export default config;