Skip to content

Commit

Permalink
Merge pull request #17 from ycd/master
Browse files Browse the repository at this point in the history
Fix: change the logic of equality checking for Widget IDs
  • Loading branch information
groovili committed Jan 11, 2021
2 parents bfe9031 + 2769759 commit 6589704
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gogtrends.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
43 changes: 43 additions & 0 deletions gogtrends_test.go
Expand Up @@ -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)

}

0 comments on commit 6589704

Please sign in to comment.