fix(growth): 修复游客资料承接与活动时区
- 资料承接:填补新账号缺失字段,保留已有称呼和显式空身份 - 站内活动:按北京时间比较日程,避免数据库时区造成八小时偏移 - 回归:补充薄资料账号及真实UTC数据库活动窗口验证
This commit is contained in:
@@ -578,3 +578,70 @@ test("服务端事件幂等键按故事隔离,游客承接不改变同一故
|
||||
assert.equal(ids[2], ids[3]);
|
||||
assert.equal(ids[0].length, 64);
|
||||
});
|
||||
|
||||
test("游客资料只填补新账号缺失字段,保留既有称呼和显式空身份", async (t) => {
|
||||
const { mergeGuest } = await import(
|
||||
"../src/modules/digital/growth/growth.repository"
|
||||
);
|
||||
for (const target of [
|
||||
{ nsfwEnabled: false },
|
||||
{ nsfwEnabled: false, userName: "既有称呼", persona: "" },
|
||||
]) {
|
||||
let patch: Record<string, unknown> | undefined;
|
||||
const query = async (q: { sql: string }, args: unknown[]) => {
|
||||
if (q.sql.startsWith("SELECT * FROM dh_growth_identities"))
|
||||
return [
|
||||
[
|
||||
args[0] === "guest:fixture"
|
||||
? { merged_into: null, subject: "guest:fixture" }
|
||||
: { subject: "user:7" },
|
||||
],
|
||||
[],
|
||||
];
|
||||
if (
|
||||
q.sql.startsWith("SELECT request_id") ||
|
||||
q.sql.startsWith("SELECT id FROM dh_conversations")
|
||||
)
|
||||
return [[], []];
|
||||
if (q.sql.startsWith("SELECT account,body FROM dh_profiles"))
|
||||
return [
|
||||
[
|
||||
{
|
||||
account: "guest:fixture",
|
||||
body: {
|
||||
userName: "游客称呼",
|
||||
persona: "游客身份",
|
||||
favorites: ["role"],
|
||||
nsfwEnabled: false,
|
||||
},
|
||||
},
|
||||
{ account: "user:7", body: target },
|
||||
],
|
||||
[],
|
||||
];
|
||||
if (q.sql.startsWith("SELECT DATE_FORMAT"))
|
||||
return [[{ day: "2026-10-28" }], []];
|
||||
if (q.sql.startsWith("SELECT used FROM")) return [[{ used: 1 }], []];
|
||||
if (q.sql.startsWith("INSERT INTO dh_profiles"))
|
||||
patch = JSON.parse(String(args[1]));
|
||||
return [{ affectedRows: 1 }, []];
|
||||
};
|
||||
t.mock.method(pool, "getConnection", async () => ({
|
||||
query,
|
||||
beginTransaction: async () => {},
|
||||
commit: async () => {},
|
||||
rollback: async () => {},
|
||||
release: () => {},
|
||||
}));
|
||||
await mergeGuest("guest:fixture", "user:7");
|
||||
assert.ok(patch);
|
||||
assert.equal(patch.nsfwEnabled, undefined);
|
||||
if ("userName" in target) {
|
||||
assert.equal(patch.userName, undefined);
|
||||
assert.equal(patch.persona, undefined);
|
||||
} else {
|
||||
assert.equal(patch.userName, "游客称呼");
|
||||
assert.equal(patch.persona, "游客身份");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user