test: 覆盖预约创建取消和状态流转
This commit is contained in:
1 parent
21801212d2
commit
3640ec46ed
2 files changed
+75
-6
No files matched your search
+5
-6
@@ -33,7 +33,7 @@
|
||||
- API 自动化业务规则测试:订单创建、客户取消、状态流转和标签品牌隔离,共 6 项通过。
|
||||
- 修复 ESM 下 `bcryptjs` 导入和 Fastify 请求 ID middleware 的运行时问题。
|
||||
- API 已通过真实 HTTP 验证:健康检查、公开品牌/服务读取和管理员登录。
|
||||
- HTTP 集成测试:公开接口、管理员登录、错误密码、管理员权限边界、客户会话和预约 DTO 校验,共 6 项通过。
|
||||
- HTTP 集成测试:公开接口、管理员登录、错误密码、管理员权限边界、客户会话、预约 DTO 校验、创建/取消和状态流转,共 8 项通过。
|
||||
- 已执行多轮 Codex 代码审查并修复关键认证和权限问题。
|
||||
|
||||
## 最近提交
|
||||
@@ -51,11 +51,10 @@ b89853b fix: harden api authentication and validation
|
||||
|
||||
## 下一步优先级
|
||||
|
||||
1. 继续补 HTTP 集成测试:订单创建、取消和状态更新。
|
||||
2. 补 OpenAPI/Swagger 契约和统一响应示例。
|
||||
3. 创建类型化 `api-client`,固定前后端接口边界。
|
||||
4. 接入管理后台订单处理页面。
|
||||
5. 接入小程序品牌展示、服务列表和下单流程。
|
||||
1. 补 OpenAPI/Swagger 契约和统一响应示例。
|
||||
2. 创建类型化 `api-client`,固定前后端接口边界。
|
||||
3. 接入管理后台订单处理页面。
|
||||
4. 接入小程序品牌展示、服务列表和下单流程。
|
||||
|
||||
## 未决问题
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ const prisma = new PrismaClient();
|
||||
const brandId = process.env.DEFAULT_BRAND_ID;
|
||||
const openid = `integration-${Date.now()}`;
|
||||
let customerToken;
|
||||
const createdBookingIds = [];
|
||||
|
||||
before(async () => {
|
||||
await prisma.customerUser.create({ data: { brandId, openid } });
|
||||
@@ -19,6 +20,7 @@ before(async () => {
|
||||
|
||||
after(async () => {
|
||||
await app.close();
|
||||
await prisma.booking.deleteMany({ where: { id: { in: createdBookingIds } } });
|
||||
await prisma.customerUser.deleteMany({ where: { openid } });
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
@@ -105,3 +107,71 @@ test("customer booking DTO rejects incomplete package requests", async () => {
|
||||
assert.equal(response.statusCode, 400);
|
||||
assert.equal(JSON.parse(response.body).error.code, "HTTP_400");
|
||||
});
|
||||
|
||||
test("customer can create and cancel a package booking", async () => {
|
||||
const service = await prisma.service.findFirst({ where: { brandId, isEnabled: true, priceAmount: { not: null } } });
|
||||
assert.ok(service);
|
||||
const created = await request("/customer/bookings", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
payload: {
|
||||
requestType: "package",
|
||||
customerName: "集成测试客户",
|
||||
wechatId: "integration-wechat",
|
||||
contactPreference: "wechat",
|
||||
items: [{ serviceId: service.id, quantity: 2 }],
|
||||
},
|
||||
});
|
||||
assert.equal(created.statusCode, 201);
|
||||
const createdBody = JSON.parse(created.body);
|
||||
assert.equal(createdBody.estimatedAmount, service.priceAmount * 2);
|
||||
const booking = await prisma.booking.findUnique({ where: { bookingNo: createdBody.bookingNo } });
|
||||
assert.ok(booking);
|
||||
createdBookingIds.push(booking.id);
|
||||
|
||||
const cancelled = await request(`/customer/bookings/${booking.id}/cancel`, {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
});
|
||||
assert.equal(cancelled.statusCode, 201);
|
||||
assert.equal(JSON.parse(cancelled.body).status, "cancelled");
|
||||
});
|
||||
|
||||
test("admin can advance booking status but cannot skip the state machine", async () => {
|
||||
const service = await prisma.service.findFirst({ where: { brandId, isEnabled: true, priceAmount: { not: null } } });
|
||||
assert.ok(service);
|
||||
const created = await request("/customer/bookings", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
payload: {
|
||||
requestType: "package",
|
||||
customerName: "状态测试客户",
|
||||
phone: "13800000000",
|
||||
contactPreference: "phone",
|
||||
items: [{ serviceId: service.id, quantity: 1 }],
|
||||
},
|
||||
});
|
||||
const booking = await prisma.booking.findUnique({ where: { bookingNo: JSON.parse(created.body).bookingNo } });
|
||||
assert.ok(booking);
|
||||
createdBookingIds.push(booking.id);
|
||||
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
const adminToken = JSON.parse(login.body).token;
|
||||
const contacting = await request(`/admin/bookings/${booking.id}/status`, {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
payload: { status: "contacting", adminNote: "已联系客户" },
|
||||
});
|
||||
assert.equal(contacting.statusCode, 201);
|
||||
assert.equal(JSON.parse(contacting.body).status, "contacting");
|
||||
|
||||
const skipped = await request(`/admin/bookings/${booking.id}/status`, {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
payload: { status: "completed" },
|
||||
});
|
||||
assert.equal(skipped.statusCode, 400);
|
||||
});
|
||||
Reference in new issue
Block a user