package main import ( "bytes" "io/ioutil" "net/mail" "testing" ) func TestScrapeChase2021Payment(t *testing.T) { b, err := ioutil.ReadFile("./testdata/chase.2021.payment.txt") if err != nil { t.Fatal(err) } message := &mail.Message{ Header: map[string][]string{ "Subject": []string{"We've received your AARP from Chase payment"}, }, Body: bytes.NewReader(b), } chase := &chaseScraper{} gots, err := chase.scrape2021(message) if err != nil { t.Fatal(err) } if len(gots) != 1 { t.Fatal(gots) } got := gots[0] if got.Account != "8824" { t.Fatalf("bad account: %v: %+v", got.Account, got) } if got.Amount != "100.00" { t.Fatalf("bad amount: %v: %+v", got.Amount, got) } if got.Vendor != "Payment" { t.Fatalf("bad vendor: %v: %+v", got.Vendor, got) } t.Logf("%+v", got) } func TestScrapeChase2021(t *testing.T) { b, err := ioutil.ReadFile("./testdata/chase.2021.txt") if err != nil { t.Fatal(err) } message := &mail.Message{ Header: map[string][]string{ "Subject": []string{"Your $38.84 transaction with TARGET T-1754"}, }, Body: bytes.NewReader(b), } chase := &chaseScraper{} gots, err := chase.scrape2021(message) if err != nil { t.Fatal(err) } if len(gots) != 1 { t.Fatal(gots) } got := gots[0] if got.Account != "8824" { t.Fatalf("bad account: %v: %+v", got.Account, got) } if got.Amount != "38.84" { t.Fatalf("bad amount: %v: %+v", got.Amount, got) } if got.Vendor != "TARGET T-1754" { t.Fatalf("bad vendor: %v: %+v", got.Vendor, got) } t.Logf("%+v", got) } func TestScrapeChase2020(t *testing.T) { b, err := ioutil.ReadFile("./testdata/chase.2020.txt") if err != nil { t.Fatal(err) } message := &mail.Message{ Body: bytes.NewReader(b), } chase := &chaseScraper{} gots, err := chase.scrape2020(message) if err != nil { t.Fatal(err) } if len(gots) != 1 { t.Fatal(gots) } got := gots[0] if got.Account != "8824" { t.Fatalf("bad account: %v: %+v", got.Account, got) } if got.Amount != "16.08" { t.Fatalf("bad amount: %v: %+v", got.Amount, got) } if got.Vendor != "PAYPAL *BLIZZARDENT" { t.Fatalf("bad vendor: %q: %+v", got.Vendor, got) } t.Logf("%+v", got) } func TestScrapeBofACharge(t *testing.T) { b, err := ioutil.ReadFile("./testdata/bofa.charge.txt") if err != nil { t.Fatal(err) } message := &mail.Message{ Header: map[string][]string{ "Subject": []string{"Credit card transaction exceeds alert limit you set"}, }, Body: bytes.NewReader(b), } bofa := &bankOfAmericaScraper{} gots, err := bofa.scrape(message) if err != nil { t.Fatal(err) } if len(gots) != 1 { t.Fatal(len(gots)) } got := gots[0] want := Transaction{ ID: got.ID, Bank: BankOfAmerica, Amount: "75.08", Vendor: "PAYPAL GIBBDOGENTE MA", Date: "[]", Account: BankOfAmerica.String(), } if *got != want { t.Fatalf("want:\n\t%+v, got\n\t%+v", want, *got) } }