From 593f35c4a6454cf777a434ca6a8c8bf88340b5c0 Mon Sep 17 00:00:00 2001 From: Anantha Kumaran Date: Sat, 7 Oct 2023 10:30:05 +0530 Subject: [PATCH] fix flaky test --- internal/server/gain.go | 4 ++- tests/fixture/inr/gain.json | 64 ++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/internal/server/gain.go b/internal/server/gain.go index 32d65c58..bbb12ce7 100644 --- a/internal/server/gain.go +++ b/internal/server/gain.go @@ -5,6 +5,7 @@ import ( "github.com/ananthakumaran/paisa/internal/query" "github.com/ananthakumaran/paisa/internal/server/assets" "github.com/ananthakumaran/paisa/internal/service" + "github.com/ananthakumaran/paisa/internal/utils" "github.com/gin-gonic/gin" "github.com/samber/lo" "github.com/shopspring/decimal" @@ -30,7 +31,8 @@ func GetGain(db *gorm.DB) gin.H { postings = service.PopulateMarketPrice(db, postings) byAccount := lo.GroupBy(postings, func(p posting.Posting) string { return p.Account }) var gains []Gain - for account, ps := range byAccount { + for _, account := range utils.SortedKeys(byAccount) { + ps := byAccount[account] gains = append(gains, Gain{Account: account, XIRR: service.XIRR(db, ps), Networth: computeNetworth(db, ps), Postings: ps}) } diff --git a/tests/fixture/inr/gain.json b/tests/fixture/inr/gain.json index b9a01fd7..6d098480 100644 --- a/tests/fixture/inr/gain.json +++ b/tests/fixture/inr/gain.json @@ -1,37 +1,5 @@ { "gain_breakdown": [ - { - "account": "Assets:Equity:NIFTY", - "networth": { - "date": "2022-02-07T23:59:59.999999999Z", - "investmentAmount": 80000, - "withdrawalAmount": 0, - "gainAmount": 800, - "balanceAmount": 80800, - "netInvestmentAmount": 80000 - }, - "xirr": 12.02, - "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": 80800 - } - ] - }, { "account": "Assets:Equity:ABNB", "networth": { @@ -63,6 +31,38 @@ "market_amount": 8025.3170071296 } ] + }, + { + "account": "Assets:Equity:NIFTY", + "networth": { + "date": "2022-02-07T23:59:59.999999999Z", + "investmentAmount": 80000, + "withdrawalAmount": 0, + "gainAmount": 800, + "balanceAmount": 80800, + "netInvestmentAmount": 80000 + }, + "xirr": 12.02, + "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": 80800 + } + ] } ] } \ No newline at end of file