2018-10-22 21:57:42 -05:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.package models
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2018-10-24 08:17:21 -05:00
|
|
|
"encoding/json"
|
2018-10-22 21:57:42 -05:00
|
|
|
"testing"
|
2018-10-24 08:17:21 -05:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-10-22 21:57:42 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetUserHeatmapDataByUser(t *testing.T) {
|
2018-10-24 08:17:21 -05:00
|
|
|
testCases := []struct {
|
|
|
|
userID int64
|
|
|
|
CountResult int
|
|
|
|
JSONResult string
|
|
|
|
}{
|
|
|
|
{2, 1, `[{"timestamp":1540080000,"contributions":1}]`},
|
|
|
|
{3, 0, `[]`},
|
|
|
|
}
|
2018-10-22 21:57:42 -05:00
|
|
|
// Prepare
|
|
|
|
assert.NoError(t, PrepareTestDatabase())
|
|
|
|
|
2018-10-24 08:17:21 -05:00
|
|
|
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))
|
|
|
|
}
|
2018-10-22 21:57:42 -05:00
|
|
|
}
|