feat(attendant): 入驻免身份证材料、城市单选、材料后补与订单池同城过滤

入驻申请只收基本信息(身份证选填、材料全可空),服务城市改为单选白名单(北京/上海/天津/西安,默认北京);新增 POST /attendant-application/mine/materials 材料后补与 PATCH /employee/me/service-area 改城市接口;订单池按陪诊师服务城市过滤(本人已接/被共享不限城市),接单与详情二次校验;appId wxapp-escort-admin 更名为 wxapp_companion。
This commit is contained in:
lik
2026-11-10 16:33:47 +08:00
parent 3086a40b4c
commit cd3b109730
14 changed files with 522 additions and 84 deletions
+165 -2
View File
@@ -112,7 +112,10 @@ test("驳回后重新提交可沿用上一份证件照,无需重复上传", ()
const result = HandlerAttendantApplication.parsePayload(payload, previous);
assert.equal(result.error, undefined);
assert.equal(result.value.materials.qualification.mime, "image/jpeg");
assert.equal(result.value.materials.healthCertificate.expireDate, expireDate);
// 照片沿用上一份,但健康证有效期不再继承:重提表单已无日期输入,
// 沿用旧日期会让过期的历史申请永远无法重新提交
assert.equal(result.value.materials.healthCertificate.data, previous.materials.healthCertificate.data);
assert.equal(result.value.materials.healthCertificate.expireDate, undefined);
});
test("入驻材料单张图片按 3MB 上限校验", () => {
@@ -201,7 +204,7 @@ test("停用陪诊师重新申请不被岗位拦截,可正常提交", async ()
await withModel("AttendantApplication", applicationStub, async () => {
const ctx = createCtx({
body: validPayload(),
user: { _id: OWNER_ID, apps: [{ appId: "wxapp-escort-admin", status: "active" }] },
user: { _id: OWNER_ID, apps: [{ appId: "wxapp_companion", status: "active" }] },
});
await new HandlerAttendantApplication().createApplication(ctx);
@@ -468,3 +471,163 @@ test("身份证被其他岗位档案占用时,查重文案按实际岗位提
});
});
});
test("证件材料全部可空,提交只校验基本信息与城市", () => {
const payload = validPayload();
delete payload.materials;
delete payload.healthExpireDate;
const result = HandlerAttendantApplication.parsePayload(payload);
assert.equal(result.error, undefined);
assert.deepEqual(result.value.materials, {});
assert.deepEqual(result.value.applicant.serviceAreas, ["北京市"]);
});
test("身份证先不填也能提交,不落空串", () => {
const payload = validPayload();
delete payload.applicant.idNumber;
delete payload.materials;
delete payload.healthExpireDate;
const result = HandlerAttendantApplication.parsePayload(payload);
assert.equal(result.error, undefined);
assert.equal(Object.hasOwn(result.value.applicant, "idNumber"), false);
});
test("只补健康证有效期、不传照片也可通过校验", () => {
const payload = validPayload({ materials: {} });
const result = HandlerAttendantApplication.parsePayload(payload);
assert.equal(result.error, undefined);
assert.equal(result.value.materials.qualification, undefined);
assert.ok(result.value.materials.healthCertificate.expireDate instanceof Date);
assert.equal(result.value.materials.healthCertificate.data, undefined);
});
test("服务城市必须单选且在白名单内", () => {
const base = validPayload().applicant;
const empty = HandlerAttendantApplication.parsePayload(
validPayload({ applicant: { ...base, serviceAreas: [] } })
);
assert.equal(empty.error, "请选择一个服务城市");
const multiple = HandlerAttendantApplication.parsePayload(
validPayload({ applicant: { ...base, serviceAreas: ["北京市", "上海市"] } })
);
assert.equal(multiple.error, "请选择一个服务城市");
const invalid = HandlerAttendantApplication.parsePayload(
validPayload({ applicant: { ...base, serviceAreas: ["广州市"] } })
);
assert.equal(invalid.error, "服务城市不在可选范围");
});
test("材料后补:仅合并本次传入字段,不覆盖未提交的材料", async () => {
const application = {
_id: OWNER_ID,
status: "approved",
meta: {},
};
let capturedUpdate = null;
const applicationStub = {
findLatestByUser: async () => application,
findByIdAndUpdate: (id, update) => {
capturedUpdate = update;
return { exec: async () => ({ ...application, materials: { qualification: { data: "x" } } }) };
},
};
const employeeStub = { updateOne: () => ({ exec: async () => ({}) }) };
await withModel("AttendantApplication", applicationStub, async () => {
await withModel("Employee", employeeStub, async () => {
const ctx = createCtx({ body: { qualification: jpegDataUrl() } });
await new HandlerAttendantApplication().updateMyMaterials(ctx);
assert.equal(ctx.body.code, 0);
assert.ok(capturedUpdate.$set["materials.qualification"]);
// 未传健康证明:不能顺带清空或改写
assert.equal(capturedUpdate.$set["materials.healthCertificate"], undefined);
});
});
});
test("材料后补:已驳回的申请不允许补传", async () => {
const applicationStub = {
findLatestByUser: async () => ({ _id: OWNER_ID, status: "rejected" }),
};
await withModel("AttendantApplication", applicationStub, async () => {
const ctx = createCtx({ body: { qualification: jpegDataUrl() } });
await new HandlerAttendantApplication().updateMyMaterials(ctx);
assert.equal(ctx.body.code, 409);
assert.match(ctx.body.msg, /重新提交入驻申请/);
});
});
test("陪诊师本人修改服务城市:在职落库为单城市数组", async () => {
let capturedFilter = null;
let capturedUpdate = null;
const stub = {
findOneAndUpdate: (filter, update) => {
capturedFilter = filter;
capturedUpdate = update;
return {
select: () => ({
lean: () => ({
exec: async () => ({
_id: OWNER_ID,
role: "attendant",
status: "active",
attendantInfo: { stage: "certified", grade: "bronze", serviceAreas: ["上海市"] },
}),
}),
}),
};
},
};
await withModel("Employee", stub, async () => {
const ctx = createCtx({ body: { serviceArea: "上海市" } });
await new HandlerEmployee().updateMyServiceArea(ctx);
assert.equal(ctx.body.code, 0);
assert.deepEqual(capturedFilter, { userId: OWNER_ID, role: "attendant", status: "active" });
assert.deepEqual(capturedUpdate.$set["attendantInfo.serviceAreas"], ["上海市"]);
assert.equal(ctx.body.data.employee.attendantInfo.serviceAreas[0], "上海市");
assert.equal(ctx.body.data.employee.canAcceptOrder, true);
});
});
test("陪诊师本人修改服务城市:白名单外拒绝且不落库", async () => {
const stub = {
findOneAndUpdate: () => {
throw new Error("不应触发落库");
},
};
await withModel("Employee", stub, async () => {
const ctx = createCtx({ body: { serviceArea: "广州市" } });
await new HandlerEmployee().updateMyServiceArea(ctx);
assert.equal(ctx.body.code, 400);
assert.match(ctx.body.msg, /不在可选范围/);
});
});
test("陪诊师本人修改服务城市:非在职陪诊师返回 403", async () => {
const stub = {
findOneAndUpdate: () => ({
select: () => ({ lean: () => ({ exec: async () => null }) }),
}),
};
await withModel("Employee", stub, async () => {
const ctx = createCtx({ body: { serviceArea: "北京市" } });
await new HandlerEmployee().updateMyServiceArea(ctx);
assert.equal(ctx.body.code, 403);
assert.match(ctx.body.msg, /仅在职陪诊师/);
});
});