fix(微信订阅): 用微信真实关键词修正歌曲排期模板(thing1/phrase2/time3/character_string4),并修掉字段认领顺序导致的校准失效

This commit is contained in:
2026-10-24 11:56:50 +08:00
parent dc2565da34
commit f5a43b37cc
7 changed files with 192 additions and 56 deletions
+18 -13
View File
@@ -30,12 +30,18 @@ test('内置模板:两个模板的 ID 与字段映射和公众平台一致', (
const selected = BUILTIN_TEMPLATES.SONG_SELECTED
assert.equal(selected.id, 'oLTAefO92xYYlGRYmcsm5AfUUlUI5IKFfXhIVNrItSk')
/*
* 这四个键是微信侧真实分配的编号(模板原文:
* 歌曲名称:{{thing1.DATA}} 排期状态:{{phrase2.DATA}}
* 播放时间:{{time3.DATA}} 排期序号:{{character_string4.DATA}}
* )。这张模板没有日期关键词 —— 曾经在这里写过一个不存在的 date4,
* 微信就回 `47003 data.thing1.value is empty`。
*/
assert.deepEqual(selected.fields, {
thing2: 'songTitle',
date4: 'playDate',
time1: 'playTime',
character_string3: 'sequence',
phrase5: 'status'
thing1: 'songTitle',
phrase2: 'status',
time3: 'playTime',
character_string4: 'sequence'
})
// 每个字段名都要带类型后缀(thing2/date4/…),否则 clampField 认不出类型、不会裁剪
@@ -139,17 +145,16 @@ test('findEmptyFields:变量没给或全是空白 → 点名到字段和变量
findEmptyFields(conf, {})
.map((f) => f.field)
.sort(),
['character_string3', 'date4', 'phrase5', 'thing2', 'time1']
['character_string4', 'phrase2', 'thing1', 'time3']
)
const partial = findEmptyFields(conf, {
songTitle: '晴天',
playDate: ' ',
playTime: '2026-02-14 12:30',
playTime: ' ',
sequence: '1',
status: '已排期'
})
assert.deepEqual(partial, [{ field: 'date4', variable: 'playDate' }])
assert.deepEqual(partial, [{ field: 'time3', variable: 'playTime' }])
})
test('findEmptyDataFields:拼完 data 再兜一层空值检查', () => {
@@ -173,10 +178,10 @@ test('buildTemplateData:按映射取值,并交给 clamp 处理(time 有兜
},
clampField
)
assert.deepEqual(Object.keys(data), ['thing2', 'date4', 'time1', 'character_string3', 'phrase5'])
assert.equal(data.thing2.value, '晴天')
assert.equal(data.character_string3.value, '3')
assert.equal(data.phrase5.value, '已排期')
assert.deepEqual(Object.keys(data), ['thing1', 'phrase2', 'time3', 'character_string4'])
assert.equal(data.thing1.value, '晴天')
assert.equal(data.character_string4.value, '3')
assert.equal(data.phrase2.value, '已排期')
assert.deepEqual(findEmptyDataFields(data), [], '有完整变量时不该出现空字段')
})