Skip to content

Commit

Permalink
fix: handle case when there are no aggregated lots
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Feb 15, 2021
1 parent 027aaf3 commit 8a8fd37
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
)

var (
Version string = "v3.1.4"
configPath string
dep c.Dependencies
ctx c.Context
options cli.Options
err error
rootCmd = &cobra.Command{
Version: "v3.1.3",
Version: Version,
Use: "ticker",
Short: "Terminal stock ticker and stock gain/loss tracker",
Args: cli.Validate(&ctx, &options, &err),
Expand Down
4 changes: 4 additions & 0 deletions internal/position/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func GetSymbols(symbols []string, aggregatedLots map[string]AggregatedLot) []str
func GetPositions(ctx c.Context, aggregatedLots map[string]AggregatedLot) func([]Quote) (map[string]Position, PositionSummary) {
return func(quotes []Quote) (map[string]Position, PositionSummary) {

if len(aggregatedLots) <= 0 {
return map[string]Position{}, PositionSummary{}
}

positionsReduced := (gubrak.
From(quotes).
Reduce(func(acc positionAcc, quote Quote) positionAcc {
Expand Down
21 changes: 21 additions & 0 deletions internal/position/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,26 @@ var _ = Describe("Position", func() {
}))
Expect(outputPositionSummary).To(Equal(expectedPositionSummary))
})

When("no aggregated lots are set", func() {
It("should return an empty positions and position summary", func() {
inputAggregatedLots := map[string]AggregatedLot{}
inputQuotes := []Quote{
{
ResponseQuote: ResponseQuote{
Symbol: "ARKW",
RegularMarketPreviousClose: 100,
},
Price: 120.0,
Change: 20.0,
},
}
inputCtx := c.Context{}
outputPositions, outputPositionSummary := GetPositions(inputCtx, inputAggregatedLots)(inputQuotes)
expectedPositionSummary := PositionSummary{}
Expect(outputPositions).To(Equal(map[string]Position{}))
Expect(outputPositionSummary).To(Equal(expectedPositionSummary))
})
})
})
})

0 comments on commit 8a8fd37

Please sign in to comment.