- 项目总群:≥3 人 appchat/create 自动建群(chatid=pgc+projectId),成员 diff 增删同步;DROP project_group_chats;推送改 appchat/send 群发、无群降级逐人 - 任务负责人:tasks.owner_userid(新建/编辑任务通讯录选人),task_set_owner 分配即预建 tgc 任务群发介绍,群主链接只归属负责人 - 任务编辑 task_update:基础字段+截图任务数量/关键词/说明,contents 调平只删 available 尾行 - 删除「一键推送」:task-one-click-push-service 整体移除(recordCardAck 移入 wecom-callback-events) - 负责人后台视角:users.wecom_userid 绑定,lib/owner-scope 行级过滤(undefined=全量/""=空范围/非空=过滤),~30 action 补 managerGate/taskOwnerGate,owner 登录仅见工作台/任务中心/数据回收/复盘报表 - 任务绑定客户群+进群活码:tasks 增 customer_chat_id/name、join_config_id、join_qr_code 4 列,join_way add/update/get/del(换绑走 update 保 config_id 活码不变),后台「客户群」弹窗,portal 认领后扫码自助进群(满员自动开新群) - 迁移 0013/0014/0015;催办支持按任务;企微可信域名 IP 验证文件 - 288 测试全绿;真机全链路验收通过(列群/活码四端点/portal 渲染/解绑清空)
109 lines
3.7 KiB
JavaScript
109 lines
3.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
isDistributionOwner,
|
|
isTaskOwner,
|
|
ownerScopeUserid,
|
|
} from "../lib/owner-scope.ts";
|
|
import { getTaskReportData } from "../lib/mvp-db.ts";
|
|
|
|
function captureDb(rowsByPattern) {
|
|
const captured = [];
|
|
const makeStatement = (sql, values) => ({
|
|
async first() {
|
|
captured.push({ sql, values });
|
|
for (const [pattern, rows] of rowsByPattern) {
|
|
if (pattern.test(sql)) return rows(values) ?? null;
|
|
}
|
|
return null;
|
|
},
|
|
async all() {
|
|
captured.push({ sql, values });
|
|
for (const [pattern, rows] of rowsByPattern) {
|
|
if (pattern.test(sql)) return { results: rows(values) ?? [] };
|
|
}
|
|
return { results: [] };
|
|
},
|
|
});
|
|
const db = {
|
|
prepare(sql) {
|
|
const unbound = makeStatement(sql, []);
|
|
return {
|
|
bind(...values) {
|
|
return makeStatement(sql, values);
|
|
},
|
|
first: unbound.first,
|
|
all: unbound.all,
|
|
};
|
|
},
|
|
};
|
|
return { db, captured };
|
|
}
|
|
|
|
test("isTaskOwner matches task owner_userid binding", async () => {
|
|
const { db, captured } = captureDb([
|
|
[
|
|
/FROM tasks WHERE id = \? AND owner_userid = \?/,
|
|
(values) =>
|
|
values[0] === "task-1" && values[1] === "zhangsan"
|
|
? { id: "task-1" }
|
|
: null,
|
|
],
|
|
]);
|
|
assert.equal(await isTaskOwner(db, "task-1", "zhangsan"), true);
|
|
assert.equal(await isTaskOwner(db, "task-2", "zhangsan"), false);
|
|
assert.equal(captured.length, 2);
|
|
});
|
|
|
|
test("isTaskOwner guards empty taskId / wecomUserId without querying", async () => {
|
|
const { db, captured } = captureDb([]);
|
|
assert.equal(await isTaskOwner(db, "task-1", ""), false);
|
|
assert.equal(await isTaskOwner(db, "", "zhangsan"), false);
|
|
assert.equal(await isTaskOwner(db, " ", "zhangsan"), false);
|
|
assert.equal(captured.length, 0);
|
|
});
|
|
|
|
test("isDistributionOwner resolves distribution → task owner", async () => {
|
|
const { db } = captureDb([
|
|
[
|
|
/FROM distributions d\s+JOIN tasks t ON t\.id = d\.task_id/,
|
|
(values) =>
|
|
values[0] === "dist-1" && values[1] === "zhangsan"
|
|
? { id: "dist-1" }
|
|
: null,
|
|
],
|
|
]);
|
|
assert.equal(await isDistributionOwner(db, "dist-1", "zhangsan"), true);
|
|
assert.equal(await isDistributionOwner(db, "dist-9", "zhangsan"), false);
|
|
assert.equal(await isDistributionOwner(db, "dist-1", ""), false);
|
|
});
|
|
|
|
test("ownerScopeUserid maps scope kinds to filter value", () => {
|
|
assert.equal(ownerScopeUserid({ kind: "full" }), undefined);
|
|
assert.equal(ownerScopeUserid({ kind: "owner", wecomUserId: "zhangsan" }), "zhangsan");
|
|
assert.equal(ownerScopeUserid({ kind: "owner", wecomUserId: "" }), "");
|
|
});
|
|
|
|
test("getTaskReportData filters by owner when ownerUserid given", async () => {
|
|
const { db, captured } = captureDb([[/FROM tasks t/, () => []]]);
|
|
await getTaskReportData(db, "zhangsan");
|
|
assert.equal(captured.length, 1);
|
|
assert.match(captured[0].sql, /WHERE t\.owner_userid = \?/);
|
|
assert.deepEqual(captured[0].values, ["zhangsan"]);
|
|
});
|
|
|
|
test("getTaskReportData keeps global aggregation without ownerUserid", async () => {
|
|
const { db, captured } = captureDb([[/FROM tasks t/, () => []]]);
|
|
await getTaskReportData(db);
|
|
assert.equal(captured.length, 1);
|
|
assert.ok(!/owner_userid = \?/.test(captured[0].sql));
|
|
assert.ok(!captured[0].values?.length);
|
|
});
|
|
|
|
test("getTaskReportData returns empty list for unbound owner (empty string scope)", async () => {
|
|
const { db, captured } = captureDb([[/FROM tasks t/, () => [{ id: "task-x" }]]]);
|
|
const rows = await getTaskReportData(db, "");
|
|
assert.deepEqual(rows, []);
|
|
assert.equal(captured.length, 0, "空范围不应执行查询(绑定 '' 会误配 owner_userid='' 的任务)");
|
|
});
|