Skip to content

Commit

Permalink
test: fixed failing tests related to Yahoo API changes and fixed pani…
Browse files Browse the repository at this point in the history
…c on test failure for quote tests
  • Loading branch information
achannarasappa committed Feb 18, 2023
1 parent e4fca96 commit c6ba5e5
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 75 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/achannarasappa/ticker

go 1.17
go 1.18

require (
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
Expand Down Expand Up @@ -44,7 +44,7 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/consul/api v1.11.0/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M=
github.com/hashicorp/consul/api v1.12.0/go.mod h1:6pVBMo0ebnYdt2S3H87XhekM/HHrUoTD2XXb/VrZVy0=
github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down Expand Up @@ -382,7 +381,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43MRiaGWX1Nig=
github.com/sagikazarmark/crypt v0.4.0/go.mod h1:ALv2SRj7GxYV4HO9elxH9nS6M9gW+xDNxqmyJ6RfDFM=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down Expand Up @@ -639,10 +637,8 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
Expand Down Expand Up @@ -752,7 +748,6 @@ google.golang.org/api v0.57.0/go.mod h1:dVPlbZyBo2/OjBpmvNdpn2GRm6rPy75jyU7bmhdr
google.golang.org/api v0.59.0/go.mod h1:sT2boj7M9YJxZzgeZqXogmhfmRWDtPzT31xkieUbuZU=
google.golang.org/api v0.61.0/go.mod h1:xQRti5UdCmoCEqFxcz93fTl338AVqDgyaDRuOZ3hg9I=
google.golang.org/api v0.62.0/go.mod h1:dKmwPCydfsad4qCH08MSdgWjfHOyfpd4VtDGgRFdavw=
google.golang.org/api v0.63.0/go.mod h1:gs4ij2ffTRXwuzzgJl/56BdwJaA194ijkfn++9tDuPo=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down Expand Up @@ -852,7 +847,6 @@ google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnD
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down
2 changes: 1 addition & 1 deletion internal/currency/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type CurrencyRateByUse struct { //nolint:golint,revive
// GetCurrencyRateFromContext reads currency rates from the context and sets the conversion rate for each use case
func GetCurrencyRateFromContext(ctx c.Context, fromCurrency string) CurrencyRateByUse {

// If currency is convertable
// If currency is convertible
if currencyRate, ok := ctx.Reference.CurrencyRates[fromCurrency]; ok {

currencyRateCost := currencyRate.Rate
Expand Down
29 changes: 19 additions & 10 deletions internal/quote/coingecko/coingecko_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

c "github.com/achannarasappa/ticker/internal/common"
. "github.com/achannarasappa/ticker/internal/quote/coingecko"
g "github.com/onsi/gomega/gstruct"
)

var _ = Describe("Coingecko", func() {
Expand Down Expand Up @@ -54,16 +55,24 @@ var _ = Describe("Coingecko", func() {
})

output := GetAssetQuotes(*client, []string{"bitcoin"})
Expect(output[0].QuotePrice.Price).To(Equal(39045.0))
Expect(output[0].QuotePrice.PricePrevClose).To(Equal(40023.048909591314))
Expect(output[0].QuotePrice.PriceOpen).To(Equal(0.0))
Expect(output[0].QuotePrice.PriceDayHigh).To(Equal(40090.0))
Expect(output[0].QuotePrice.PriceDayLow).To(Equal(38195.0))
Expect(output[0].QuotePrice.Change).To(Equal(-978.048909591315))
Expect(output[0].QuotePrice.ChangePercent).To(Equal(-2.44373))
Expect(output[0].QuoteSource).To(Equal(c.QuoteSourceCoingecko))
Expect(output[0].Exchange.IsActive).To(BeTrue())
Expect(output[0].Exchange.IsRegularTradingSession).To(BeTrue())
Expect(output).To(g.MatchAllElementsWithIndex(g.IndexIdentity, g.Elements{
"0": g.MatchFields(g.IgnoreExtras, g.Fields{
"QuotePrice": g.MatchFields(g.IgnoreExtras, g.Fields{
"Price": Equal(39045.0),
"PricePrevClose": Equal(40023.048909591314),
"PriceOpen": Equal(0.0),
"PriceDayHigh": Equal(40090.0),
"PriceDayLow": Equal(38195.0),
"Change": Equal(-978.048909591315),
"ChangePercent": Equal(-2.44373),
}),
"QuoteSource": Equal(c.QuoteSourceCoingecko),
"Exchange": g.MatchFields(g.IgnoreExtras, g.Fields{
"IsActive": BeTrue(),
"IsRegularTradingSession": BeTrue(),
}),
}),
}))
})

})
Expand Down
4 changes: 3 additions & 1 deletion internal/quote/quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ var _ = Describe("Quote", func() {
}
output := GetAssetGroupQuote(dep)(input)

Expect(output.AssetQuotes).To(HaveLen(2))
Expect(output).To(g.MatchFields(g.IgnoreExtras, g.Fields{
"AssetQuotes": HaveLen(2),
}))

})

Expand Down
9 changes: 7 additions & 2 deletions internal/quote/yahoo/quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/go-resty/resty/v2"
)

//nolint:gochecknoglobals
var (
postMarketStatuses = map[string]bool{"POST": true, "POSTPOST": true}
)

// ResponseQuote represents a quote of a single security from the API response
type ResponseQuote struct {
ShortName string `json:"shortName"`
Expand Down Expand Up @@ -99,7 +104,7 @@ func transformResponseQuote(responseQuote ResponseQuote) c.AssetQuote {
return assetQuote
}

if responseQuote.MarketState == "POSTPOST" && responseQuote.PostMarketPrice == 0.0 {
if _, exists := postMarketStatuses[responseQuote.MarketState]; exists && responseQuote.PostMarketPrice == 0.0 {
assetQuote.Exchange.IsRegularTradingSession = false

return assetQuote
Expand All @@ -112,7 +117,7 @@ func transformResponseQuote(responseQuote ResponseQuote) c.AssetQuote {
return assetQuote
}

if responseQuote.MarketState == "POSTPOST" {
if _, exists := postMarketStatuses[responseQuote.MarketState]; exists {
assetQuote.QuotePrice.Price = responseQuote.PostMarketPrice
assetQuote.QuotePrice.Change = (responseQuote.PostMarketChange + responseQuote.RegularMarketChange)
assetQuote.QuotePrice.ChangePercent = responseQuote.PostMarketChangePercent + responseQuote.RegularMarketChangePercent
Expand Down
Loading

0 comments on commit c6ba5e5

Please sign in to comment.