76 lines
1.3 KiB
Go
76 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"local/storage"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func TestUploadLedger(t *testing.T) {
|
|
cases := map[string]struct {
|
|
transaction Transaction
|
|
}{
|
|
"simple": {
|
|
transaction: Transaction{
|
|
ID: uuid.New().String(),
|
|
Bank: Chase,
|
|
Amount: "1.10",
|
|
Vendor: "my's totally realistic!!! VENDOR 11",
|
|
Date: "today",
|
|
},
|
|
},
|
|
}
|
|
|
|
for name, d := range cases {
|
|
c := d
|
|
t.Run(name, func(t *testing.T) {
|
|
config := Config{
|
|
TodoAddr: path.Join(t.TempDir(), name),
|
|
Uploader: UploaderLedger,
|
|
Storage: storage.NewMap(),
|
|
}
|
|
if err := uploadLedger(config, &c.transaction); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := ioutil.ReadFile(config.TodoAddr)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Contains(b, []byte("mystotallyrealisticVENDOR11")) {
|
|
t.Fatal(string(b))
|
|
}
|
|
t.Logf("\n%s", b)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFormatGMailDate(t *testing.T) {
|
|
cases := map[string]struct {
|
|
input string
|
|
want string
|
|
}{
|
|
"ok": {
|
|
input: "[Tue, 20 Jul 2021 23:46:00 -0400 (EDT)]",
|
|
want: "2021-07-20",
|
|
},
|
|
"bad": {
|
|
input: "2021-07-20",
|
|
want: "2021-07-20",
|
|
},
|
|
}
|
|
|
|
for name, d := range cases {
|
|
c := d
|
|
t.Run(name, func(t *testing.T) {
|
|
got := formatGMailDate(c.input)
|
|
if got != c.want {
|
|
t.Fatal(c.input, c.want, got)
|
|
}
|
|
})
|
|
}
|
|
}
|