Skip to content

Commit

Permalink
fix: show regular market price when there is no post market price
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Feb 11, 2021
1 parent 7588ef6 commit efb3fff
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
11 changes: 11 additions & 0 deletions internal/quote/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ func transformResponseQuote(responseQuote ResponseQuote) Quote {
}
}

if responseQuote.MarketState == "POST" && responseQuote.PostMarketPrice == 0.0 {
return Quote{
ResponseQuote: responseQuote,
Price: responseQuote.RegularMarketPrice,
Change: responseQuote.RegularMarketChange,
ChangePercent: responseQuote.RegularMarketChangePercent,
IsActive: true,
IsRegularTradingSession: false,
}
}

if responseQuote.MarketState == "POST" {
return Quote{
ResponseQuote: responseQuote,
Expand Down
38 changes: 37 additions & 1 deletion internal/quote/quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,45 @@ var _ = Describe("Quote", func() {
}
Expect(output).To(Equal(expected))
})

When("there is no post-market price", func() {
It("should return the regular market price", func() {
responseFixture := `{
"quoteResponse": {
"result": [
{
"marketState": "POST",
"shortName": "Cloudflare, Inc.",
"regularMarketChange": 3.0800018,
"regularMarketChangePercent": 3.7606857,
"regularMarketTime": 1608832801,
"regularMarketPrice": 84.98,
"regularMarketPreviousClose": 81.9,
"symbol": "NET"
}
],
"error": null
}
}`
responseUrl := "https://query1.finance.yahoo.com/v7/finance/quote?lang=en-US&region=US&corsDomain=finance.yahoo.com&symbols=NET"
httpmock.RegisterResponder("GET", responseUrl, func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, responseFixture)
resp.Header.Set("Content-Type", "application/json")
return resp, nil
})

output := GetQuotes(*client, []string{"NET"})()
expectedPrice := 84.98
expectedChange := 3.0800018
expectedChangePercent := 3.7606857
Expect(output[0].Price).To(Equal(expectedPrice))
Expect(output[0].Change).To(Equal(expectedChange))
Expect(output[0].ChangePercent).To(Equal(expectedChangePercent))
})
})
})

When("the market is CLOSED", func() {
When("the market is closed", func() {
It("should return the post-market price added to the regular market price", func() {
responseFixture := `{
"quoteResponse": {
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ = Describe("Util", func() {
})
It("should generate text for values", func() {
output := ValueText(435.32)
expectedOutput := NewStyle("#d4d4d4", "", false)("435.32")
expectedOutput := NewStyle("#d0d0d0", "", false)("435.32")
Expect(output).To(Equal(expectedOutput))
})
})
Expand Down

0 comments on commit efb3fff

Please sign in to comment.