feat(attendant): 入驻默认实习阶段并新增阶段等级调整接口

- employee.attendantInfo 增加 stage/grade/star,存量档案按正式青铜归一化

- 入驻审批仅在新建档案时写 intern,重新激活保留原阶段

- /employee/me 返回阶段等级与 canAcceptOrder

- C 端公示列表与详情排除实习陪诊师

- 新增 PATCH /employee/:id/level:转正、调级、钻石设星
This commit is contained in:
lik
2026-11-10 12:02:07 +08:00
parent d748034835
commit 67f2962574
5 changed files with 288 additions and 17 deletions
+149
View File
@@ -300,6 +300,155 @@ test("审批遇岗位冲突时申请单回滚为 pending,不卡死在 approved
});
});
test("入驻审批新建档案只写实习阶段,重新激活不改动已有阶段", async () => {
let capturedUpdate = null;
const stub = {
findOne: () => ({
select: () => ({ lean: () => ({ exec: async () => ({ role: "attendant" }) }) }),
}),
findOneAndUpdate: (filter, update) => {
capturedUpdate = update;
return { exec: async () => ({ _id: OWNER_ID }) };
},
};
await withModel("Employee", stub, async () => {
await HandlerAttendantApplication.ensureEmployee({
userId: OWNER_ID,
applicant: { name: "张三" },
materials: {},
});
// 只在插入时给实习身份;$set 不能带 stage,否则重新审批会把已转正的人降回实习
assert.equal(capturedUpdate.$setOnInsert["attendantInfo.stage"], "intern");
assert.equal(capturedUpdate.$set["attendantInfo.stage"], undefined);
});
});
test("公示口径排除实习陪诊师,存量无阶段字段仍视为正式", () => {
const filter = HandlerEmployee.publicAttendantFilter();
assert.equal(filter.role, "attendant");
assert.equal(filter.status, "active");
// $ne 对缺失字段同样成立,历史档案不会被误排除
assert.deepEqual(filter["attendantInfo.stage"], { $ne: "intern" });
});
test("/employee/me 对存量档案按正式陪诊师归一化并允许接单", async () => {
const stub = {
findOne: () => ({
select: () => ({
lean: () => ({ exec: async () => ({ _id: OWNER_ID, role: "attendant", status: "active" }) }),
}),
}),
};
await withModel("Employee", stub, async () => {
const ctx = createCtx({ user: { _id: OWNER_ID } });
await new HandlerEmployee().getMyEmployee(ctx);
assert.equal(ctx.body.code, 0);
assert.equal(ctx.body.data.employee.attendantInfo.stage, "certified");
assert.equal(ctx.body.data.employee.attendantInfo.grade, "bronze");
assert.equal(ctx.body.data.employee.canAcceptOrder, true);
});
});
test("/employee/me 实习陪诊师不可接单,非钻石等级星级归零", async () => {
const stub = {
findOne: () => ({
select: () => ({
lean: () => ({
exec: async () => ({
_id: OWNER_ID,
role: "attendant",
status: "active",
attendantInfo: { stage: "intern", grade: "silver", star: 3 },
}),
}),
}),
}),
};
await withModel("Employee", stub, async () => {
const ctx = createCtx({ user: { _id: OWNER_ID } });
await new HandlerEmployee().getMyEmployee(ctx);
assert.equal(ctx.body.code, 0);
assert.equal(ctx.body.data.employee.attendantInfo.stage, "intern");
assert.equal(ctx.body.data.employee.attendantInfo.star, 0);
assert.equal(ctx.body.data.employee.canAcceptOrder, false);
});
});
/** Employee.findById 链式 stub + updateEmployee 记录 */
function levelStub(employee) {
const calls = { update: null };
return {
calls,
findById: () => ({
select: () => ({ lean: () => ({ exec: async () => employee }) }),
}),
updateEmployee: async (id, flat) => {
calls.update = flat;
return { _id: id };
},
};
}
test("管理员可把实习陪诊师转正并调级", async () => {
const stub = levelStub({ role: "attendant", attendantInfo: { stage: "intern", grade: "bronze" } });
await withModel("Employee", stub, async () => {
const ctx = createCtx({
params: { id: OWNER_ID },
body: { stage: "certified", grade: "silver" },
});
await new HandlerEmployee().updateEmployeeLevel(ctx);
assert.equal(ctx.body.code, 0);
assert.deepEqual(stub.calls.update, {
"attendantInfo.stage": "certified",
"attendantInfo.grade": "silver",
});
});
});
test("非钻石等级不能设置星级", async () => {
const stub = levelStub({ role: "attendant", attendantInfo: { grade: "gold" } });
await withModel("Employee", stub, async () => {
const ctx = createCtx({ params: { id: OWNER_ID }, body: { star: 3 } });
await new HandlerEmployee().updateEmployeeLevel(ctx);
assert.equal(ctx.body.code, 400);
assert.equal(stub.calls.update, null);
});
});
test("离开钻石等级时星级自动归零", async () => {
const stub = levelStub({ role: "attendant", attendantInfo: { grade: "diamond", star: 4 } });
await withModel("Employee", stub, async () => {
const ctx = createCtx({ params: { id: OWNER_ID }, body: { grade: "gold" } });
await new HandlerEmployee().updateEmployeeLevel(ctx);
assert.equal(ctx.body.code, 0);
assert.equal(stub.calls.update["attendantInfo.star"], 0);
});
});
test("非陪诊师岗位不能设置阶段与等级", async () => {
const stub = levelStub({ role: "nurse" });
await withModel("Employee", stub, async () => {
const ctx = createCtx({ params: { id: OWNER_ID }, body: { grade: "gold" } });
await new HandlerEmployee().updateEmployeeLevel(ctx);
assert.equal(ctx.body.code, 400);
assert.equal(stub.calls.update, null);
});
});
test("身份证被其他岗位档案占用时,查重文案按实际岗位提示", async () => {
const employeeStub = employeeFindOneStub((filter) => {
// 按账号查:本账号无档案;按身份证查重:命中护士档案