Files
photo-live/services/api/jest.config.ts
T
浅念 2d9b9f9fad feat(api): server-side album role permission checks
Task 14 (A02 foundation): PermissionsService with fresh-DB-per-call
canViewAlbum/canManageAlbum/canUploadToAlbum/canManagePhoto over the
album_members @@unique([albumId,userId]) compound key; admin bypass,
owner/collaborator matrix per requirements doc section 2, removed
members lose access on the very next call (no caching). Boolean-only
returns; callers map 404/403. AlbumsModule shell wired into app module
(controllers arrive in Task 15). jest maxWorkers=1: DB-backed specs
share one MySQL database and reset it via TRUNCATE, so parallel spec
files wipe each other's seed data.

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

40 lines
2.2 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',
'^(\\.{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;