summaryrefslogtreecommitdiffstats
path: root/models/user_heatmap_test.go
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2018-10-24 15:17:21 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2018-10-24 21:17:21 +0800
commit70ad46133f123750edd3fa62bea229c083b8af26 (patch)
tree079c198e815271de31f170eb616229c229b2ef66 /models/user_heatmap_test.go
parent317ddb72830e11a361d3ca04647b98090b799fd5 (diff)
downloadgitea-70ad46133f123750edd3fa62bea229c083b8af26.tar.gz
gitea-70ad46133f123750edd3fa62bea229c083b8af26.zip
Fix JSON result of empty array (#5154)
Diffstat (limited to 'models/user_heatmap_test.go')
-rw-r--r--models/user_heatmap_test.go55
1 files changed, 37 insertions, 18 deletions
diff --git a/models/user_heatmap_test.go b/models/user_heatmap_test.go
index aeea427499..a71202d857 100644
--- a/models/user_heatmap_test.go
+++ b/models/user_heatmap_test.go
@@ -5,29 +5,48 @@
package models
import (
- "github.com/stretchr/testify/assert"
+ "encoding/json"
"testing"
+
+ "github.com/stretchr/testify/assert"
)
func TestGetUserHeatmapDataByUser(t *testing.T) {
+ testCases := []struct {
+ userID int64
+ CountResult int
+ JSONResult string
+ }{
+ {2, 1, `[{"timestamp":1540080000,"contributions":1}]`},
+ {3, 0, `[]`},
+ }
// Prepare
assert.NoError(t, PrepareTestDatabase())
- // Insert some action
- user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
-
- // get the action for comparison
- actions, err := GetFeeds(GetFeedsOptions{
- RequestedUser: user,
- RequestingUserID: user.ID,
- IncludePrivate: true,
- OnlyPerformedBy: false,
- IncludeDeleted: true,
- })
- assert.NoError(t, err)
-
- // Get the heatmap and compare
- heatmap, err := GetUserHeatmapDataByUser(user)
- assert.NoError(t, err)
- assert.Equal(t, len(actions), len(heatmap))
+ for _, tc := range testCases {
+
+ // Insert some action
+ user := AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User)
+
+ // get the action for comparison
+ actions, err := GetFeeds(GetFeedsOptions{
+ RequestedUser: user,
+ RequestingUserID: user.ID,
+ IncludePrivate: true,
+ OnlyPerformedBy: false,
+ IncludeDeleted: true,
+ })
+ assert.NoError(t, err)
+
+ // Get the heatmap and compare
+ heatmap, err := GetUserHeatmapDataByUser(user)
+ assert.NoError(t, err)
+ assert.Equal(t, len(actions), len(heatmap))
+ assert.Equal(t, tc.CountResult, len(heatmap))
+
+ //Test JSON rendering
+ jsonData, err := json.Marshal(heatmap)
+ assert.NoError(t, err)
+ assert.Equal(t, tc.JSONResult, string(jsonData))
+ }
}