test: 覆盖业务提供项生命周期操作
This commit is contained in:
1 parent
2aafa871bc
commit
7821c0c98c
1 file changed
+37
-1
@@ -320,8 +320,44 @@ test("admin can manage offerings and public endpoint hides disabled offerings",
|
|||||||
assert.equal(updated.statusCode, 200);
|
assert.equal(updated.statusCode, 200);
|
||||||
const hidden = await request(`/public/offerings/${id}`);
|
const hidden = await request(`/public/offerings/${id}`);
|
||||||
assert.equal(hidden.statusCode, 400);
|
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 {
|
} 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 } });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user