refactor: 移除旧服务模型统一使用业务提供项

This commit is contained in:
que01 committed 2026-09-21 17:11:45 +08:00
1 parent ca85a583ce
commit 844a3bd715
13 files changed
+92 -146

No files matched your search

+17 -7
View File
@@ -5,17 +5,16 @@ import { BookingService } from "../src/booking.service.js";
const brandId = "brand-1";
const customerId = "customer-1";
const service = {
const offering = {
id: "service-1",
name: "套餐",
bookingEnabled: true,
priceAmount: 2800,
};
function createPrisma(overrides: Record<string, unknown> = {}): any {
return {
service: {
findMany: async () => [service],
offering: {
findMany: async () => [offering],
},
booking: {
create: async ({ data }: any) => ({
@@ -31,7 +30,7 @@ function createPrisma(overrides: Record<string, unknown> = {}): any {
},
tag: { findMany: async () => [] },
bookingTag: { deleteMany: {}, createMany: {} },
$transaction: async () => undefined,
$transaction: async (callback: (tx: unknown) => unknown) => callback(undefined),
...overrides,
};
}
@@ -43,7 +42,7 @@ test("创建普通套餐订单时保存价格快照和预计金额", async () =>
customerName: "陈同学",
wechatId: "wx-test",
contactPreference: "wechat",
items: [{ serviceId: service.id, quantity: 2 }],
items: [{ offeringId: offering.id, quantity: 2 }],
});
assert.equal(result.estimatedAmount, 5600);
assert.equal(result.status, "received");
@@ -85,9 +84,20 @@ test("取消不存在或不属于当前客户的订单返回不存在", async ()
test("订单状态只能按定义的状态机流转", async () => {
const prisma = createPrisma({
booking: {
findFirst: async () => ({ id: "booking-1", status: "received" }),
findFirst: async () => ({
id: "booking-1",
status: "received",
currentState: "received",
workflowKey: "booking.basic",
workflowVersion: "1.0.0",
}),
update: async ({ data }: any) => data,
},
$transaction: async (callback: (tx: any) => unknown) =>
callback({
booking: { update: async ({ data }: any) => data },
bookingStateTransition: { create: async () => undefined },
}),
});
const bookings = new BookingService(prisma);
assert.equal(
+11 -16
View File
@@ -346,7 +346,7 @@ test("admin can read and update brand and service configuration", async () => {
const brandBefore = await prisma.brandProfile.findUnique({ where: { id: brandId } });
assert.ok(brandBefore);
const serviceBefore = await prisma.service.findFirst({ where: { brandId, isEnabled: true } });
const serviceBefore = await prisma.offering.findFirst({ where: { brandId, isEnabled: true } });
assert.ok(serviceBefore);
let createdServiceId;
@@ -381,7 +381,7 @@ test("admin can read and update brand and service configuration", async () => {
const publicServices = await request("/public/services");
assert.equal(publicServices.statusCode, 200);
const projectedService = JSON.parse(publicServices.body).find(
(item) => item.id === serviceBefore.offeringId,
(item) => item.id === serviceBefore.id,
);
assert.equal(projectedService.priceText, "集成测试价格");
@@ -404,10 +404,9 @@ test("admin can read and update brand and service configuration", async () => {
assert.equal(createdService.statusCode, 201);
const createdServiceBody = JSON.parse(createdService.body);
createdServiceId = createdServiceBody.id;
assert.equal(createdServiceBody.categoryKey, "consulting");
assert.ok(createdServiceBody.offeringId);
assert.equal(createdServiceBody.kind, "consulting");
const createdOffering = await prisma.offering.findUnique({
where: { id: createdServiceBody.offeringId },
where: { id: createdServiceBody.id },
});
assert.equal(createdOffering?.name, "集成测试通用服务");
} finally {
@@ -419,15 +418,12 @@ test("admin can read and update brand and service configuration", async () => {
templateKey: brandBefore.templateKey,
},
});
await prisma.service.update({
await prisma.offering.update({
where: { id: serviceBefore.id },
data: { priceText: serviceBefore.priceText, sortOrder: serviceBefore.sortOrder },
});
if (createdServiceId) {
const deletedService = await prisma.service.delete({ where: { id: createdServiceId } });
if (deletedService.offeringId) {
await prisma.offering.delete({ where: { id: deletedService.offeringId } });
}
await prisma.offering.delete({ where: { id: createdServiceId } });
}
}
});
@@ -534,11 +530,10 @@ test("customer can create a generic inquiry without food-specific fields", async
});
test("customer can create and cancel a package booking", async () => {
const service = await prisma.service.findFirst({
const service = await prisma.offering.findFirst({
where: { brandId, isEnabled: true, priceAmount: { not: null } },
});
assert.ok(service);
assert.ok(service.offeringId);
const created = await request("/customer/bookings", {
method: "POST",
headers: { authorization: `Bearer ${customerToken}` },
@@ -547,7 +542,7 @@ test("customer can create and cancel a package booking", async () => {
customerName: "集成测试客户",
wechatId: "integration-wechat",
contactPreference: "wechat",
items: [{ serviceId: service.id, quantity: 2 }],
items: [{ offeringId: service.id, quantity: 2 }],
},
});
assert.equal(created.statusCode, 201);
@@ -557,7 +552,7 @@ test("customer can create and cancel a package booking", async () => {
assert.ok(booking);
assert.equal(booking.workflowKey, "booking.basic");
assert.equal(booking.currentState, "received");
assert.equal(booking.offeringId, service.offeringId);
assert.equal(booking.offeringId, service.id);
const initialTransitions = await prisma.bookingStateTransition.findMany({
where: { bookingId: booking.id },
});
@@ -582,7 +577,7 @@ test("customer can create and cancel a package booking", async () => {
});
test("admin can advance booking status but cannot skip the state machine", async () => {
const service = await prisma.service.findFirst({
const service = await prisma.offering.findFirst({
where: { brandId, isEnabled: true, priceAmount: { not: null } },
});
assert.ok(service);
@@ -594,7 +589,7 @@ test("admin can advance booking status but cannot skip the state machine", async
customerName: "状态测试客户",
phone: "13800000000",
contactPreference: "phone",
items: [{ serviceId: service.id, quantity: 1 }],
items: [{ offeringId: service.id, quantity: 1 }],
},
});
const booking = await prisma.booking.findUnique({