chore: initial commit of HouseholdBudgetBook (backend, frontend, desktop)

This commit is contained in:
mapleferry committed 2026-11-29 21:29:06 +08:00
commit 4a5db3f1f9
167 files changed
+21732

No files matched your search

@@ -0,0 +1,78 @@
package service
import (
"os"
"path/filepath"
"testing"
"household-book/model"
)
func TestParseDebitStatementPDF(t *testing.T) {
content := readExamplePDF(t, "招商银行交易流水(申请时间2026年04月12日16时46分05秒).pdf")
req := model.ImportTransactionsRequest{
Filename: "招商银行交易流水(申请时间2026年04月12日16时46分05秒).pdf",
Content: content,
BankName: "招商银行",
CardType: "debit_card",
}
text := extractPDFText(content)
items := parseImportTransactions(text, req)
items = mergeCreditRawAmounts(items, parseCreditRawAmounts(extractPDFRawText(content), req, text))
if len(items) < 100 {
t.Fatalf("expected many debit statement items, got %d", len(items))
}
if items[0].Date != "2025-04-10" || items[0].Type != "income" || items[0].Amount != 2016372 {
t.Fatalf("unexpected first debit item: %+v", items[0])
}
foundFeb20 := false
foundApr10 := false
for _, item := range items {
if item.Date == "2026-04-10" && item.Amount == 1230000 {
foundApr10 = true
if item.Description != "转账汇款张聚锁" || item.Counterparty != "张聚锁" {
t.Fatalf("unexpected 2026-04-10 item: %+v", item)
}
}
if item.Date == "2026-02-20" && item.Amount == 150000 {
foundFeb20 = true
if item.Description != "银联快捷支付微信转账" || item.Counterparty != "微信转账" {
t.Fatalf("unexpected 2026-02-20 item: %+v", item)
}
}
}
if !foundApr10 || !foundFeb20 {
t.Fatalf("expected target debit items, foundApr10=%v foundFeb20=%v", foundApr10, foundFeb20)
}
}
func TestParseCreditCardStatementPDF(t *testing.T) {
content := readExamplePDF(t, "2025年10月信用卡账单.pdf")
req := model.ImportTransactionsRequest{
Filename: "2025年10月信用卡账单.pdf",
Content: content,
BankName: "招商银行",
CardType: "credit_card",
}
items := parseImportTransactions(extractPDFText(content), req)
if len(items) < 10 {
t.Fatalf("expected credit card bill items, got %d", len(items))
}
for _, item := range items {
if item.Type != "expense" || item.Date != "2025-10-01" || item.Amount <= 0 {
t.Fatalf("unexpected credit card item: %+v", item)
}
}
}
func readExamplePDF(t *testing.T, name string) []byte {
t.Helper()
path := filepath.Join("..", "..", "docs", name)
content, err := os.ReadFile(path)
if err != nil {
t.Skipf("example PDF not available: %v", err)
}
return content
}