1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-11-01 00:10:06 -04:00

testing: Add test for fetching transactions/splits

This commit is contained in:
Aaron Lindsay 2017-10-17 21:28:06 -04:00
parent cdba839c66
commit 2c85975e92

View File

@ -53,6 +53,86 @@ func TestCreateTransaction(t *testing.T) {
if transaction.Date != orig.Date { if transaction.Date != orig.Date {
t.Errorf("Date doesn't match") t.Errorf("Date doesn't match")
} }
if len(transaction.Splits) != len(orig.Splits) {
t.Fatalf("Expected %d splits, received %d", len(orig.Splits), len(transaction.Splits))
}
foundIds := make(map[int64]bool)
for j := 0; j < len(orig.Splits); j++ {
origsplit := orig.Splits[j]
if transaction.Splits[j].TransactionId != transaction.TransactionId {
t.Fatalf("Split TransactionId doesn't match transaction's")
}
found := false
for _, s := range transaction.Splits {
if origsplit.Status == s.Status && origsplit.ImportSplitType == s.ImportSplitType && s.AccountId == d.accounts[origsplit.AccountId].AccountId && s.SecurityId == -1 && origsplit.RemoteId == origsplit.RemoteId && origsplit.Number == s.Number && origsplit.Memo == s.Memo && origsplit.Amount == s.Amount {
if _, ok := foundIds[s.SplitId]; ok {
continue
}
foundIds[s.SplitId] = true
found = true
break
}
}
if !found {
t.Errorf("Unable to find matching split: %+v", origsplit)
}
}
}
})
}
func TestGetTransaction(t *testing.T) {
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
for i := 0; i < len(data[0].transactions); i++ {
orig := data[0].transactions[i]
curr := d.transactions[i]
tran, err := getTransaction(d.clients[orig.UserId], curr.TransactionId)
if err != nil {
t.Fatalf("Error fetching transaction: %s\n", err)
}
if tran.TransactionId != curr.TransactionId {
t.Errorf("TransactionId doesn't match")
}
if tran.Description != orig.Description {
t.Errorf("Description doesn't match")
}
if tran.Date != orig.Date {
t.Errorf("Date doesn't match")
}
if len(tran.Splits) != len(orig.Splits) {
t.Fatalf("Expected %d splits, received %d", len(orig.Splits), len(tran.Splits))
}
foundIds := make(map[int64]bool)
for j := 0; j < len(orig.Splits); j++ {
origsplit := orig.Splits[j]
currsplit := curr.Splits[j]
if tran.Splits[j].TransactionId != tran.TransactionId {
t.Fatalf("Split TransactionId doesn't match transaction's")
}
found := false
for _, s := range tran.Splits {
if origsplit.Status == s.Status && origsplit.ImportSplitType == s.ImportSplitType && currsplit.AccountId == s.AccountId && currsplit.SecurityId == s.SecurityId && origsplit.RemoteId == origsplit.RemoteId && origsplit.Number == s.Number && origsplit.Memo == s.Memo && origsplit.Amount == s.Amount {
if _, ok := foundIds[s.SplitId]; ok {
continue
}
foundIds[s.SplitId] = true
found = true
break
}
}
if !found {
t.Errorf("Unable to find matching split: %+v", curr)
}
}
} }
}) })
} }