test: 覆盖预约创建取消和状态流转
This commit is contained in:
1 parent
21801212d2
commit
3640ec46ed
2 files changed
+75
-6
No files matched your search
@@ -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