fix(attendant): 订单池审查问题修复

接单排除取消中/已取消订单;已取消订单禁止变动共享名单;取消共享补 404;实习脱敏补收货人姓名与诉求并禁用关键词侧信道。
This commit is contained in:
lik
2026-11-10 12:54:18 +08:00
parent d60a160180
commit 78138a417b
3 changed files with 116 additions and 11 deletions
+86 -5
View File
@@ -21,7 +21,7 @@ function buildRecord(overrides = {}) {
patient: { name: "张三", mobile: "13800138000" },
escort: { serviceId: 1, serviceName: "全天陪诊" },
hospital: { name: "北京协和医院", address: "北京市东城区", medicalRecordNo: "MR0001" },
shippingAddress: { mobile: "13900139000", address: "北京市西城区" },
shippingAddress: { recipientName: "张三", mobile: "13900139000", address: "北京市西城区" },
inquiry: { medicalHistory: "高血压", demand: "陪同检查" },
schedule: {
date: new Date("2026-12-01T00:00:00.000Z"),
@@ -47,9 +47,9 @@ function buildEmployee(overrides = {}) {
};
}
function createCtx({ body = {}, user, params = { id: RECORD_ID } } = {}) {
function createCtx({ body = {}, query = {}, user, params = { id: RECORD_ID } } = {}) {
return {
request: { query: {}, body },
request: { query, body },
params,
state: { user: user ?? { _id: CERT_USER_ID } },
headers: {},
@@ -96,13 +96,18 @@ test("实习陪诊师看未分配订单:可见范围含未分配且按 employe
await withModel("Employee", employeeFindOneStub(intern), () =>
withModel("EscortRecord", recordStub, async () => {
const ctx = createCtx({ user: { _id: INTERN_USER_ID } });
const ctx = createCtx({
user: { _id: INTERN_USER_ID },
// 实习传关键词想按手机号搜池订单:应被服务端忽略(防侧信道)
query: { keyword: "13800138000" },
});
await new HandlerEscortRecord().getAttendantRecords(ctx);
assert.equal(ctx.body.code, 0);
assert.equal(captured.attendantVisibility.includeUnassigned, true);
assert.equal(captured.attendantVisibility.userId, undefined);
assert.equal(String(captured.attendantVisibility.employeeId), INTERN_EMPLOYEE_ID);
assert.equal(captured.keyword, undefined);
const record = ctx.body.data.records[0];
assert.equal(record.isPoolOrder, true);
@@ -111,7 +116,9 @@ test("实习陪诊师看未分配订单:可见范围含未分配且按 employe
assert.equal(record.patient.mobile, "138****8000");
assert.equal(record.hospital.address, "接单后可见");
assert.equal(record.hospital.medicalRecordNo, "接单后可见");
assert.equal(record.shippingAddress.recipientName, "张**");
assert.equal(record.inquiry.medicalHistory, "接单后可见");
assert.equal(record.inquiry.demand, "接单后可见");
})
);
});
@@ -130,12 +137,17 @@ test("正式陪诊师可见本人已接与被共享订单,未分配同样在
await withModel("Employee", employeeFindOneStub(buildEmployee()), () =>
withModel("EscortRecord", recordStub, async () => {
const ctx = createCtx({ user: { _id: CERT_USER_ID } });
const ctx = createCtx({
user: { _id: CERT_USER_ID },
// 正式陪诊师可见完整信息,keyword 正常生效
query: { keyword: "协和" },
});
await new HandlerEscortRecord().getAttendantRecords(ctx);
assert.equal(ctx.body.code, 0);
assert.equal(captured.attendantVisibility.includeUnassigned, true);
assert.equal(String(captured.attendantVisibility.userId), CERT_USER_ID);
assert.equal(captured.keyword, "协和");
const item = ctx.body.data.records[0];
assert.equal(item.attendantSharedToMe, true);
@@ -317,3 +329,72 @@ test("实习陪诊师可看未分配订单详情,但不能看他人已接且
})
);
});
test("取消中/已取消订单不能接单", async () => {
const cases = [
{ cancelStatus: "requested", msg: "取消申请确认中" },
{ cancelStatus: "cancelled", msg: "订单已取消" },
{ status: "cancelled", msg: "订单已取消" },
];
for (const override of cases) {
let accepted = 0;
await withModel("Employee", employeeFindOneStub(buildEmployee()), () =>
withModel("EscortRecord", {
findById: async () => buildRecord(override),
acceptRecord: async () => {
accepted += 1;
return buildRecord();
},
}, async () => {
const ctx = createCtx({ user: { _id: CERT_USER_ID } });
await new HandlerEscortRecord().acceptRecord(ctx);
assert.equal(ctx.body.code, 409, `场景 ${JSON.stringify(override)} 应返回 409`);
assert.equal(accepted, 0);
})
);
}
});
test("已取消订单不能共享", async () => {
let shared = 0;
const recordStub = {
findById: async () => buildRecord({
cancelStatus: "cancelled",
attendant: { id: CERT_USER_ID, name: "李四", sharedWith: [] },
}),
addSharedWith: async () => {
shared += 1;
return null;
},
};
await withModel("Employee", employeeFindOneStub(buildEmployee()), () =>
withModel("EscortRecord", recordStub, async () => {
const ctx = createCtx({
user: { _id: CERT_USER_ID },
body: { employeeIds: [INTERN_EMPLOYEE_ID] },
});
await new HandlerEscortRecord().shareRecord(ctx);
assert.equal(ctx.body.code, 409);
assert.equal(shared, 0);
})
);
});
test("取消共享时订单不存在返回 404", async () => {
await withModel("Employee", employeeFindOneStub(buildEmployee()), () =>
withModel("EscortRecord", {
findById: async () => null,
}, async () => {
const ctx = createCtx({
user: { _id: CERT_USER_ID },
body: { employeeIds: [INTERN_EMPLOYEE_ID] },
});
await new HandlerEscortRecord().unshareRecord(ctx);
assert.equal(ctx.body.code, 404);
})
);
});