Skip to content

Commit

Permalink
fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Oct 7, 2023
1 parent 841f14c commit 593f35c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
4 changes: 3 additions & 1 deletion internal/server/gain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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})
}

Expand Down
64 changes: 32 additions & 32 deletions tests/fixture/inr/gain.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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
}
]
}
]
}

0 comments on commit 593f35c

Please sign in to comment.