Skip to content

Commit

Permalink
fix panic while unmarshaling into object.BaseLinkRating (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenCurs authored Oct 3, 2023
1 parent 7136f3f commit b2ba2c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ type BaseLinkProduct struct {

// BaseLinkRating struct.
type BaseLinkRating struct {
ReviewsCount int `json:"reviews_count"`
Stars float64 `json:"stars"`
ReviewsCount json.Number `json:"reviews_count"`
Stars float64 `json:"stars"`
}

// BasePlace struct.
Expand Down
11 changes: 11 additions & 0 deletions object/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package object_test

import (
"bytes"
"encoding/json"
"reflect"
"testing"

Expand Down Expand Up @@ -320,3 +321,13 @@ func TestBaseSticker_MinSizeBackground(t *testing.T) {
Width: 10, Height: 20,
})
}

func TestBaseLinkRating_UnmarshalJSON(t *testing.T) {

Check failure on line 325 in object/object_test.go

View workflow job for this annotation

GitHub Actions / lint

Function TestBaseLinkRating_UnmarshalJSON missing the call to method parallel
ratingJSON := []byte(`{"reviews_count":1.0,"stars":5.0}`)
var rating object.BaseLinkRating

Check failure on line 327 in object/object_test.go

View workflow job for this annotation

GitHub Actions / lint

declarations should never be cuddled (wsl)

assert.NoError(t, json.Unmarshal(ratingJSON, &rating))
review, _ := rating.ReviewsCount.Float64()
assert.Equal(t, 1.0, review)
assert.Equal(t, 5.0, rating.Stars)
}

0 comments on commit b2ba2c4

Please sign in to comment.