feat(escort): 下单强制确认免责协议并留存版本快照
新增 GET /health/disclaimer 与精简版免责协议正文(对齐 GB/T 47801);非管理员下单须勾选且协议版本与服务端一致,服务端盖章写入 accepted/version/acceptedAt;agreement 不在更新白名单内,保证凭据不可篡改。
This commit is contained in:
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
|
||||
|
||||
import { DBModel } from "../models/index.js";
|
||||
import { HandlerEscortRecord } from "../handler/escort_record.js";
|
||||
import { disclaimer } from "../resource/agreement.js";
|
||||
|
||||
const USER_ID = "64b000000000000000000101";
|
||||
const PROFILE_ID = "64b000000000000000000102";
|
||||
@@ -45,6 +46,8 @@ function buildBody(attendant) {
|
||||
hospital: { province: "北京市", name: "北京协和医院" },
|
||||
schedule: { date: futureDate(3), startTime: "08:00" },
|
||||
payment: { payChannel: "offline" },
|
||||
// 非管理员下单必须确认免责协议,且版本需与服务端当前版本一致
|
||||
agreement: { accepted: true, version: disclaimer.version },
|
||||
...(attendant ? { attendant } : {}),
|
||||
};
|
||||
}
|
||||
@@ -83,7 +86,7 @@ function employeeFindOneStub(employee, overrides = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
async function runCreate({ attendant, employee = buildEmployee(), user } = {}) {
|
||||
async function runCreate({ attendant, employee = buildEmployee(), user, bodyOverrides } = {}) {
|
||||
const calls = { payload: null, bumped: null };
|
||||
const recordStub = {
|
||||
findByIdempotencyKey: async () => null,
|
||||
@@ -99,7 +102,7 @@ async function runCreate({ attendant, employee = buildEmployee(), user } = {}) {
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = createCtx(buildBody(attendant), user);
|
||||
const ctx = createCtx({ ...buildBody(attendant), ...(bodyOverrides || {}) }, user);
|
||||
await withModel("HealthProfile", { findProfileById: async () => buildProfile() }, () =>
|
||||
withModel("EscortRecord", recordStub, () =>
|
||||
withModel("Employee", employeeStub, () => new HandlerEscortRecord().createRecord(ctx))
|
||||
@@ -187,3 +190,23 @@ test("陪诊师 ID 不合法返回 400", async () => {
|
||||
assert.equal(ctx.body.code, 400);
|
||||
assert.equal(calls.payload, null);
|
||||
});
|
||||
|
||||
test("用户下单未确认免责协议返回 400 且不创建订单", async () => {
|
||||
const { ctx, calls } = await runCreate({
|
||||
bodyOverrides: { agreement: undefined },
|
||||
});
|
||||
|
||||
assert.equal(ctx.body.code, 400);
|
||||
assert.match(ctx.body.msg, /免责协议/);
|
||||
assert.equal(calls.payload, null);
|
||||
});
|
||||
|
||||
test("用户下单协议版本过期返回 400 且不创建订单", async () => {
|
||||
const { ctx, calls } = await runCreate({
|
||||
bodyOverrides: { agreement: { accepted: true, version: "2000-01-01" } },
|
||||
});
|
||||
|
||||
assert.equal(ctx.body.code, 400);
|
||||
assert.match(ctx.body.msg, /已更新/);
|
||||
assert.equal(calls.payload, null);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user