Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: explore if we can create a particular DAG structure #176

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ sqlx-prepare:
cd cala-ledger && cargo sqlx prepare -- --all-features
cd cala-server && cargo sqlx prepare -- --all-features

reset-tf-state:
rm -rf bats/tf/terraform.tfstate

run-tf:
cd bats/tf && tofu init && tofu apply -auto-approve

test-in-ci: start-deps setup-db
cargo nextest run --verbose --locked
cargo test --doc
Expand Down
25 changes: 25 additions & 0 deletions bats/add-interest-account.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bats

load "helpers"

setup_file() {
make reset-tf-state run-tf || true
}

@test "add-interest-account: can add account" {
interest_account_id=$(random_uuid)
variables=$(
jq -n \
--arg interest_account_id "$interest_account_id" \
'{
"interestAccountId": $interest_account_id,
"interestAccountName": ("Interest Income #" + $interest_account_id),
"interestAccountCode": ("INTEREST_INCOME." + $interest_account_id),
"interestRevenueControlAccountSetId": "00000000-0000-0000-0000-140000000001"
}'
)
exec_graphql 'add-interest-account' "$variables"
graphql_output
id=$(graphql_output '.data.interest.account.accountId')
[[ "$id" == "$interest_account_id" ]] || exit 1
}
19 changes: 19 additions & 0 deletions bats/gql/add-interest-account.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mutation CreateInterestAccount(
$interestAccountId: UUID!
$interestAccountCode: String!
$interestAccountName: String!
$interestRevenueControlAccountSetId: UUID!
) {
interest: accountCreate(
input: {
accountId: $interestAccountId
code: $interestAccountCode
name: $interestAccountName
accountSetIds: [$interestRevenueControlAccountSetId]
}
) {
account {
accountId
}
}
}
4 changes: 4 additions & 0 deletions bats/tf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.terraform.*
.terraform/*
terraform.tfstate
terraform.tfstate.*
62 changes: 62 additions & 0 deletions bats/tf/accounts.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# "Chart of Accounts" Account Set
resource "cala_account_set" "chart_of_accounts" {
id = "00000000-0000-0000-0000-100000000001"
journal_id = cala_journal.journal.id
name = "Chart of Accounts"
}

# EQUITY
resource "random_uuid" "equity" {}
resource "cala_account_set" "equity" {
id = random_uuid.equity.result
journal_id = cala_journal.journal.id
name = "Equity"
normal_balance_type = "CREDIT"
}
resource "cala_account_set_member_account_set" "equity" {
account_set_id = cala_account_set.chart_of_accounts.id
member_account_set_id = cala_account_set.equity.id
}

resource "random_uuid" "retained_earnings" {}
resource "cala_account_set" "retained_earnings" {
id = random_uuid.retained_earnings.result
journal_id = cala_journal.journal.id
name = "Retained Earnings"
normal_balance_type = "CREDIT"
}
resource "cala_account_set_member_account_set" "retained_earnings_in_equity" {
account_set_id = cala_account_set.equity.id # this should be 'equity'
member_account_set_id = cala_account_set.retained_earnings.id
}


# REVENUE
resource "random_uuid" "revenue" {}
resource "cala_account_set" "revenue" {
id = random_uuid.revenue.result
journal_id = cala_journal.journal.id
name = "Revenue"
normal_balance_type = "CREDIT"
}
resource "cala_account_set_member_account_set" "revenue" {
account_set_id = cala_account_set.chart_of_accounts.id
member_account_set_id = cala_account_set.revenue.id
}
resource "cala_account_set_member_account_set" "revenue_in_retained_earnings" {
account_set_id = cala_account_set.retained_earnings.id
member_account_set_id = cala_account_set.revenue.id
}

# REVENUE: Members
resource "cala_account_set" "interest_revenue_control" {
id = "00000000-0000-0000-0000-140000000001"
journal_id = cala_journal.journal.id
name = "Interest Revenue Control Account"
normal_balance_type = "CREDIT"
}
resource "cala_account_set_member_account_set" "interest_revenue_control_in_revenue" {
account_set_id = cala_account_set.revenue.id
member_account_set_id = cala_account_set.interest_revenue_control.id
}

5 changes: 5 additions & 0 deletions bats/tf/journal.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "cala_journal" "journal" {
id = "00000000-0000-0000-0000-000000000001"
name = "My Journal"
description = "Journal for my accounts"
}
12 changes: 12 additions & 0 deletions bats/tf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
provider "cala" {
endpoint = "http://localhost:2252/graphql"
}

terraform {
required_providers {
cala = {
source = "registry.terraform.io/galoymoney/cala"
version = "0.0.18"
}
}
}
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
nativeBuildInputs = with pkgs;
[
rustToolchain
opentofu
alejandra
sqlx-cli
cargo-nextest
Expand Down
Loading