From 6a935ffbdbd0dcfaac0f29ab1e404b4544c46be4 Mon Sep 17 00:00:00 2001 From: yagiz Date: Thu, 10 Dec 2020 20:29:38 +0300 Subject: [PATCH 1/2] Fix: change the logic of equality checking for IDs, instead check does ID contains prefix of Widget's ID --- gogtrends.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gogtrends.go b/gogtrends.go index 3bc0f87..bb152b4 100644 --- a/gogtrends.go +++ b/gogtrends.go @@ -163,7 +163,7 @@ func Explore(ctx context.Context, r *ExploreRequest, hl string) ([]*ExploreWidge // InterestOverTime as list of `Timeline` dots for chart. func InterestOverTime(ctx context.Context, w *ExploreWidget, hl string) ([]*Timeline, error) { - if w.ID != intOverTimeWidgetID { + if !strings.HasPrefix(w.ID, intOverTimeWidgetID) { return nil, ErrInvalidWidgetType } @@ -207,7 +207,7 @@ func InterestOverTime(ctx context.Context, w *ExploreWidget, hl string) ([]*Time // InterestByLocation as list of `GeoMap`, with geo codes and interest values. func InterestByLocation(ctx context.Context, w *ExploreWidget, hl string) ([]*GeoMap, error) { - if w.ID != intOverRegionID { + if !strings.HasPrefix(w.ID, intOverRegionID) { return nil, ErrInvalidWidgetType } @@ -249,7 +249,7 @@ func InterestByLocation(ctx context.Context, w *ExploreWidget, hl string) ([]*Ge // Related topics or queries, list of `RankedKeyword`, supports two types of widgets. func Related(ctx context.Context, w *ExploreWidget, hl string) ([]*RankedKeyword, error) { - if w.ID != relatedQueriesID && w.ID != relatedTopicsID { + if !strings.HasPrefix(w.ID, relatedQueriesID) && !strings.HasPrefix(w.ID, relatedTopicsID) { return nil, ErrInvalidWidgetType } From 2769759dd6ec6c11c4e44acad9e23d296ceb1ac4 Mon Sep 17 00:00:00 2001 From: Yagiz Degirmenci Date: Mon, 11 Jan 2021 11:44:28 +0300 Subject: [PATCH 2/2] test: add test case for multiple comparasion items --- gogtrends_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/gogtrends_test.go b/gogtrends_test.go index 84dec12..5158d4c 100644 --- a/gogtrends_test.go +++ b/gogtrends_test.go @@ -403,3 +403,46 @@ func TestCompareInterestConcurrent(t *testing.T) { }() } } + +func TestMultipleComparisonItems(t *testing.T) { + req := &ExploreRequest{ + ComparisonItems: []*ComparisonItem{ + { + Keyword: "Golang", + Geo: locUS, + Time: "today 12-m", + }, + { + Keyword: "Python", + Geo: locUS, + Time: "today 12-m", + }, + }, + Category: catProgramming, + Property: "", + } + + explore, err := Explore(context.Background(), req, langEN) + assert.NoError(t, err) + + // Interest overtime for first keyword + overTime, err := InterestOverTime(context.Background(), explore[0], langEN) + assert.NoError(t, err) + assert.True(t, len(overTime) > 0) + + // Interest by location for first keyword + byLoc, err := InterestByLocation(context.Background(), explore[1], langEN) + assert.NoError(t, err) + assert.True(t, len(byLoc) > 0) + + // Interest overtime for second keyword + overTime, err = InterestOverTime(context.Background(), explore[3], langEN) + assert.NoError(t, err) + assert.True(t, len(overTime) > 0) + + // Interest by location for second keyword + byLoc, err = InterestByLocation(context.Background(), explore[4], langEN) + assert.NoError(t, err) + assert.True(t, len(byLoc) > 0) + +}