Skip to content

Commit

Permalink
✨ (rule): 新增掌上生活消费通知规则及测试用例 #634
Browse files Browse the repository at this point in the history
新增掌上生活消费通知的规则处理逻辑,包括解析消费信息、生成账单对象等功能。同时添加了相应的测试用例,确保规则的正确性和稳定性。
  • Loading branch information
AnkioTomas committed Dec 27, 2024
1 parent 349f1f3 commit 60dbd74
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { BillType, RuleObject, splitShop, toFloat } from 'common/index.js';

export function get (data) {
let json = JSON.parse(data);
// 信用卡通知:您尾号1356的招行信用卡消费6225.34人民币。
// 信用卡通知:您尾号1356的招行信用卡预授权1,362.41人民币。
// 您在美团支付-美团App酱新香酥鸡饼(鸡柳拌饼益有一笔29.96人民币的消费已成功,点击查看详情【消费达标集喵赢好礼,限特邀用户,戳此>>】
let regex = /您在(.*?)有一笔(.*?)人民币的消费已成功,点击查看详情/;
const match = json.text.match(regex);
if (!match) {
return null;
}

let obj = new RuleObject();

let [, shopItem_, money] = match;
let { shopName, shopItem } = splitShop(shopItem_);
obj.money = toFloat(money);
obj.channel = `掌上生活[信用卡消费]`;
obj.shopName = shopName;
obj.shopItem = shopItem;
obj.time = json.t;
obj.type = BillType.Expend;

obj.accountNameFrom = `招商银行信用卡`;
return obj;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { get } = require('./main');
const { testAnkio, testAnkioInit } = require('../../../../tests/TestUtils');
const { formatDate } = require('common/Time.js');

testAnkioInit(get, __dirname, 'cmb.pb');
test('掌上生活消费通知', () =>
testAnkio('掌上生活消费通知', [
{
'type': 'Expend',
'money': 29.96,
'fee': 0,
'shopName': '美团支付',
'shopItem': '美团App酱新香酥鸡饼(鸡柳拌饼益',
'accountNameFrom': '招商银行信用卡',
'accountNameTo': '',
'currency': 'CNY',
'time': 1735045607824,
'channel': '掌上生活[信用卡消费]'
}
]));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "交易提醒",
"text": "您在美团支付-美团App酱新香酥鸡饼(鸡柳拌饼益有一笔29.96人民币的消费已成功,点击查看详情【消费达标集喵赢好礼,限特邀用户,戳此>>】",
"t": 1735045607824
}

0 comments on commit 60dbd74

Please sign in to comment.