test: 覆盖后台配置接口
This commit is contained in:
1 parent
f485257e37
commit
3ddef14c08
1 file changed
+43
@@ -83,6 +83,49 @@ test("admin login validates credentials", async () => {
|
||||
assert.equal(response.statusCode, 401);
|
||||
});
|
||||
|
||||
test("admin can read and update brand and service configuration", async () => {
|
||||
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;
|
||||
assert.ok(adminToken);
|
||||
|
||||
const unauthorized = await request("/admin/config/brand");
|
||||
assert.equal(unauthorized.statusCode, 400);
|
||||
|
||||
const brandBefore = await prisma.brandProfile.findUnique({ where: { id: brandId } });
|
||||
assert.ok(brandBefore);
|
||||
const serviceBefore = await prisma.service.findFirst({ where: { brandId, isEnabled: true } });
|
||||
assert.ok(serviceBefore);
|
||||
|
||||
try {
|
||||
const brand = await request("/admin/config/brand", { headers: { authorization: `Bearer ${adminToken}` } });
|
||||
assert.equal(brand.statusCode, 200);
|
||||
assert.equal(JSON.parse(brand.body).id, brandId);
|
||||
|
||||
const updatedBrand = await request("/admin/config/brand", {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
payload: { description: "集成测试品牌简介", contactPhone: "13800000000" },
|
||||
});
|
||||
assert.equal(updatedBrand.statusCode, 200);
|
||||
assert.equal(JSON.parse(updatedBrand.body).description, "集成测试品牌简介");
|
||||
|
||||
const updatedService = await request(`/admin/config/services/${serviceBefore.id}`, {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
payload: { priceText: "集成测试价格", sortOrder: 99 },
|
||||
});
|
||||
assert.equal(updatedService.statusCode, 200);
|
||||
assert.equal(JSON.parse(updatedService.body).priceText, "集成测试价格");
|
||||
assert.equal(JSON.parse(updatedService.body).sortOrder, 99);
|
||||
} finally {
|
||||
await prisma.brandProfile.update({ where: { id: brandId }, data: { description: brandBefore.description, contactPhone: brandBefore.contactPhone } });
|
||||
await prisma.service.update({ where: { id: serviceBefore.id }, data: { priceText: serviceBefore.priceText, sortOrder: serviceBefore.sortOrder } });
|
||||
}
|
||||
});
|
||||
|
||||
test("customer booking endpoints require a valid customer session", async () => {
|
||||
const missing = await request("/customer/bookings");
|
||||
assert.equal(missing.statusCode, 400);
|
||||
|
||||
Reference in new issue
Block a user