mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 07:33:21 -05:00
testing: Check more post-gnucash import account balances
This commit is contained in:
parent
d65019f55c
commit
947db54433
@ -54,6 +54,18 @@ func importGnucash(client *http.Client, filename string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func gnucashAccountBalanceHelper(t *testing.T, client *http.Client, account *handlers.Account, balance string) {
|
||||||
|
t.Helper()
|
||||||
|
transactions, err := getAccountTransactions(client, account.AccountId, 0, 0, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Couldn't fetch account transactions for '%s': %s\n", account.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if transactions.EndingBalance != balance {
|
||||||
|
t.Errorf("Expected ending balance for '%s' to be '%s', but found %s\n", account.Name, balance, transactions.EndingBalance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestImportGnucash(t *testing.T) {
|
func TestImportGnucash(t *testing.T) {
|
||||||
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
|
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
|
||||||
// Ensure there's only one USD currency
|
// Ensure there's only one USD currency
|
||||||
@ -75,7 +87,7 @@ func TestImportGnucash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Next, find the Expenses/Groceries account and verify it's balance
|
// Next, find the Expenses/Groceries account and verify it's balance
|
||||||
var income, liabilities, expenses, salary, creditcard, groceries *handlers.Account
|
var income, equity, liabilities, expenses, salary, creditcard, groceries, cable, openingbalances *handlers.Account
|
||||||
accounts, err := getAccounts(d.clients[0])
|
accounts, err := getAccounts(d.clients[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error fetching accounts: %s\n", err)
|
t.Fatalf("Error fetching accounts: %s\n", err)
|
||||||
@ -83,6 +95,8 @@ func TestImportGnucash(t *testing.T) {
|
|||||||
for i, account := range *accounts.Accounts {
|
for i, account := range *accounts.Accounts {
|
||||||
if account.Name == "Income" && account.Type == handlers.Income && account.ParentAccountId == -1 {
|
if account.Name == "Income" && account.Type == handlers.Income && account.ParentAccountId == -1 {
|
||||||
income = &(*accounts.Accounts)[i]
|
income = &(*accounts.Accounts)[i]
|
||||||
|
} else if account.Name == "Equity" && account.Type == handlers.Equity && account.ParentAccountId == -1 {
|
||||||
|
equity = &(*accounts.Accounts)[i]
|
||||||
} else if account.Name == "Liabilities" && account.Type == handlers.Liability && account.ParentAccountId == -1 {
|
} else if account.Name == "Liabilities" && account.Type == handlers.Liability && account.ParentAccountId == -1 {
|
||||||
liabilities = &(*accounts.Accounts)[i]
|
liabilities = &(*accounts.Accounts)[i]
|
||||||
} else if account.Name == "Expenses" && account.Type == handlers.Expense && account.ParentAccountId == -1 {
|
} else if account.Name == "Expenses" && account.Type == handlers.Expense && account.ParentAccountId == -1 {
|
||||||
@ -92,6 +106,9 @@ func TestImportGnucash(t *testing.T) {
|
|||||||
if income == nil {
|
if income == nil {
|
||||||
t.Fatalf("Couldn't find 'Income' account")
|
t.Fatalf("Couldn't find 'Income' account")
|
||||||
}
|
}
|
||||||
|
if equity == nil {
|
||||||
|
t.Fatalf("Couldn't find 'Equity' account")
|
||||||
|
}
|
||||||
if liabilities == nil {
|
if liabilities == nil {
|
||||||
t.Fatalf("Couldn't find 'Liabilities' account")
|
t.Fatalf("Couldn't find 'Liabilities' account")
|
||||||
}
|
}
|
||||||
@ -101,30 +118,36 @@ func TestImportGnucash(t *testing.T) {
|
|||||||
for i, account := range *accounts.Accounts {
|
for i, account := range *accounts.Accounts {
|
||||||
if account.Name == "Salary" && account.Type == handlers.Income && account.ParentAccountId == income.AccountId {
|
if account.Name == "Salary" && account.Type == handlers.Income && account.ParentAccountId == income.AccountId {
|
||||||
salary = &(*accounts.Accounts)[i]
|
salary = &(*accounts.Accounts)[i]
|
||||||
|
} else if account.Name == "Opening Balances" && account.Type == handlers.Equity && account.ParentAccountId == equity.AccountId {
|
||||||
|
openingbalances = &(*accounts.Accounts)[i]
|
||||||
} else if account.Name == "Credit Card" && account.Type == handlers.Liability && account.ParentAccountId == liabilities.AccountId {
|
} else if account.Name == "Credit Card" && account.Type == handlers.Liability && account.ParentAccountId == liabilities.AccountId {
|
||||||
creditcard = &(*accounts.Accounts)[i]
|
creditcard = &(*accounts.Accounts)[i]
|
||||||
} else if account.Name == "Groceries" && account.Type == handlers.Expense && account.ParentAccountId == expenses.AccountId {
|
} else if account.Name == "Groceries" && account.Type == handlers.Expense && account.ParentAccountId == expenses.AccountId {
|
||||||
groceries = &(*accounts.Accounts)[i]
|
groceries = &(*accounts.Accounts)[i]
|
||||||
|
} else if account.Name == "Cable" && account.Type == handlers.Expense && account.ParentAccountId == expenses.AccountId {
|
||||||
|
cable = &(*accounts.Accounts)[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if salary == nil {
|
if salary == nil {
|
||||||
t.Fatalf("Couldn't find 'Income/Salary' account")
|
t.Fatalf("Couldn't find 'Income/Salary' account")
|
||||||
}
|
}
|
||||||
|
if openingbalances == nil {
|
||||||
|
t.Fatalf("Couldn't find 'Equity/Opening Balances")
|
||||||
|
}
|
||||||
if creditcard == nil {
|
if creditcard == nil {
|
||||||
t.Fatalf("Couldn't find 'Liabilities/Credit Card' account")
|
t.Fatalf("Couldn't find 'Liabilities/Credit Card' account")
|
||||||
}
|
}
|
||||||
if groceries == nil {
|
if groceries == nil {
|
||||||
t.Fatalf("Couldn't find 'Expenses/Groceries' account")
|
t.Fatalf("Couldn't find 'Expenses/Groceries' account")
|
||||||
}
|
}
|
||||||
|
if cable == nil {
|
||||||
grocerytransactions, err := getAccountTransactions(d.clients[0], groceries.AccountId, 0, 0, "")
|
t.Fatalf("Couldn't find 'Expenses/Cable' account")
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Couldn't fetch account transactions for 'Expenses/Groceries': %s\n", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 87.19 from preexisting transactions and 200.37 from Gnucash
|
gnucashAccountBalanceHelper(t, d.clients[0], salary, "-998.34")
|
||||||
if grocerytransactions.EndingBalance != "287.56" {
|
gnucashAccountBalanceHelper(t, d.clients[0], creditcard, "-272.03")
|
||||||
t.Errorf("Expected ending balance for 'Expenses/Groceries' to be '287.56', but found %s\n", grocerytransactions.EndingBalance)
|
gnucashAccountBalanceHelper(t, d.clients[0], openingbalances, "-21014.33")
|
||||||
}
|
gnucashAccountBalanceHelper(t, d.clients[0], groceries, "287.56") // 87.19 from preexisting transactions and 200.37 from Gnucash
|
||||||
|
gnucashAccountBalanceHelper(t, d.clients[0], cable, "89.98")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user