|
|
@@ -41,6 +41,8 @@ const {
|
|
|
deleteDmsContent,
|
|
|
DMS_COLUMN_SESSION,
|
|
|
DMS_COLUMN_RECORD,
|
|
|
+ enterpriseInfo,
|
|
|
+ DMS_SESSION_CHAT_CREDIT_CODE_FIELD,
|
|
|
} = await import('./_dms.mjs');
|
|
|
|
|
|
let pass = 0;
|
|
|
@@ -90,16 +92,31 @@ const cleanup = async () => {
|
|
|
try {
|
|
|
// ── 1. 会话行 ──────────────────────────────────────────────────────
|
|
|
console.log('【1】会话(1887)');
|
|
|
- check('upsertDmsSession 新增', (await upsertDmsSession({ sessionId: SESSION_ID, title: TITLE_A, creditCode: TEST_CREDIT })) === true);
|
|
|
+ check('upsertDmsSession 新增', (await upsertDmsSession({ sessionId: SESSION_ID, sessionTitle: TITLE_A, creditCode: TEST_CREDIT })) === true);
|
|
|
let sessions = await fetchDmsSessions(TEST_CREDIT);
|
|
|
check('列表能查到', sessions.some((s) => s.session_id === SESSION_ID));
|
|
|
- check('标题正确', sessions.find((s) => s.session_id === SESSION_ID)?.title === TITLE_A);
|
|
|
check('updated_at 合理', Math.abs((sessions.find((s) => s.session_id === SESSION_ID)?.updated_at || 0) - Date.now()) < 10 * 60 * 1000);
|
|
|
|
|
|
- await upsertDmsSession({ sessionId: SESSION_ID, title: TITLE_B, creditCode: TEST_CREDIT });
|
|
|
+ // 标题规则(用户 2026-09-22):**c_title 不写**(标题由运营侧生成);
|
|
|
+ // DMS 系统字段 `title` 只在创建那一刻带上会话标题(不写会落成字符串 "null",1889 踩过)。
|
|
|
+ let rowSession = (await searchDmsContents(DMS_COLUMN_SESSION, {
|
|
|
+ search: [{ field: 'c_session_id', searchType: 1, content: { value: SESSION_ID } }],
|
|
|
+ page: 0,
|
|
|
+ pageSize: 1,
|
|
|
+ }))[0];
|
|
|
+ check('创建时带上了系统 title', rowSession?.title === TITLE_A, JSON.stringify(rowSession?.title));
|
|
|
+ check('**c_title 不写**(前端不碰标题)', !rowSession?.c_title, JSON.stringify(rowSession?.c_title));
|
|
|
+
|
|
|
+ await upsertDmsSession({ sessionId: SESSION_ID, sessionTitle: TITLE_B, creditCode: TEST_CREDIT });
|
|
|
sessions = await fetchDmsSessions(TEST_CREDIT);
|
|
|
- check('改名后只有一行', sessions.filter((s) => s.session_id === SESSION_ID).length === 1);
|
|
|
- check('标题已更新', sessions.find((s) => s.session_id === SESSION_ID)?.title === TITLE_B);
|
|
|
+ check('再次 upsert 只有一行', sessions.filter((s) => s.session_id === SESSION_ID).length === 1);
|
|
|
+ rowSession = (await searchDmsContents(DMS_COLUMN_SESSION, {
|
|
|
+ search: [{ field: 'c_session_id', searchType: 1, content: { value: SESSION_ID } }],
|
|
|
+ page: 0,
|
|
|
+ pageSize: 1,
|
|
|
+ }))[0];
|
|
|
+ check('**再 upsert 也不写 c_title**', !rowSession?.c_title, JSON.stringify(rowSession?.c_title));
|
|
|
+ check('系统 title 保持创建时的值(只在创建那一刻初始化)', rowSession?.title === TITLE_A, JSON.stringify(rowSession?.title));
|
|
|
|
|
|
// ── 2. 粒度:一问一答一条 ──────────────────────────────────────────
|
|
|
console.log('\n【2】问答记录(1889)—— 粒度必须是「一问一答一条」');
|
|
|
@@ -167,6 +184,89 @@ try {
|
|
|
check('parseDmsTimestamp 秒', parseDmsTimestamp(1789651800) === 1789651800000);
|
|
|
check('parseDmsTimestamp 字符串', parseDmsTimestamp('2026-09-17 21:30:00') === 1789651800000, String(parseDmsTimestamp('2026-09-17 21:30:00')));
|
|
|
check('访客归属形态 访客_<id>', /^访客_.+/.test(resolveDmsCreditCode()), resolveDmsCreditCode());
|
|
|
+
|
|
|
+ // ── 8. 1887 的企业字段(2026-09-22 用户要求)──────────────────────
|
|
|
+ // 规则:登录态的值优先级最高(覆盖);对话带出的 company_info **只填空**(未登录不修改);
|
|
|
+ // 归属键 c_credit_code 不变(公司代码另存 c_chat_credit_code 一列)。
|
|
|
+ console.log('\n【8】1887 企业字段(名称 / 公司代码 / 图片 / 是否登录)');
|
|
|
+ const SID8 = `verify_ent_${Date.now().toString(36)}`;
|
|
|
+ const sessionRowOf = async (sid) =>
|
|
|
+ (
|
|
|
+ await searchDmsContents(DMS_COLUMN_SESSION, {
|
|
|
+ search: [{ field: 'c_session_id', searchType: 1, content: { value: sid } }],
|
|
|
+ page: 0,
|
|
|
+ pageSize: 1,
|
|
|
+ })
|
|
|
+ )[0];
|
|
|
+ const COMPANY_A = {
|
|
|
+ profile: { data: { Name: '甲测试公司', CreditCode: '91310000AAAAAAAAAA', ImageUrl: 'https://example.com/a.png' } },
|
|
|
+ };
|
|
|
+ const COMPANY_B = {
|
|
|
+ profile: { data: { Name: '乙测试公司', CreditCode: '91310000BBBBBBBBBB', ImageUrl: 'https://example.com/b.png' } },
|
|
|
+ };
|
|
|
+
|
|
|
+ // 8.1 未登录 + company_info → 填进 1887
|
|
|
+ enterpriseInfo.value = null;
|
|
|
+ await upsertDmsSession({ sessionId: SID8, sessionTitle: '企业字段验证', companyInfo: COMPANY_A });
|
|
|
+ let entRow = await sessionRowOf(SID8);
|
|
|
+ check('未登录:企业名称已填', entRow?.c_ent_name === '甲测试公司', JSON.stringify(entRow?.c_ent_name));
|
|
|
+ // ⚠️ `c_chat_credit_code`(公司代码另存的那一列)需要 **DMS 侧先加列**(模型 2034)。
|
|
|
+ // 加好之前写它会被 DMS 静默忽略(未知字段不报错),所以这里按「列存不存在」分别断言:
|
|
|
+ // 不存在就打印 ⏭ 跳过,不当作失败 —— 前端已经照发,加列后自然生效。
|
|
|
+ const hasChatCreditColumn = entRow
|
|
|
+ ? Object.prototype.hasOwnProperty.call(entRow, DMS_SESSION_CHAT_CREDIT_CODE_FIELD)
|
|
|
+ : false;
|
|
|
+ if (!hasChatCreditColumn) {
|
|
|
+ console.log(` ⏭ 列 ${DMS_SESSION_CHAT_CREDIT_CODE_FIELD} 在 DMS 模型里还不存在 →`);
|
|
|
+ console.log(' 前端开关 DMS_SESSION_CHAT_CREDIT_CODE_ENABLED 仍为 false(**故意**):');
|
|
|
+ console.log(' 实测 updateContent 只要含一个不存在的列,整个 patch 会被静默丢弃,');
|
|
|
+ console.log(' 连企业名称/登录态都写不进去 —— 所以先不发它。加列后把开关改 true 即可。');
|
|
|
+ }
|
|
|
+ if (hasChatCreditColumn) {
|
|
|
+ check(
|
|
|
+ `未登录:公司代码写进 ${DMS_SESSION_CHAT_CREDIT_CODE_FIELD}`,
|
|
|
+ entRow[DMS_SESSION_CHAT_CREDIT_CODE_FIELD] === '91310000AAAAAAAAAA',
|
|
|
+ JSON.stringify(entRow[DMS_SESSION_CHAT_CREDIT_CODE_FIELD])
|
|
|
+ );
|
|
|
+ }
|
|
|
+ check('未登录:企业图片已填', entRow?.c_ent_image_url === 'https://example.com/a.png', JSON.stringify(entRow?.c_ent_image_url));
|
|
|
+ check('未登录:是否登录 = "0"', entRow?.c_is_login === '0', JSON.stringify(entRow?.c_is_login));
|
|
|
+ check('归属键仍是 访客_<id>(没被公司代码顶掉)', /^访客_/.test(String(entRow?.c_credit_code)), JSON.stringify(entRow?.c_credit_code));
|
|
|
+
|
|
|
+ // 8.2 未登录再来一轮、带的是**另一家**公司 → 已有值不动(「未登录则不修改」)
|
|
|
+ await upsertDmsSession({ sessionId: SID8, companyInfo: COMPANY_B });
|
|
|
+ entRow = await sessionRowOf(SID8);
|
|
|
+ check('未登录:第二轮**不改**已填的名称', entRow?.c_ent_name === '甲测试公司', JSON.stringify(entRow?.c_ent_name));
|
|
|
+ if (hasChatCreditColumn) {
|
|
|
+ check(
|
|
|
+ '未登录:第二轮也不改公司代码',
|
|
|
+ entRow?.[DMS_SESSION_CHAT_CREDIT_CODE_FIELD] === '91310000AAAAAAAAAA',
|
|
|
+ JSON.stringify(entRow?.[DMS_SESSION_CHAT_CREDIT_CODE_FIELD])
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 8.3 登录 → 登录态的值优先级最高,**覆盖**库里已有的
|
|
|
+ enterpriseInfo.value = { credit_code: '91310000LOGIN000001', name: '登录态公司' };
|
|
|
+ await upsertDmsSession({ sessionId: SID8, companyInfo: COMPANY_B });
|
|
|
+ entRow = await sessionRowOf(SID8);
|
|
|
+ check('登录:企业名称被登录值**覆盖**', entRow?.c_ent_name === '登录态公司', JSON.stringify(entRow?.c_ent_name));
|
|
|
+ check('登录:归属键被登录值**覆盖**', entRow?.c_credit_code === '91310000LOGIN000001', JSON.stringify(entRow?.c_credit_code));
|
|
|
+ check('登录:是否登录 = "1"', entRow?.c_is_login === '1', JSON.stringify(entRow?.c_is_login));
|
|
|
+ if (hasChatCreditColumn) {
|
|
|
+ check(
|
|
|
+ '登录:对话带出的公司代码**不会**顶掉登录归属(另存一列)',
|
|
|
+ entRow?.[DMS_SESSION_CHAT_CREDIT_CODE_FIELD] === '91310000AAAAAAAAAA',
|
|
|
+ JSON.stringify(entRow?.[DMS_SESSION_CHAT_CREDIT_CODE_FIELD])
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 8.4 退出登录后再写 → 登录值**不被**访客值改回去
|
|
|
+ enterpriseInfo.value = null;
|
|
|
+ await upsertDmsSession({ sessionId: SID8, companyInfo: COMPANY_B });
|
|
|
+ entRow = await sessionRowOf(SID8);
|
|
|
+ check('退出后:企业名称保持登录值', entRow?.c_ent_name === '登录态公司', JSON.stringify(entRow?.c_ent_name));
|
|
|
+ check('退出后:是否登录不被改回 "0"', entRow?.c_is_login === '1', JSON.stringify(entRow?.c_is_login));
|
|
|
+ await deleteDmsSession(SID8);
|
|
|
} finally {
|
|
|
console.log('\n【清理】');
|
|
|
await cleanup();
|
|
|
@@ -189,7 +289,7 @@ console.log('\n【7】title 字段');
|
|
|
pageSize: 1,
|
|
|
}))[0];
|
|
|
|
|
|
- await upsertDmsSession({ sessionId: SID2, title: '标题甲', creditCode: TEST_CREDIT });
|
|
|
+ await upsertDmsSession({ sessionId: SID2, sessionTitle: '标题甲', creditCode: TEST_CREDIT });
|
|
|
let row = await rowOf(DMS_COLUMN_SESSION, 'c_session_id', SID2);
|
|
|
check('新建会话带上了系统 title', row?.title === '标题甲', JSON.stringify(row?.title));
|
|
|
// 四个必填运营字段(summary/qpyszx/qyzt/rzqpyx)**故意传空值/默认值**:
|
|
|
@@ -199,10 +299,10 @@ console.log('\n【7】title 字段');
|
|
|
check('三个布尔运营字段为默认 false', row?.qpyszx === false && row?.qyzt === false && row?.rzqpyx === false,
|
|
|
JSON.stringify([row?.qpyszx, row?.qyzt, row?.rzqpyx]));
|
|
|
|
|
|
- await upsertDmsSession({ sessionId: SID2, title: '标题乙', creditCode: TEST_CREDIT });
|
|
|
+ await upsertDmsSession({ sessionId: SID2, sessionTitle: '标题乙', creditCode: TEST_CREDIT });
|
|
|
row = await rowOf(DMS_COLUMN_SESSION, 'c_session_id', SID2);
|
|
|
- check('改名后 c_title 已更新', row?.c_title === '标题乙', JSON.stringify(row?.c_title));
|
|
|
- check('**改名后系统 title 也跟着变**(原先不跟随)', row?.title === '标题乙', JSON.stringify(row?.title));
|
|
|
+ check('再 upsert 仍不写 c_title', !row?.c_title, JSON.stringify(row?.c_title));
|
|
|
+ check('系统 title 保持创建时的值', row?.title === '标题甲', JSON.stringify(row?.title));
|
|
|
|
|
|
await upsertDmsRecord({ recordId: REC3, sessionId: SID2, creditCode: TEST_CREDIT, question: '记录的问题文本' });
|
|
|
const recRow = await rowOf(DMS_COLUMN_RECORD, 'c_record_id', REC3);
|