|
|
|
@ -5,16 +5,28 @@ |
|
|
|
|
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()) |
|
|
|
|
|
|
|
|
|
for _, tc := range testCases { |
|
|
|
|
|
|
|
|
|
// Insert some action
|
|
|
|
|
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) |
|
|
|
|
user := AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User) |
|
|
|
|
|
|
|
|
|
// get the action for comparison
|
|
|
|
|
actions, err := GetFeeds(GetFeedsOptions{ |
|
|
|
@ -30,4 +42,11 @@ func TestGetUserHeatmapDataByUser(t *testing.T) { |
|
|
|
|
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)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|