chore: initial commit of HouseholdBudgetBook (backend, frontend, desktop)
This commit is contained in:
commit
4a5db3f1f9
167 files changed
+21732
No files matched your search
@@ -0,0 +1,80 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"household-book/model"
|
||||
)
|
||||
|
||||
func TestParseAlipayCSV(t *testing.T) {
|
||||
content := readExampleFile(t, "alipay_record_20250723_2030_1.csv")
|
||||
req := model.ImportTransactionsRequest{
|
||||
Filename: "alipay_record_20250723_2030_1.csv",
|
||||
Content: content,
|
||||
SourceKind: "alipay",
|
||||
BankName: "支付宝",
|
||||
CardType: "alipay",
|
||||
}
|
||||
items, err := parseAlipayCSV(req)
|
||||
if err != nil {
|
||||
t.Fatalf("parse alipay: %v", err)
|
||||
}
|
||||
if len(items) < 50 {
|
||||
t.Fatalf("expected many alipay items, got %d", len(items))
|
||||
}
|
||||
|
||||
// 抽样校验:第一行是 2025-05-31 张红旗饸饹面 29.7 支出
|
||||
first := items[0]
|
||||
if first.Date != "2025-05-31" || first.Type != "expense" || first.Amount != 2970 {
|
||||
t.Fatalf("unexpected first alipay item: %+v", first)
|
||||
}
|
||||
if first.Counterparty != "张红旗饸饹面" {
|
||||
t.Fatalf("unexpected counterparty: %q", first.Counterparty)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseWechatCSV(t *testing.T) {
|
||||
content := readExampleFile(t, "微信支付账单(20241001-20250101).csv")
|
||||
req := model.ImportTransactionsRequest{
|
||||
Filename: "微信支付账单(20241001-20250101).csv",
|
||||
Content: content,
|
||||
SourceKind: "wechat",
|
||||
BankName: "微信",
|
||||
CardType: "wechat",
|
||||
}
|
||||
items, err := parseWechatCSV(req)
|
||||
if err != nil {
|
||||
t.Fatalf("parse wechat: %v", err)
|
||||
}
|
||||
if len(items) < 5 {
|
||||
t.Fatalf("expected wechat items, got %d", len(items))
|
||||
}
|
||||
|
||||
var foundExpense, foundIncome bool
|
||||
for _, item := range items {
|
||||
if item.Type == "expense" && item.Date == "2024-12-26" && item.Amount == 13700 && item.Counterparty == "我心依然" {
|
||||
foundExpense = true
|
||||
}
|
||||
if item.Type == "income" && item.Date == "2024-12-20" && item.Amount == 1800 && item.Counterparty == "范军" {
|
||||
foundIncome = true
|
||||
}
|
||||
}
|
||||
if !foundExpense {
|
||||
t.Fatalf("expected wechat expense 我心依然 137.00 not found")
|
||||
}
|
||||
if !foundIncome {
|
||||
t.Fatalf("expected wechat income 范军 18.00 not found")
|
||||
}
|
||||
}
|
||||
|
||||
func readExampleFile(t *testing.T, name string) []byte {
|
||||
t.Helper()
|
||||
path := filepath.Join("..", "..", "docs", name)
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Skipf("example file not available: %v", err)
|
||||
}
|
||||
return content
|
||||
}
|
||||
Reference in new issue
Block a user