From 137ca3439a8ef50cce64d93ff88a954dd09952d4 Mon Sep 17 00:00:00 2001 From: Anantha Kumaran Date: Fri, 6 Oct 2023 22:38:55 +0530 Subject: [PATCH] add regression test suite --- .gitignore | 8 +- Makefile | 12 +- bunfig.toml | 2 - internal/server/expense.go | 22 +- package-lock.json | 364 ++++++++++++- package.json | 7 +- shell.nix | 4 + src/happydom.ts | 2 + tests/fixture/inr/allocation.json | 527 +++++++++++++++++++ tests/fixture/inr/assets_balance.json | 48 ++ tests/fixture/inr/balance.json | 48 ++ tests/fixture/inr/budget.json | 5 + tests/fixture/inr/cash_flow.json | 24 + tests/fixture/inr/cash_flow_monthly.json | 24 + tests/fixture/inr/dashboard.json | 209 ++++++++ tests/fixture/inr/diagnosis.json | 3 + tests/fixture/inr/expense.json | 265 ++++++++++ tests/fixture/inr/files.json | 25 + tests/fixture/inr/gain.json | 36 ++ tests/fixture/inr/income.json | 61 +++ tests/fixture/inr/investment.json | 55 ++ tests/fixture/inr/ledger.json | 112 ++++ tests/fixture/inr/liabilities_balance.json | 3 + tests/fixture/inr/liabilities_interest.json | 3 + tests/fixture/inr/liabilities_repayment.json | 3 + tests/fixture/inr/main.ledger | 16 + tests/fixture/inr/networth.json | 309 +++++++++++ tests/fixture/inr/paisa.yaml | 4 + tests/fixture/inr/price.json | 22 + tests/fixture/inr/recurring.json | 3 + tests/fixture/inr/retirement.json | 160 ++++++ tests/fixture/inr/transaction.json | 148 ++++++ tests/regression.test.ts | 103 ++++ 33 files changed, 2625 insertions(+), 12 deletions(-) delete mode 100644 bunfig.toml create mode 100644 tests/fixture/inr/allocation.json create mode 100644 tests/fixture/inr/assets_balance.json create mode 100644 tests/fixture/inr/balance.json create mode 100644 tests/fixture/inr/budget.json create mode 100644 tests/fixture/inr/cash_flow.json create mode 100644 tests/fixture/inr/cash_flow_monthly.json create mode 100644 tests/fixture/inr/dashboard.json create mode 100644 tests/fixture/inr/diagnosis.json create mode 100644 tests/fixture/inr/expense.json create mode 100644 tests/fixture/inr/files.json create mode 100644 tests/fixture/inr/gain.json create mode 100644 tests/fixture/inr/income.json create mode 100644 tests/fixture/inr/investment.json create mode 100644 tests/fixture/inr/ledger.json create mode 100644 tests/fixture/inr/liabilities_balance.json create mode 100644 tests/fixture/inr/liabilities_interest.json create mode 100644 tests/fixture/inr/liabilities_repayment.json create mode 100644 tests/fixture/inr/main.ledger create mode 100644 tests/fixture/inr/networth.json create mode 100644 tests/fixture/inr/paisa.yaml create mode 100644 tests/fixture/inr/price.json create mode 100644 tests/fixture/inr/recurring.json create mode 100644 tests/fixture/inr/retirement.json create mode 100644 tests/fixture/inr/transaction.json create mode 100644 tests/regression.test.ts diff --git a/.gitignore b/.gitignore index 3c45f257..3e37c9c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ paisa.db -paisa.yaml +/paisa.yaml /paisa +/sample web/static -example.ledger -main.ledger +/example.ledger +/main.ledger .DS_Store node_modules /build @@ -18,3 +19,4 @@ vite.config.ts.timestamp-* *.test docs/lexer/__pycache__/ bun.lockb +svg/* diff --git a/Makefile b/Makefile index deb9a64a..043d20a0 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,16 @@ lint: npm run check test -z $$(gofmt -l .) -test: - npm run test +regen: + go build + REGENERATE=true TZ=UTC bun test tests + +jstest: + bun test --preload ./src/happydom.ts src + go build + TZ=UTC bun test tests + +test: jstest npm run build go test ./... diff --git a/bunfig.toml b/bunfig.toml deleted file mode 100644 index ce808f02..00000000 --- a/bunfig.toml +++ /dev/null @@ -1,2 +0,0 @@ -[test] -preload = "./src/happydom.ts" diff --git a/internal/server/expense.go b/internal/server/expense.go index 45873088..ad452407 100644 --- a/internal/server/expense.go +++ b/internal/server/expense.go @@ -1,6 +1,7 @@ package server import ( + "sort" "strings" "github.com/ananthakumaran/paisa/internal/model/posting" @@ -49,8 +50,8 @@ func GetExpense(db *gorm.DB) gin.H { graph := make(map[string]map[string]Graph) for fy, ps := range utils.GroupByFY(postings) { graph[fy] = make(map[string]Graph) - graph[fy]["flat"] = computeGraph(ps) - graph[fy]["hierarchy"] = computeHierarchyGraph(ps) + graph[fy]["flat"] = sortGraph(computeGraph(ps)) + graph[fy]["hierarchy"] = sortGraph(computeHierarchyGraph(ps)) } return gin.H{ @@ -68,6 +69,23 @@ func GetExpense(db *gorm.DB) gin.H { "graph": graph} } +func sortGraph(graph Graph) Graph { + nodes := graph.Nodes + sort.Slice(nodes, func(i, j int) bool { + return graph.Nodes[i].Name < graph.Nodes[j].Name + }) + + links := graph.Links + sort.Slice(links, func(i, j int) bool { + return graph.Links[i].Source < graph.Links[j].Source || (graph.Links[i].Source == graph.Links[j].Source && graph.Links[i].Target < graph.Links[j].Target) + }) + return Graph{ + Nodes: nodes, + Links: links, + } + +} + func computeGraph(postings []posting.Posting) Graph { nodes := make(map[string]Node) links := make(map[Pair]decimal.Decimal) diff --git a/package-lock.json b/package-lock.json index 04e5b3ab..d91b2bea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,12 +62,14 @@ "@types/chroma-js": "^2.1.4", "@types/clusterize.js": "^0.18.1", "@types/d3": "^7.4.0", + "@types/json-diff": "^1.0.0", "@types/lodash": "^4.14.194", "@types/papaparse": "^5.3.7", "@types/sprintf-js": "^1.1.2", "@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/parser": "^5.45.0", "autoprefixer": "^10.4.14", + "axios": "^1.5.1", "bun-types": "^1.0.3", "concurrently": "^7.6.0", "daisyui": "^3.5.1", @@ -75,6 +77,7 @@ "eslint": "^8.28.0", "eslint-config-prettier": "^8.0", "eslint-plugin-svelte": "^2.32.4", + "json-diff": "^1.0.6", "nodemon": "^2.0.15", "postcss": "^8.4.27", "prettier": "^3.0", @@ -85,7 +88,8 @@ "tailwindcss": "^3.3.3", "tslib": "^2.4.1", "typescript": "^5.0.0", - "vite": "^4.0.0" + "vite": "^4.0.0", + "wait-port": "^1.1.0" } }, "node_modules/@alloc/quick-lru": { @@ -1258,6 +1262,15 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "node_modules/@ewoudenberg/difflib": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@ewoudenberg/difflib/-/difflib-0.1.0.tgz", + "integrity": "sha512-OU5P5mJyD3OoWYMWY+yIgwvgNS9cFAU10f+DDuvtogcWQOoJIsQ4Hy2McSfUfhKjq8L0FuWVb4Rt7kgA+XK86A==", + "dev": true, + "dependencies": { + "heap": ">= 0.2.0" + } + }, "node_modules/@floating-ui/core": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.2.6.tgz", @@ -2043,6 +2056,12 @@ "integrity": "sha512-1rkryxURpr6aWP7R786/UQOkJ3PcpQiWkAXBmdWc7ryFWqN6a4xfK7BtjXvFBKO9LjQ+MWQSWxYeZX1OApnArA==", "dev": true }, + "node_modules/@types/json-diff": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/json-diff/-/json-diff-1.0.0.tgz", + "integrity": "sha512-dCXC1F73Sqriz2d8Wt/sP/DztE+rlfIRPxW9WSYheHp/l3gvkeSvM6l4vhm7t4Dgn8AJAxNKajx/eobbPdP6Wg==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.12", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", @@ -2616,6 +2635,12 @@ "node": ">=8" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "node_modules/autoprefixer": { "version": "10.4.14", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.14.tgz", @@ -2649,6 +2674,17 @@ "postcss": "^8.1.0" } }, + "node_modules/axios": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.5.1.tgz", + "integrity": "sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -2996,6 +3032,27 @@ "integrity": "sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==", "dev": true }, + "node_modules/colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", + "dev": true, + "engines": { + "node": ">=0.1.90" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", @@ -3783,6 +3840,15 @@ "robust-predicates": "^3.0.0" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/delegate": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/delegate/-/delegate-3.2.0.tgz", @@ -3861,6 +3927,18 @@ "node": ">=6.0.0" } }, + "node_modules/dreamopt": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/dreamopt/-/dreamopt-0.8.0.tgz", + "integrity": "sha512-vyJTp8+mC+G+5dfgsY+r3ckxlz+QMX40VjPQsZc5gxVAxLmi64TBoVkP54A/pRAXMXsbu2GMMBrZPxNv23waMg==", + "dev": true, + "dependencies": { + "wordwrap": ">=0.0.2" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/easy-reactive": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/easy-reactive/-/easy-reactive-1.0.4.tgz", @@ -4781,6 +4859,40 @@ "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", + "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fraction.js": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz", @@ -5026,6 +5138,12 @@ "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==", "optional": true }, + "node_modules/heap": { + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/heap/-/heap-0.2.7.tgz", + "integrity": "sha512-2bsegYkkHO+h/9MGbn6KWcE45cHZgPANo5LXF7EvWdT0yT2EguSVO1nDgU5c8+ZOPwp2vMNa7YFsJhVcDR9Sdg==", + "dev": true + }, "node_modules/https-proxy-agent": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", @@ -5284,6 +5402,23 @@ "node": ">=4" } }, + "node_modules/json-diff": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/json-diff/-/json-diff-1.0.6.tgz", + "integrity": "sha512-tcFIPRdlc35YkYdGxcamJjllUhXWv4n2rK9oJ2RsAzV4FBkuV4ojKEDgcZ+kpKxDmJKv+PFK65+1tVVOnSeEqA==", + "dev": true, + "dependencies": { + "@ewoudenberg/difflib": "0.1.0", + "colors": "^1.4.0", + "dreamopt": "~0.8.0" + }, + "bin": { + "json-diff": "bin/json-diff.js" + }, + "engines": { + "node": "*" + } + }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -5511,6 +5646,27 @@ "node": ">=10.0.0" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/mimic-response": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz", @@ -6218,6 +6374,12 @@ "svelte": "^3.2.0 || ^4.0.0-next.0" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true + }, "node_modules/pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", @@ -7734,6 +7896,55 @@ "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.6.tgz", "integrity": "sha512-f+fciywl1SJEniZHD6H+kUO8gOnwIr7f4ijKA6+ZvJFjeGi1r4PDLl53Ayud9O/rk64RqgoQine0feoeOU0kXg==" }, + "node_modules/wait-port": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/wait-port/-/wait-port-1.1.0.tgz", + "integrity": "sha512-3e04qkoN3LxTMLakdqeWth8nih8usyg+sf1Bgdf9wwUkp05iuK1eSY/QpLvscT/+F/gA89+LpUmmgBtesbqI2Q==", + "dev": true, + "dependencies": { + "chalk": "^4.1.2", + "commander": "^9.3.0", + "debug": "^4.3.4" + }, + "bin": { + "wait-port": "bin/wait-port.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/wait-port/node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "dev": true, + "engines": { + "node": "^12.20.0 || >=14" + } + }, + "node_modules/wait-port/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/wait-port/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", @@ -8744,6 +8955,15 @@ } } }, + "@ewoudenberg/difflib": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@ewoudenberg/difflib/-/difflib-0.1.0.tgz", + "integrity": "sha512-OU5P5mJyD3OoWYMWY+yIgwvgNS9cFAU10f+DDuvtogcWQOoJIsQ4Hy2McSfUfhKjq8L0FuWVb4Rt7kgA+XK86A==", + "dev": true, + "requires": { + "heap": ">= 0.2.0" + } + }, "@floating-ui/core": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.2.6.tgz", @@ -9424,6 +9644,12 @@ "integrity": "sha512-1rkryxURpr6aWP7R786/UQOkJ3PcpQiWkAXBmdWc7ryFWqN6a4xfK7BtjXvFBKO9LjQ+MWQSWxYeZX1OApnArA==", "dev": true }, + "@types/json-diff": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/json-diff/-/json-diff-1.0.0.tgz", + "integrity": "sha512-dCXC1F73Sqriz2d8Wt/sP/DztE+rlfIRPxW9WSYheHp/l3gvkeSvM6l4vhm7t4Dgn8AJAxNKajx/eobbPdP6Wg==", + "dev": true + }, "@types/json-schema": { "version": "7.0.12", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", @@ -9828,6 +10054,12 @@ "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "autoprefixer": { "version": "10.4.14", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.14.tgz", @@ -9842,6 +10074,17 @@ "postcss-value-parser": "^4.2.0" } }, + "axios": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.5.1.tgz", + "integrity": "sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==", + "dev": true, + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "axobject-query": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz", @@ -10103,6 +10346,21 @@ "integrity": "sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==", "dev": true }, + "colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", + "dev": true + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", @@ -10732,6 +10990,12 @@ "robust-predicates": "^3.0.0" } }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true + }, "delegate": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/delegate/-/delegate-3.2.0.tgz", @@ -10795,6 +11059,15 @@ "esutils": "^2.0.2" } }, + "dreamopt": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/dreamopt/-/dreamopt-0.8.0.tgz", + "integrity": "sha512-vyJTp8+mC+G+5dfgsY+r3ckxlz+QMX40VjPQsZc5gxVAxLmi64TBoVkP54A/pRAXMXsbu2GMMBrZPxNv23waMg==", + "dev": true, + "requires": { + "wordwrap": ">=0.0.2" + } + }, "easy-reactive": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/easy-reactive/-/easy-reactive-1.0.4.tgz", @@ -11378,6 +11651,23 @@ "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==", "dev": true }, + "follow-redirects": { + "version": "1.15.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", + "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "dev": true + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "fraction.js": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz", @@ -11561,6 +11851,12 @@ "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==", "optional": true }, + "heap": { + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/heap/-/heap-0.2.7.tgz", + "integrity": "sha512-2bsegYkkHO+h/9MGbn6KWcE45cHZgPANo5LXF7EvWdT0yT2EguSVO1nDgU5c8+ZOPwp2vMNa7YFsJhVcDR9Sdg==", + "dev": true + }, "https-proxy-agent": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", @@ -11751,6 +12047,17 @@ "optional": true, "peer": true }, + "json-diff": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/json-diff/-/json-diff-1.0.6.tgz", + "integrity": "sha512-tcFIPRdlc35YkYdGxcamJjllUhXWv4n2rK9oJ2RsAzV4FBkuV4ojKEDgcZ+kpKxDmJKv+PFK65+1tVVOnSeEqA==", + "dev": true, + "requires": { + "@ewoudenberg/difflib": "0.1.0", + "colors": "^1.4.0", + "dreamopt": "~0.8.0" + } + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -11929,6 +12236,21 @@ "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", "dev": true }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "requires": { + "mime-db": "1.52.0" + } + }, "mimic-response": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz", @@ -12405,6 +12727,12 @@ "dev": true, "requires": {} }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true + }, "pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", @@ -13450,6 +13778,40 @@ "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.6.tgz", "integrity": "sha512-f+fciywl1SJEniZHD6H+kUO8gOnwIr7f4ijKA6+ZvJFjeGi1r4PDLl53Ayud9O/rk64RqgoQine0feoeOU0kXg==" }, + "wait-port": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/wait-port/-/wait-port-1.1.0.tgz", + "integrity": "sha512-3e04qkoN3LxTMLakdqeWth8nih8usyg+sf1Bgdf9wwUkp05iuK1eSY/QpLvscT/+F/gA89+LpUmmgBtesbqI2Q==", + "dev": true, + "requires": { + "chalk": "^4.1.2", + "commander": "^9.3.0", + "debug": "^4.3.4" + }, + "dependencies": { + "commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "dev": true + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package.json b/package.json index 88bbee5a..a65bdc7d 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,6 @@ "scripts": { "parser-build": "lezer-generator src/lib/search/parser/query.grammar -o src/lib/search/parser/parser", "parser-build-debug": "lezer-generator src/lib/search/parser/query.grammar --names -o src/lib/search/parser/parser", - "test": "bun test", "dev": "vite dev --host 0.0.0.0", "build": "vite build", "build:watch": "vite build --watch", @@ -70,12 +69,14 @@ "@types/chroma-js": "^2.1.4", "@types/clusterize.js": "^0.18.1", "@types/d3": "^7.4.0", + "@types/json-diff": "^1.0.0", "@types/lodash": "^4.14.194", "@types/papaparse": "^5.3.7", "@types/sprintf-js": "^1.1.2", "@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/parser": "^5.45.0", "autoprefixer": "^10.4.14", + "axios": "^1.5.1", "bun-types": "^1.0.3", "concurrently": "^7.6.0", "daisyui": "^3.5.1", @@ -83,6 +84,7 @@ "eslint": "^8.28.0", "eslint-config-prettier": "^8.0", "eslint-plugin-svelte": "^2.32.4", + "json-diff": "^1.0.6", "nodemon": "^2.0.15", "postcss": "^8.4.27", "prettier": "^3.0", @@ -93,7 +95,8 @@ "tailwindcss": "^3.3.3", "tslib": "^2.4.1", "typescript": "^5.0.0", - "vite": "^4.0.0" + "vite": "^4.0.0", + "wait-port": "^1.1.0" }, "type": "module" } diff --git a/shell.nix b/shell.nix index 973b3c2a..38ff40d6 100644 --- a/shell.nix +++ b/shell.nix @@ -13,6 +13,10 @@ pkgs.mkShell { pkgs.python311Packages.mkdocs pkgs.python311Packages.mkdocs-material + + # test + pkgs.ledger + pkgs.hledger ] ++ (pkgs.lib.optional pkgs.stdenv.isLinux pkgs.wails); shellHook = '' diff --git a/src/happydom.ts b/src/happydom.ts index 7f712d02..0dd2dce1 100644 --- a/src/happydom.ts +++ b/src/happydom.ts @@ -1,3 +1,5 @@ import { GlobalRegistrator } from "@happy-dom/global-registrator"; +const oldConsole = console; GlobalRegistrator.register(); +window.console = oldConsole; diff --git a/tests/fixture/inr/allocation.json b/tests/fixture/inr/allocation.json new file mode 100644 index 00000000..5019aae2 --- /dev/null +++ b/tests/fixture/inr/allocation.json @@ -0,0 +1,527 @@ +{ + "aggregates": { + "Assets": { + "date": "0001-01-01T00:00:00Z", + "account": "Assets", + "amount": 0, + "market_amount": 0 + }, + "Assets:Checking": { + "date": "2022-02-07T23:59:59.999999999Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity": { + "date": "0001-01-01T00:00:00Z", + "account": "Assets:Equity", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-02-07T23:59:59.999999999Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + "aggregates_timeline": [ + { + "Assets:Checking": { + "date": "2022-01-01T00:00:00Z", + "account": "Assets:Checking", + "amount": 100000, + "market_amount": 100000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-02T00:00:00Z", + "account": "Assets:Checking", + "amount": 100000, + "market_amount": 100000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-03T00:00:00Z", + "account": "Assets:Checking", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-04T00:00:00Z", + "account": "Assets:Checking", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-05T00:00:00Z", + "account": "Assets:Checking", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-06T00:00:00Z", + "account": "Assets:Checking", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-07T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-07T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-08T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-08T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-09T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-09T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-10T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-10T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-11T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-11T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-12T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-12T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-13T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-13T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-14T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-14T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-15T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-15T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-16T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-16T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-17T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-17T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-18T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-18T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-19T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-19T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-20T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-20T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-21T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-21T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-22T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-22T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-23T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-23T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-24T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-24T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-25T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-25T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-26T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-26T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-27T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-27T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-28T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-28T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-29T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-29T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-30T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-30T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-01-31T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-01-31T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-02-01T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-02-01T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-02-02T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-02-02T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-02-03T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-02-03T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-02-04T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-02-04T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-02-05T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-02-05T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-02-06T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-02-06T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + }, + { + "Assets:Checking": { + "date": "2022-02-07T00:00:00Z", + "account": "Assets:Checking", + "amount": 0, + "market_amount": 0 + }, + "Assets:Equity:NIFTY": { + "date": "2022-02-07T00:00:00Z", + "account": "Assets:Equity:NIFTY", + "amount": 80000, + "market_amount": 80000 + } + } + ], + "allocation_targets": null +} \ No newline at end of file diff --git a/tests/fixture/inr/assets_balance.json b/tests/fixture/inr/assets_balance.json new file mode 100644 index 00000000..fa19b72c --- /dev/null +++ b/tests/fixture/inr/assets_balance.json @@ -0,0 +1,48 @@ +{ + "asset_breakdowns": { + "Assets": { + "group": "Assets", + "investmentAmount": 80000, + "withdrawalAmount": 0, + "marketAmount": 80000, + "balanceUnits": 0, + "latestPrice": 0, + "xirr": 0, + "gainAmount": 0, + "absoluteReturn": 0 + }, + "Assets:Checking": { + "group": "Assets:Checking", + "investmentAmount": 0, + "withdrawalAmount": 0, + "marketAmount": 0, + "balanceUnits": 0, + "latestPrice": 0, + "xirr": 0, + "gainAmount": 0, + "absoluteReturn": 0 + }, + "Assets:Equity": { + "group": "Assets:Equity", + "investmentAmount": 80000, + "withdrawalAmount": 0, + "marketAmount": 80000, + "balanceUnits": 0, + "latestPrice": 0, + "xirr": 0, + "gainAmount": 0, + "absoluteReturn": 0 + }, + "Assets:Equity:NIFTY": { + "group": "Assets:Equity:NIFTY", + "investmentAmount": 80000, + "withdrawalAmount": 0, + "marketAmount": 80000, + "balanceUnits": 800, + "latestPrice": 0, + "xirr": 0, + "gainAmount": 0, + "absoluteReturn": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixture/inr/balance.json b/tests/fixture/inr/balance.json new file mode 100644 index 00000000..fa19b72c --- /dev/null +++ b/tests/fixture/inr/balance.json @@ -0,0 +1,48 @@ +{ + "asset_breakdowns": { + "Assets": { + "group": "Assets", + "investmentAmount": 80000, + "withdrawalAmount": 0, + "marketAmount": 80000, + "balanceUnits": 0, + "latestPrice": 0, + "xirr": 0, + "gainAmount": 0, + "absoluteReturn": 0 + }, + "Assets:Checking": { + "group": "Assets:Checking", + "investmentAmount": 0, + "withdrawalAmount": 0, + "marketAmount": 0, + "balanceUnits": 0, + "latestPrice": 0, + "xirr": 0, + "gainAmount": 0, + "absoluteReturn": 0 + }, + "Assets:Equity": { + "group": "Assets:Equity", + "investmentAmount": 80000, + "withdrawalAmount": 0, + "marketAmount": 80000, + "balanceUnits": 0, + "latestPrice": 0, + "xirr": 0, + "gainAmount": 0, + "absoluteReturn": 0 + }, + "Assets:Equity:NIFTY": { + "group": "Assets:Equity:NIFTY", + "investmentAmount": 80000, + "withdrawalAmount": 0, + "marketAmount": 80000, + "balanceUnits": 800, + "latestPrice": 0, + "xirr": 0, + "gainAmount": 0, + "absoluteReturn": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixture/inr/budget.json b/tests/fixture/inr/budget.json new file mode 100644 index 00000000..60e76ff4 --- /dev/null +++ b/tests/fixture/inr/budget.json @@ -0,0 +1,5 @@ +{ + "availableForBudgeting": 0, + "budgetsByMonth": {}, + "checkingBalance": 0 +} \ No newline at end of file diff --git a/tests/fixture/inr/cash_flow.json b/tests/fixture/inr/cash_flow.json new file mode 100644 index 00000000..abaf209f --- /dev/null +++ b/tests/fixture/inr/cash_flow.json @@ -0,0 +1,24 @@ +{ + "cash_flows": [ + { + "date": "2022-01-01T00:00:00Z", + "income": 100000, + "expenses": 20000, + "liabilities": 0, + "investment": 80000, + "tax": 0, + "checking": 0, + "balance": 0 + }, + { + "date": "2022-02-01T00:00:00Z", + "income": 0, + "expenses": 0, + "liabilities": 0, + "investment": 0, + "tax": 0, + "checking": 0, + "balance": 0 + } + ] +} \ No newline at end of file diff --git a/tests/fixture/inr/cash_flow_monthly.json b/tests/fixture/inr/cash_flow_monthly.json new file mode 100644 index 00000000..8b9c822d --- /dev/null +++ b/tests/fixture/inr/cash_flow_monthly.json @@ -0,0 +1,24 @@ +{ + "cash_flows": [ + { + "date": "2022-01-01T00:00:00+05:30", + "income": 100000, + "expenses": 20000, + "liabilities": 0, + "investment": 80000, + "tax": 0, + "checking": 0, + "balance": 0 + }, + { + "date": "2022-02-01T00:00:00+05:30", + "income": 0, + "expenses": 0, + "liabilities": 0, + "investment": 0, + "tax": 0, + "checking": 0, + "balance": 0 + } + ] +} \ No newline at end of file diff --git a/tests/fixture/inr/dashboard.json b/tests/fixture/inr/dashboard.json new file mode 100644 index 00000000..65f496b2 --- /dev/null +++ b/tests/fixture/inr/dashboard.json @@ -0,0 +1,209 @@ +{ + "budget": { + "availableForBudgeting": 0, + "budgetsByMonth": {}, + "checkingBalance": 0 + }, + "cashFlows": [ + { + "date": "2022-01-01T00:00:00Z", + "income": 100000, + "expenses": 20000, + "liabilities": 0, + "investment": 80000, + "tax": 0, + "checking": 0, + "balance": 0 + }, + { + "date": "2022-02-01T00:00:00Z", + "income": 0, + "expenses": 0, + "liabilities": 0, + "investment": 0, + "tax": 0, + "checking": 0, + "balance": 0 + } + ], + "expenses": { + "2022-01": [ + { + "id": 4, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Expenses:Rent", + "commodity": "INR", + "quantity": 20000, + "amount": 20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ] + }, + "networth": { + "networth": { + "date": "2022-02-07T23:59:59.999999999Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + "xirr": 0 + }, + "transactionSequences": [], + "transactions": [ + { + "id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "postings": [ + { + "id": 6, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Equity:NIFTY", + "commodity": "NIFTY", + "quantity": 800, + "amount": 80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + }, + { + "id": 5, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": -80000, + "amount": -80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "tag_recurring": "", + "tag_period": "", + "beginLine": 14, + "endLine": 17, + "fileName": "main.ledger" + }, + { + "id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "postings": [ + { + "id": 4, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Expenses:Rent", + "commodity": "INR", + "quantity": 20000, + "amount": 20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + }, + { + "id": 3, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": -20000, + "amount": -20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "tag_recurring": "", + "tag_period": "", + "beginLine": 10, + "endLine": 13, + "fileName": "main.ledger" + }, + { + "id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "postings": [ + { + "id": 2, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": 100000, + "amount": 100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + }, + { + "id": 1, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Income:Salary:Acme", + "commodity": "INR", + "quantity": -100000, + "amount": -100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "tag_recurring": "", + "tag_period": "", + "beginLine": 6, + "endLine": 9, + "fileName": "main.ledger" + } + ] +} \ No newline at end of file diff --git a/tests/fixture/inr/diagnosis.json b/tests/fixture/inr/diagnosis.json new file mode 100644 index 00000000..18b086be --- /dev/null +++ b/tests/fixture/inr/diagnosis.json @@ -0,0 +1,3 @@ +{ + "issues": [] +} \ No newline at end of file diff --git a/tests/fixture/inr/expense.json b/tests/fixture/inr/expense.json new file mode 100644 index 00000000..9f2fa93f --- /dev/null +++ b/tests/fixture/inr/expense.json @@ -0,0 +1,265 @@ +{ + "expenses": [ + { + "id": 4, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Expenses:Rent", + "commodity": "INR", + "quantity": 20000, + "amount": 20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "graph": { + "2021 - 22": { + "flat": { + "nodes": [ + { + "id": 1, + "name": "Assets:Checking" + }, + { + "id": 4, + "name": "Assets:Equity:NIFTY" + }, + { + "id": 3, + "name": "Expenses:Rent" + }, + { + "id": 2, + "name": "Income:Salary:Acme" + } + ], + "links": [ + { + "source": 1, + "target": 3, + "value": 20000 + }, + { + "source": 1, + "target": 4, + "value": 80000 + }, + { + "source": 2, + "target": 1, + "value": 100000 + } + ] + }, + "hierarchy": { + "nodes": [ + { + "id": 1, + "name": "Assets:Checking" + }, + { + "id": 7, + "name": "Assets:Equity:NIFTY" + }, + { + "id": 5, + "name": "Expenses" + }, + { + "id": 6, + "name": "Expenses:Rent" + }, + { + "id": 2, + "name": "Income" + }, + { + "id": 3, + "name": "Income:Salary" + }, + { + "id": 4, + "name": "Income:Salary:Acme" + } + ], + "links": [ + { + "source": 1, + "target": 5, + "value": 20000 + }, + { + "source": 1, + "target": 7, + "value": 80000 + }, + { + "source": 2, + "target": 1, + "value": 100000 + }, + { + "source": 3, + "target": 2, + "value": 100000 + }, + { + "source": 4, + "target": 3, + "value": 100000 + }, + { + "source": 5, + "target": 6, + "value": 20000 + } + ] + } + } + }, + "month_wise": { + "expenses": { + "2022-01": [ + { + "id": 4, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Expenses:Rent", + "commodity": "INR", + "quantity": 20000, + "amount": 20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ] + }, + "incomes": { + "2022-01": [ + { + "id": 1, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Income:Salary:Acme", + "commodity": "INR", + "quantity": -100000, + "amount": -100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ] + }, + "investments": { + "2022-01": [ + { + "id": 6, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Equity:NIFTY", + "commodity": "NIFTY", + "quantity": 800, + "amount": 80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ] + }, + "taxes": {} + }, + "year_wise": { + "expenses": { + "2021 - 22": [ + { + "id": 4, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Expenses:Rent", + "commodity": "INR", + "quantity": 20000, + "amount": 20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ] + }, + "incomes": { + "2021 - 22": [ + { + "id": 1, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Income:Salary:Acme", + "commodity": "INR", + "quantity": -100000, + "amount": -100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ] + }, + "investments": { + "2021 - 22": [ + { + "id": 6, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Equity:NIFTY", + "commodity": "NIFTY", + "quantity": 800, + "amount": 80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ] + }, + "taxes": {} + } +} \ No newline at end of file diff --git a/tests/fixture/inr/files.json b/tests/fixture/inr/files.json new file mode 100644 index 00000000..5c7debb9 --- /dev/null +++ b/tests/fixture/inr/files.json @@ -0,0 +1,25 @@ +{ + "accounts": [ + "Income:Salary:Acme", + "Assets:Checking", + "Expenses:Rent", + "Assets:Equity:NIFTY" + ], + "commodities": [ + "INR", + "NIFTY" + ], + "files": [ + { + "name": "main.ledger", + "content": "commodity INR 9,99,99,999.00\n\nP 2022/01/07 00:00:00 NIFTY 100 INR\nP 2022/08/07 00:00:00 NIFTY 150 INR\n\n2022/01/01 Salary\n Income:Salary:Acme -100,000 INR\n Assets:Checking 100,000 INR\n\n2022/01/03 Rent\n Assets:Checking -20,000 INR\n Expenses:Rent\n\n2022/01/07 Investment\n Assets:Checking -80,000 INR\n Assets:Equity:NIFTY 800 NIFTY @ 100 INR\n", + "versions": [], + "operation": "" + } + ], + "payees": [ + "Salary", + "Rent", + "Investment" + ] +} \ No newline at end of file diff --git a/tests/fixture/inr/gain.json b/tests/fixture/inr/gain.json new file mode 100644 index 00000000..511c216a --- /dev/null +++ b/tests/fixture/inr/gain.json @@ -0,0 +1,36 @@ +{ + "gain_breakdown": [ + { + "account": "Assets:Equity:NIFTY", + "networth": { + "date": "2022-02-07T23:59:59.999999999Z", + "investmentAmount": 80000, + "withdrawalAmount": 0, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + "xirr": 0, + "postings": [ + { + "id": 6, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Equity:NIFTY", + "commodity": "NIFTY", + "quantity": 800, + "amount": 80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 80000 + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/fixture/inr/income.json b/tests/fixture/inr/income.json new file mode 100644 index 00000000..c18d8cd0 --- /dev/null +++ b/tests/fixture/inr/income.json @@ -0,0 +1,61 @@ +{ + "income_timeline": [ + { + "date": "2022-01-01T00:00:00Z", + "postings": [ + { + "id": 1, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Income:Salary:Acme", + "commodity": "INR", + "quantity": -100000, + "amount": -100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ] + }, + { + "date": "2022-02-01T00:00:00Z", + "postings": [] + } + ], + "tax_timeline": [], + "yearly_cards": [ + { + "start_date": "2021-04-01T00:00:00Z", + "end_date": "2022-03-31T23:59:59.999999999Z", + "postings": [ + { + "id": 1, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Income:Salary:Acme", + "commodity": "INR", + "quantity": -100000, + "amount": -100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "gross_income": 100000, + "net_tax": 0, + "net_income": 100000 + } + ] +} \ No newline at end of file diff --git a/tests/fixture/inr/investment.json b/tests/fixture/inr/investment.json new file mode 100644 index 00000000..c02bc5f1 --- /dev/null +++ b/tests/fixture/inr/investment.json @@ -0,0 +1,55 @@ +{ + "assets": [ + { + "id": 6, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Equity:NIFTY", + "commodity": "NIFTY", + "quantity": 800, + "amount": 80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "yearly_cards": [ + { + "start_date": "2021-04-01T00:00:00Z", + "end_date": "2022-03-31T23:59:59.999999999Z", + "postings": [ + { + "id": 6, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Equity:NIFTY", + "commodity": "NIFTY", + "quantity": 800, + "amount": 80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "gross_salary_income": 100000, + "gross_other_income": 0, + "net_tax": 0, + "net_income": 100000, + "net_investment": 80000, + "net_expense": 20000, + "savings_rate": 80 + } + ] +} \ No newline at end of file diff --git a/tests/fixture/inr/ledger.json b/tests/fixture/inr/ledger.json new file mode 100644 index 00000000..b256d690 --- /dev/null +++ b/tests/fixture/inr/ledger.json @@ -0,0 +1,112 @@ +{ + "postings": [ + { + "id": 6, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Equity:NIFTY", + "commodity": "NIFTY", + "quantity": 800, + "amount": 80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 80000 + }, + { + "id": 5, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": -80000, + "amount": -80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": -80000 + }, + { + "id": 4, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Expenses:Rent", + "commodity": "INR", + "quantity": 20000, + "amount": 20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 20000 + }, + { + "id": 3, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": -20000, + "amount": -20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": -20000 + }, + { + "id": 2, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": 100000, + "amount": 100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 100000 + }, + { + "id": 1, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Income:Salary:Acme", + "commodity": "INR", + "quantity": -100000, + "amount": -100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": -100000 + } + ] +} \ No newline at end of file diff --git a/tests/fixture/inr/liabilities_balance.json b/tests/fixture/inr/liabilities_balance.json new file mode 100644 index 00000000..25e3825c --- /dev/null +++ b/tests/fixture/inr/liabilities_balance.json @@ -0,0 +1,3 @@ +{ + "liability_breakdowns": {} +} \ No newline at end of file diff --git a/tests/fixture/inr/liabilities_interest.json b/tests/fixture/inr/liabilities_interest.json new file mode 100644 index 00000000..3936c0ad --- /dev/null +++ b/tests/fixture/inr/liabilities_interest.json @@ -0,0 +1,3 @@ +{ + "interest_timeline_breakdown": null +} \ No newline at end of file diff --git a/tests/fixture/inr/liabilities_repayment.json b/tests/fixture/inr/liabilities_repayment.json new file mode 100644 index 00000000..b95d9ac5 --- /dev/null +++ b/tests/fixture/inr/liabilities_repayment.json @@ -0,0 +1,3 @@ +{ + "repayments": [] +} \ No newline at end of file diff --git a/tests/fixture/inr/main.ledger b/tests/fixture/inr/main.ledger new file mode 100644 index 00000000..3f327504 --- /dev/null +++ b/tests/fixture/inr/main.ledger @@ -0,0 +1,16 @@ +commodity INR 9,99,99,999.00 + +P 2022/01/07 00:00:00 NIFTY 100 INR +P 2022/08/07 00:00:00 NIFTY 150 INR + +2022/01/01 Salary + Income:Salary:Acme -100,000 INR + Assets:Checking 100,000 INR + +2022/01/03 Rent + Assets:Checking -20,000 INR + Expenses:Rent + +2022/01/07 Investment + Assets:Checking -80,000 INR + Assets:Equity:NIFTY 800 NIFTY @ 100 INR diff --git a/tests/fixture/inr/networth.json b/tests/fixture/inr/networth.json new file mode 100644 index 00000000..1737ded8 --- /dev/null +++ b/tests/fixture/inr/networth.json @@ -0,0 +1,309 @@ +{ + "networthTimeline": [ + { + "date": "2022-01-01T00:00:00Z", + "investmentAmount": 100000, + "withdrawalAmount": 0, + "gainAmount": 0, + "balanceAmount": 100000, + "netInvestmentAmount": 100000 + }, + { + "date": "2022-01-02T00:00:00Z", + "investmentAmount": 100000, + "withdrawalAmount": 0, + "gainAmount": 0, + "balanceAmount": 100000, + "netInvestmentAmount": 100000 + }, + { + "date": "2022-01-03T00:00:00Z", + "investmentAmount": 100000, + "withdrawalAmount": 20000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-04T00:00:00Z", + "investmentAmount": 100000, + "withdrawalAmount": 20000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-05T00:00:00Z", + "investmentAmount": 100000, + "withdrawalAmount": 20000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-06T00:00:00Z", + "investmentAmount": 100000, + "withdrawalAmount": 20000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-07T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-08T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-09T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-10T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-11T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-12T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-13T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-14T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-15T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-16T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-17T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-18T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-19T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-20T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-21T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-22T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-23T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-24T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-25T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-26T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-27T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-28T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-29T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-30T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-01-31T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-02-01T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-02-02T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-02-03T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-02-04T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-02-05T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-02-06T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + }, + { + "date": "2022-02-07T00:00:00Z", + "investmentAmount": 180000, + "withdrawalAmount": 100000, + "gainAmount": 0, + "balanceAmount": 80000, + "netInvestmentAmount": 80000 + } + ], + "xirr": 0 +} \ No newline at end of file diff --git a/tests/fixture/inr/paisa.yaml b/tests/fixture/inr/paisa.yaml new file mode 100644 index 00000000..df303eab --- /dev/null +++ b/tests/fixture/inr/paisa.yaml @@ -0,0 +1,4 @@ +journal_path: main.ledger +db_path: paisa.db +ledger_cli: ledger + diff --git a/tests/fixture/inr/price.json b/tests/fixture/inr/price.json new file mode 100644 index 00000000..da6446ea --- /dev/null +++ b/tests/fixture/inr/price.json @@ -0,0 +1,22 @@ +{ + "prices": { + "NIFTY": [ + { + "id": 3, + "date": "2022-08-07T00:00:00Z", + "commodity_type": "unknown", + "commodity_id": "NIFTY", + "commodity_name": "NIFTY", + "value": 150 + }, + { + "id": 2, + "date": "2022-01-07T00:00:00Z", + "commodity_type": "unknown", + "commodity_id": "NIFTY", + "commodity_name": "NIFTY", + "value": 100 + } + ] + } +} \ No newline at end of file diff --git a/tests/fixture/inr/recurring.json b/tests/fixture/inr/recurring.json new file mode 100644 index 00000000..5e86a101 --- /dev/null +++ b/tests/fixture/inr/recurring.json @@ -0,0 +1,3 @@ +{ + "transaction_sequences": [] +} \ No newline at end of file diff --git a/tests/fixture/inr/retirement.json b/tests/fixture/inr/retirement.json new file mode 100644 index 00000000..9560db8b --- /dev/null +++ b/tests/fixture/inr/retirement.json @@ -0,0 +1,160 @@ +{ + "savings_timeline": [ + { + "date": "2022-01-01T00:00:00Z", + "value": 100000 + }, + { + "date": "2022-01-02T00:00:00Z", + "value": 100000 + }, + { + "date": "2022-01-03T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-04T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-05T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-06T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-07T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-08T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-09T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-10T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-11T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-12T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-13T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-14T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-15T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-16T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-17T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-18T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-19T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-20T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-21T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-22T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-23T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-24T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-25T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-26T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-27T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-28T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-29T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-30T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-01-31T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-02-01T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-02-02T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-02-03T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-02-04T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-02-05T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-02-06T00:00:00Z", + "value": 80000 + }, + { + "date": "2022-02-07T00:00:00Z", + "value": 80000 + } + ], + "savings_total": 80000, + "swr": 4, + "xirr": 0, + "yearly_expense": 10000 +} \ No newline at end of file diff --git a/tests/fixture/inr/transaction.json b/tests/fixture/inr/transaction.json new file mode 100644 index 00000000..9269cea5 --- /dev/null +++ b/tests/fixture/inr/transaction.json @@ -0,0 +1,148 @@ +{ + "transactions": [ + { + "id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "postings": [ + { + "id": 6, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Equity:NIFTY", + "commodity": "NIFTY", + "quantity": 800, + "amount": 80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + }, + { + "id": 5, + "transaction_id": "3", + "date": "2022-01-07T00:00:00Z", + "payee": "Investment", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": -80000, + "amount": -80000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 14, + "transaction_end_line": 17, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "tag_recurring": "", + "tag_period": "", + "beginLine": 14, + "endLine": 17, + "fileName": "main.ledger" + }, + { + "id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "postings": [ + { + "id": 4, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Expenses:Rent", + "commodity": "INR", + "quantity": 20000, + "amount": 20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + }, + { + "id": 3, + "transaction_id": "2", + "date": "2022-01-03T00:00:00Z", + "payee": "Rent", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": -20000, + "amount": -20000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 10, + "transaction_end_line": 13, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "tag_recurring": "", + "tag_period": "", + "beginLine": 10, + "endLine": 13, + "fileName": "main.ledger" + }, + { + "id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "postings": [ + { + "id": 2, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Assets:Checking", + "commodity": "INR", + "quantity": 100000, + "amount": 100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + }, + { + "id": 1, + "transaction_id": "1", + "date": "2022-01-01T00:00:00Z", + "payee": "Salary", + "account": "Income:Salary:Acme", + "commodity": "INR", + "quantity": -100000, + "amount": -100000, + "status": "unmarked", + "tag_recurring": "", + "tag_period": "", + "transaction_begin_line": 6, + "transaction_end_line": 9, + "file_name": "main.ledger", + "forecast": false, + "market_amount": 0 + } + ], + "tag_recurring": "", + "tag_period": "", + "beginLine": 6, + "endLine": 9, + "fileName": "main.ledger" + } + ] +} \ No newline at end of file diff --git a/tests/regression.test.ts b/tests/regression.test.ts new file mode 100644 index 00000000..76f8a5e3 --- /dev/null +++ b/tests/regression.test.ts @@ -0,0 +1,103 @@ +import { spawn } from "bun"; +import path from "path"; +import { describe, expect, test } from "bun:test"; +import waitPort from "wait-port"; +import fs from "fs"; +import axios from "axios"; +import { diffString } from "json-diff"; + +const fixture = "tests/fixture"; +const port = 5700; +axios.defaults.baseURL = `http://localhost:${port}`; + +function updateConfig(dir: string, from: string, to: string) { + const filename = path.join(dir, "paisa.yaml"); + let config = fs.readFileSync(filename).toString(); + config = config.replace(from, to); + fs.writeFileSync(filename, config); +} + +async function recordAndVerify(dir: string, route: string, name: string) { + const { data: data } = await axios.get(route); + + const filename = path.join(dir, name + ".json"); + if (fs.existsSync(filename) && process.env["REGENERATE"] !== "true") { + const current = JSON.parse(fs.readFileSync(filename).toString()); + const diff = diffString(data, current, { + excludeKeys: ["id", "transaction_id", "endLine", "transaction_end_line"] + }); + + if (diff != "") { + expect(current).toEqual(data); + } + } + fs.writeFileSync(filename, JSON.stringify(data, null, 2)); +} + +async function verifyApi(dir: string) { + const { + data: { success } + } = await axios.post("/api/sync", { journal: true }); + expect(success).toBe(true); + + await recordAndVerify(dir, "/api/dashboard", "dashboard"); + await recordAndVerify(dir, "/api/cash_flow", "cash_flow"); + await recordAndVerify(dir, "/api/expense", "expense"); + await recordAndVerify(dir, "/api/recurring", "recurring"); + await recordAndVerify(dir, "/api/budget", "budget"); + await recordAndVerify(dir, "/api/assets/balance", "assets_balance"); + await recordAndVerify(dir, "/api/networth", "networth"); + await recordAndVerify(dir, "/api/investment", "investment"); + await recordAndVerify(dir, "/api/gain", "gain"); + await recordAndVerify(dir, "/api/allocation", "allocation"); + await recordAndVerify(dir, "/api/liabilities/balance", "liabilities_balance"); + await recordAndVerify(dir, "/api/liabilities/repayment", "liabilities_repayment"); + await recordAndVerify(dir, "/api/liabilities/interest", "liabilities_interest"); + await recordAndVerify(dir, "/api/income", "income"); + await recordAndVerify(dir, "/api/transaction", "transaction"); + await recordAndVerify(dir, "/api/editor/files", "files"); + await recordAndVerify(dir, "/api/ledger", "ledger"); + await recordAndVerify(dir, "/api/price", "price"); + await recordAndVerify(dir, "/api/retirement/progress", "retirement"); + await recordAndVerify(dir, "/api/diagnosis", "diagnosis"); +} + +async function wait() { + try { + await waitPort({ port: port, output: "silent" }); + } catch (e) { + // ignore + } +} + +async function check(directory: string) { + const process = spawn([ + "./paisa", + "--config", + path.join(directory, "paisa.yaml"), + "--port", + port.toString(), + "--now", + "2022-02-07", + "serve" + ]); + try { + await wait(); + await verifyApi(directory); + } finally { + process.kill(); + await process.exited; + } +} + +describe("regression", () => { + fs.readdirSync(fixture).forEach((dir) => { + test(dir, async () => { + const directory = path.join(fixture, dir); + await check(directory); + updateConfig(directory, "ledger_cli: ledger", "ledger_cli: hledger"); + await check(directory); + updateConfig(directory, "ledger_cli: hledger", "ledger_cli: ledger"); + }); + }); +});