Files
echo/scripts/rule-smoke.mjs

114 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import assert from 'node:assert/strict'
import { transformNotificationToTransaction } from '../src/services/notificationRuleService.js'
const cases = [
{
name: 'ignore transit operation notice',
notification: {
id: 'n1',
channel: '绍兴公交',
text: '黄酒小镇专线绍兴北站出站该线路已于2025年10月17日起暂停运营',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule, undefined)
},
},
{
name: 'capture transit expense with payment context',
notification: {
id: 'n2',
channel: '绍兴公交',
text: '乘车码扣费2元绍兴北站->黄酒小镇',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'transit-card-expense')
assert.equal(result.transaction.amount, -2)
assert.equal(result.transaction.fundSourceType, 'stored_value')
assert.equal(result.transaction.impactExpense, true)
},
},
{
name: 'capture transit expense from route and fare only',
notification: {
id: 'n2b',
channel: '杭州通互联互通卡',
text: '武林广场->古荡2.10元',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'transit-card-expense')
assert.equal(result.transaction.amount, -2.1)
assert.equal(result.transaction.category, 'Transport')
assert.equal(result.transaction.fundSourceName, '杭州通互联互通卡')
},
},
{
name: 'capture stored value topup as transfer',
notification: {
id: 'n2c',
channel: '杭州通互联互通卡',
text: '充值成功20元',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'stored-value-topup')
assert.equal(result.transaction.entryType, 'transfer')
assert.equal(result.transaction.category, 'Transfer')
assert.equal(result.transaction.amount, -20)
assert.equal(result.transaction.impactExpense, false)
assert.equal(result.transaction.fundTargetName, '杭州通互联互通卡')
},
},
{
name: 'capture stored value refund as transfer',
notification: {
id: 'n2d',
channel: '杭州通互联互通卡',
text: '退款成功5元',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'stored-value-refund')
assert.equal(result.transaction.entryType, 'transfer')
assert.equal(result.transaction.amount, 5)
assert.equal(result.transaction.impactIncome, false)
assert.equal(result.transaction.fundSourceName, '杭州通互联互通卡')
},
},
{
name: 'capture bank expense',
notification: {
id: 'n3',
channel: '招商银行',
text: '您尾号1234信用卡消费支出3.23元,商户支付宝-上海拉扎斯信息科技有限公司',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'bank-expense')
assert.equal(result.transaction.amount, -3.23)
},
},
{
name: 'capture wechat income',
notification: {
id: 'n4',
channel: '微信支付',
text: '收款到账12.50元,来自张三',
createdAt: '2026-03-11T00:00:00.000Z',
},
verify(result) {
assert.equal(result.rule?.id, 'wechat-income')
assert.equal(result.transaction.amount, 12.5)
},
},
]
for (const testCase of cases) {
const result = transformNotificationToTransaction(testCase.notification)
testCase.verify(result)
}
console.log(`rule smoke passed: ${cases.length} cases`)