From 7821c0c98c29a7933fe2d35d57dfce58b614dca4 Mon Sep 17 00:00:00 2001 From: que01 Date: Tue, 22 Sep 2026 11:25:03 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=A6=86=E7=9B=96=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E9=A1=B9=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/test/http.integration.test.js | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index ef4addc..8d57f65 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -320,8 +320,44 @@ test("admin can manage offerings and public endpoint hides disabled offerings", assert.equal(updated.statusCode, 200); const hidden = await request(`/public/offerings/${id}`); assert.equal(hidden.statusCode, 400); + const reenabled = await request(`/admin/workspace/offerings/${id}`, { + method: "PATCH", + headers: { authorization: `Bearer ${token}` }, + payload: { isEnabled: true }, + }); + assert.equal(reenabled.statusCode, 200); + assert.equal((await request(`/public/offerings/${id}`)).statusCode, 200); } finally { - await prisma.offering.delete({ where: { id } }); + const deleted = await request(`/admin/workspace/offerings/${id}`, { + method: "DELETE", + headers: { authorization: `Bearer ${token}` }, + }); + assert.equal(deleted.statusCode, 200); + assert.equal(await prisma.offering.findUnique({ where: { id } }), null); + } +}); + +test("offering with an inquiry form cannot be deleted", async () => { + const login = await request("/admin/session/login", { + method: "POST", + payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD }, + }); + const token = JSON.parse(login.body).token; + const offering = await prisma.offering.create({ + data: { brandId, kind: "service", name: `保护测试-${Date.now()}`, description: "测试" }, + }); + const form = await prisma.inquiryForm.create({ + data: { brandId, offeringId: offering.id, name: "保护测试表单", fieldsSnapshot: [] }, + }); + try { + const response = await request(`/admin/workspace/offerings/${offering.id}`, { + method: "DELETE", + headers: { authorization: `Bearer ${token}` }, + }); + assert.equal(response.statusCode, 400); + } finally { + await prisma.inquiryForm.delete({ where: { id: form.id } }); + await prisma.offering.delete({ where: { id: offering.id } }); } });