Skip to content

Commit

Permalink
test: redo charts bats tests for new schema
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Jan 16, 2025
1 parent a121245 commit ba17602
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 59 deletions.
39 changes: 27 additions & 12 deletions bats/admin-gql/chart-of-accounts.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@ query ChartOfAccounts {
chartOfAccounts {
name
categories {
name
accounts {
__typename
... on AccountSet {
queryableId: id
name
hasSubAccounts
}
... on Account {
id
name
}
assets {
...category
}
liabilities {
...category
}
equity {
...category
}
revenues {
...category
}
expenses {
...category
}
}
}
}

fragment category on ChartCategory {
name
accountCode
controlAccounts {
name
accountCode
controlSubAccounts {
name
accountCode
}
}
}
73 changes: 26 additions & 47 deletions bats/chart-of-accounts.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,39 @@ teardown_file() {
}

@test "chart-of-accounts: can traverse chart of accounts" {
skip # TODO: re-implement from entity
exec_admin_graphql 'chart-of-accounts'

for i in {1..2}; do create_customer; done
category_account_code=$(echo "$output" | jq -r \
'.data.chartOfAccounts.categories.assets.accountCode'
)
[[ "$category_account_code" == "10000" ]] || exit 1

# Fetch Chart of Accounts
exec_admin_graphql 'chart-of-accounts'

liabilities_name="Liabilities"
user_checking_control_name="Customer Checking Control Account"
user_checking_control_account_set_id=$(echo "$output" | jq -r \
--arg category_name "$liabilities_name" \
--arg account_name "$user_checking_control_name" \
control_name="Deposits"
control_account_code=$(echo "$output" | jq -r \
--arg account_name "$control_name" \
'
.data.chartOfAccounts.categories[] |
select(.name == $category_name) |
.accounts[] |
.data.chartOfAccounts.categories.liabilities |
.controlAccounts[] |
select(.name == $account_name)
.queryableId
.accountCode
'
)
[[ "$control_account_code" == "20100" ]] || exit 1

# Fetch 1st page
variables=$(
jq -n \
--arg account_set_id "$user_checking_control_account_set_id" \
--arg from "$(from_utc)" \
'{
accountSetId: $account_set_id,
first: 100,
from: $from,
}'
)
exec_admin_graphql 'account-set' "$variables"
num_accounts_with_balance=$(graphql_output '.data.accountSet.subAccounts.edges | length')
first_cursor=$(graphql_output '.data.accountSet.subAccounts.edges[0].cursor')
btc_balance=$(graphql_output '.data.accountSet.subAccounts.edges[0].node.amounts.btc.balancesByLayer.all.netDebit')
[[ "$num_accounts_with_balance" -gt "0" ]] || exit 1
[[ "$btc_balance" == "0" ]] || exit 1

# Fetch paginated page
variables=$(
jq -n \
--arg account_set_id "$user_checking_control_account_set_id" \
--arg after "$first_cursor" \
--arg from "$(from_utc)" \
'{
accountSetId: $account_set_id,
first: 100,
after: $after,
from: $from,
}'
control_name="Credit Facilities Interest Income"
control_sub_name="Fixed Term Credit Facilities Interest Income"
control_account_code=$(echo "$output" | jq -r \
--arg account_name "$control_name" \
--arg account_sub_name "$control_sub_name" \
'
.data.chartOfAccounts.categories.revenues |
.controlAccounts[] |
select(.name == $account_name)
.controlSubAccounts[] |
select(.name == $account_sub_name)
.accountCode
'
)
exec_admin_graphql 'account-set' "$variables"
num_accounts_paginated_with_balance=$(graphql_output '.data.accountSet.subAccounts.edges | length')
[[ "$num_accounts_paginated_with_balance" -gt "0" ]] || exit 1
[[ "$num_accounts_paginated_with_balance" -lt "$num_accounts_with_balance" ]] || exit 1
[[ "$control_account_code" == "40101" ]] || exit 1
}

0 comments on commit ba17602

Please sign in to comment.