feat: 收口多品牌与模板构建基础
This commit is contained in:
1 parent
0425a1c672
commit
77224ea51f
317 files changed
+11290
-1158
No files matched your search
@@ -2,6 +2,8 @@ import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { BadRequestException, NotFoundException } from "@nestjs/common";
|
||||
import { BookingService } from "../src/booking.service.js";
|
||||
import type { PrismaService } from "../src/prisma.service.js";
|
||||
import type { BrandReleaseService } from "../src/brand-release.service.js";
|
||||
|
||||
const brandId = "brand-1";
|
||||
const customerId = "customer-1";
|
||||
@@ -11,20 +13,20 @@ const offering = {
|
||||
priceAmount: 2800,
|
||||
};
|
||||
|
||||
function createPrisma(overrides: Record<string, unknown> = {}): any {
|
||||
function createPrisma(overrides: Record<string, unknown> = {}): PrismaService {
|
||||
return {
|
||||
offering: {
|
||||
findMany: async () => [offering],
|
||||
count: async () => 1,
|
||||
},
|
||||
booking: {
|
||||
create: async ({ data }: any) => ({
|
||||
create: async ({ data }: { data: { estimatedAmount: number | null } }) => ({
|
||||
bookingNo: "AC-test",
|
||||
status: "received",
|
||||
estimatedAmount: data.estimatedAmount,
|
||||
createdAt: new Date(),
|
||||
}),
|
||||
findFirst: async () => null,
|
||||
update: async ({ data }: any) => ({ status: data.status }),
|
||||
update: async ({ data }: { data: { status: string } }) => ({ status: data.status }),
|
||||
findMany: async () => [],
|
||||
count: async () => 0,
|
||||
},
|
||||
@@ -32,12 +34,20 @@ function createPrisma(overrides: Record<string, unknown> = {}): any {
|
||||
bookingTag: { deleteMany: {}, createMany: {} },
|
||||
$transaction: async (callback: (tx: unknown) => unknown) => callback(undefined),
|
||||
...overrides,
|
||||
};
|
||||
} as unknown as PrismaService;
|
||||
}
|
||||
|
||||
function createService(prisma = createPrisma()): BookingService {
|
||||
const releases = {
|
||||
getPublishedSnapshot: async () => ({ offerings: [{ ...offering, isEnabled: true }] }),
|
||||
publishedOfferingIds: () => new Set([offering.id]),
|
||||
} as unknown as BrandReleaseService;
|
||||
return new BookingService(prisma, releases);
|
||||
}
|
||||
|
||||
test("创建普通套餐订单时保存价格快照和预计金额", async () => {
|
||||
const prisma = createPrisma();
|
||||
const result = await new BookingService(prisma).create(brandId, customerId, {
|
||||
const result = await createService(prisma).create(brandId, customerId, {
|
||||
requestType: "package",
|
||||
customerName: "陈同学",
|
||||
wechatId: "wx-test",
|
||||
@@ -51,7 +61,7 @@ test("创建普通套餐订单时保存价格快照和预计金额", async () =>
|
||||
test("普通套餐不能在没有明细时创建", async () => {
|
||||
await assert.rejects(
|
||||
() =>
|
||||
new BookingService(createPrisma()).create(brandId, customerId, {
|
||||
createService().create(brandId, customerId, {
|
||||
requestType: "package",
|
||||
customerName: "陈同学",
|
||||
phone: "13800000000",
|
||||
@@ -69,14 +79,14 @@ test("客户只能取消自己的 received 订单", async () => {
|
||||
},
|
||||
});
|
||||
await assert.rejects(
|
||||
() => new BookingService(prisma).cancelForCustomer(brandId, customerId, "booking-1"),
|
||||
() => createService(prisma).cancelForCustomer(brandId, customerId, "booking-1"),
|
||||
(error: unknown) => error instanceof BadRequestException,
|
||||
);
|
||||
});
|
||||
|
||||
test("取消不存在或不属于当前客户的订单返回不存在", async () => {
|
||||
await assert.rejects(
|
||||
() => new BookingService(createPrisma()).cancelForCustomer(brandId, customerId, "missing"),
|
||||
() => createService().cancelForCustomer(brandId, customerId, "missing"),
|
||||
(error: unknown) => error instanceof NotFoundException,
|
||||
);
|
||||
});
|
||||
@@ -91,15 +101,15 @@ test("订单状态只能按定义的状态机流转", async () => {
|
||||
workflowKey: "booking.basic",
|
||||
workflowVersion: "1.0.0",
|
||||
}),
|
||||
update: async ({ data }: any) => data,
|
||||
update: async ({ data }: { data: { status: string } }) => data,
|
||||
},
|
||||
$transaction: async (callback: (tx: any) => unknown) =>
|
||||
$transaction: async (callback: (tx: unknown) => unknown) =>
|
||||
callback({
|
||||
booking: { update: async ({ data }: any) => data },
|
||||
booking: { update: async ({ data }: { data: { status: string } }) => data },
|
||||
bookingStateTransition: { create: async () => undefined },
|
||||
}),
|
||||
});
|
||||
const bookings = new BookingService(prisma);
|
||||
const bookings = createService(prisma);
|
||||
assert.equal(
|
||||
(await bookings.updateStatus(brandId, "booking-1", "contacting")).status,
|
||||
"contacting",
|
||||
@@ -116,7 +126,7 @@ test("更新订单标签时拒绝其他品牌的标签", async () => {
|
||||
tag: { findMany: async () => [] },
|
||||
});
|
||||
await assert.rejects(
|
||||
() => new BookingService(prisma).updateTags(brandId, "booking-1", ["foreign-tag"]),
|
||||
() => createService(prisma).updateTags(brandId, "booking-1", ["foreign-tag"]),
|
||||
(error: unknown) => error instanceof BadRequestException,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user