1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-03 12:48:38 -04:00

testing: Test fetching all a user's accounts

This commit is contained in:
2017-10-12 22:19:53 -04:00
parent c26ce83aa3
commit 6726d9cb2f
4 changed files with 55 additions and 2 deletions

View File

@ -22,6 +22,15 @@ func getAccount(client *http.Client, accountid int64) (*handlers.Account, error)
return &a, nil
}
func getAccounts(client *http.Client) (*handlers.AccountList, error) {
var al handlers.AccountList
err := read(client, &al, "/account/", "accounts")
if err != nil {
return nil, err
}
return &al, nil
}
func updateAccount(client *http.Client, account *handlers.Account) (*handlers.Account, error) {
var a handlers.Account
err := update(client, account, &a, "/account/"+strconv.FormatInt(account.AccountId, 10), "account")
@ -81,6 +90,46 @@ func TestGetAccount(t *testing.T) {
})
}
func TestGetAccounts(t *testing.T) {
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
al, err := getAccounts(d.clients[0])
if err != nil {
t.Fatalf("Error fetching accounts: %s\n", err)
}
numaccounts := 0
foundIds := make(map[int64]bool)
for i := 0; i < len(data[0].accounts); i++ {
orig := data[0].accounts[i]
curr := d.accounts[i]
if curr.UserId != d.users[0].UserId {
continue
}
numaccounts += 1
found := false
for _, a := range *al.Accounts {
if orig.Name == a.Name && orig.Type == a.Type && a.ExternalAccountId == orig.ExternalAccountId && d.securities[orig.SecurityId].SecurityId == a.SecurityId && ((orig.ParentAccountId == -1 && a.ParentAccountId == -1) || d.accounts[orig.ParentAccountId].AccountId == a.ParentAccountId) {
if _, ok := foundIds[a.AccountId]; ok {
continue
}
foundIds[a.AccountId] = true
found = true
break
}
}
if !found {
t.Errorf("Unable to find matching account: %+v", orig)
}
}
if numaccounts != len(*al.Accounts) {
t.Fatalf("Expected %d accounts, received %d", numaccounts, len(*al.Accounts))
}
})
}
func TestUpdateAccount(t *testing.T) {
RunWith(t, &data[0], func(t *testing.T, d *TestData) {
for i := 1; i < len(data[0].accounts); i++ {