diff --git a/Makefile b/Makefile index e4dbcdec4..6a332ccc6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/bats/add-interest-account.bats b/bats/add-interest-account.bats new file mode 100644 index 000000000..c644315ba --- /dev/null +++ b/bats/add-interest-account.bats @@ -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 +} diff --git a/bats/gql/add-interest-account.gql b/bats/gql/add-interest-account.gql new file mode 100644 index 000000000..9ba173f84 --- /dev/null +++ b/bats/gql/add-interest-account.gql @@ -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 + } + } +} diff --git a/bats/tf/.gitignore b/bats/tf/.gitignore new file mode 100644 index 000000000..62f6ec285 --- /dev/null +++ b/bats/tf/.gitignore @@ -0,0 +1,4 @@ +.terraform.* +.terraform/* +terraform.tfstate +terraform.tfstate.* diff --git a/bats/tf/accounts.tf b/bats/tf/accounts.tf new file mode 100644 index 000000000..07d5336e5 --- /dev/null +++ b/bats/tf/accounts.tf @@ -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 +} + diff --git a/bats/tf/journal.tf b/bats/tf/journal.tf new file mode 100644 index 000000000..ebf1bc0aa --- /dev/null +++ b/bats/tf/journal.tf @@ -0,0 +1,5 @@ +resource "cala_journal" "journal" { + id = "00000000-0000-0000-0000-000000000001" + name = "My Journal" + description = "Journal for my accounts" +} diff --git a/bats/tf/main.tf b/bats/tf/main.tf new file mode 100644 index 000000000..c16c3773a --- /dev/null +++ b/bats/tf/main.tf @@ -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" + } + } +} diff --git a/flake.nix b/flake.nix index 842e31772..36a8283ee 100644 --- a/flake.nix +++ b/flake.nix @@ -37,6 +37,7 @@ nativeBuildInputs = with pkgs; [ rustToolchain + opentofu alejandra sqlx-cli cargo-nextest