package.json test:e2e:prepare 现在是 migrate reset --force && prisma generate && seed 为 seed 运行时补充 JS Prisma client 生成器: schema.prisma 修复 seed 在 ESM/CJS 下的 Prisma 导入兼容: seed.mjs 修复 Jest 环境未加载 .env 导致连到 127.0.0.1 的问题: e2e-app.helper.ts 修复夹具依赖“名称”导致被组织测试改名后失效的问题(改为按 seed openId 反查): e2e-fixtures.helper.ts 修复组织测试的状态污染与清理逻辑,并收敛 afterAll 资源释放: organization.e2e-spec.ts e2e-context.helper.ts
38 lines
999 B
TypeScript
38 lines
999 B
TypeScript
import type { Response } from 'supertest';
|
|
|
|
export function expectSuccessEnvelope(response: Response, status: number) {
|
|
expect(response.status).toBe(status);
|
|
expect(response.body).toEqual(
|
|
expect.objectContaining({
|
|
code: 0,
|
|
msg: '成功',
|
|
}),
|
|
);
|
|
expect(response.body).toHaveProperty('data');
|
|
}
|
|
|
|
export function expectErrorEnvelope(
|
|
response: Response,
|
|
status: number,
|
|
messageIncludes?: string,
|
|
) {
|
|
expect(response.status).toBe(status);
|
|
expect(response.body.code).toBe(status);
|
|
expect(response.body.data).toBeNull();
|
|
|
|
if (messageIncludes) {
|
|
expect(String(response.body.msg)).toContain(messageIncludes);
|
|
}
|
|
}
|
|
|
|
export function uniqueSeedValue(prefix: string): string {
|
|
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
}
|
|
|
|
export function uniquePhone(): string {
|
|
const suffix = `${Date.now()}${Math.floor(Math.random() * 1000)}`
|
|
.replace(/\D/g, '')
|
|
.slice(-10);
|
|
return `1${suffix.padStart(10, '0')}`.slice(0, 11);
|
|
}
|