forked from forgejo/forgejo
Fix heatmap activity (#15252)
* Group heatmap actions by 15 minute intervals Signed-off-by: Sidd Weiker <siddweiker@gmail.com> * Add multi-contribution test for user heatmap Signed-off-by: Sidd Weiker <siddweiker@gmail.com> * Add timezone aware summation for activity heatmap Signed-off-by: Sidd Weiker <siddweiker@gmail.com> * Fix api user heatmap test Signed-off-by: Sidd Weiker <siddweiker@gmail.com> * Update variable declaration style Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
3ef23d5411
commit
f573e93ed4
5 changed files with 58 additions and 18 deletions
|
@ -19,12 +19,20 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
|
|||
CountResult int
|
||||
JSONResult string
|
||||
}{
|
||||
{2, 2, 1, `[{"timestamp":1603152000,"contributions":1}]`}, // self looks at action in private repo
|
||||
{2, 1, 1, `[{"timestamp":1603152000,"contributions":1}]`}, // admin looks at action in private repo
|
||||
{2, 3, 0, `[]`}, // other user looks at action in private repo
|
||||
{2, 0, 0, `[]`}, // nobody looks at action in private repo
|
||||
{16, 15, 1, `[{"timestamp":1603238400,"contributions":1}]`}, // collaborator looks at action in private repo
|
||||
{3, 3, 0, `[]`}, // no action action not performed by target user
|
||||
// self looks at action in private repo
|
||||
{2, 2, 1, `[{"timestamp":1603227600,"contributions":1}]`},
|
||||
// admin looks at action in private repo
|
||||
{2, 1, 1, `[{"timestamp":1603227600,"contributions":1}]`},
|
||||
// other user looks at action in private repo
|
||||
{2, 3, 0, `[]`},
|
||||
// nobody looks at action in private repo
|
||||
{2, 0, 0, `[]`},
|
||||
// collaborator looks at action in private repo
|
||||
{16, 15, 1, `[{"timestamp":1603267200,"contributions":1}]`},
|
||||
// no action action not performed by target user
|
||||
{3, 3, 0, `[]`},
|
||||
// multiple actions performed with two grouped together
|
||||
{10, 10, 3, `[{"timestamp":1603009800,"contributions":1},{"timestamp":1603010700,"contributions":2}]`},
|
||||
}
|
||||
// Prepare
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
@ -51,9 +59,13 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
|
|||
|
||||
// Get the heatmap and compare
|
||||
heatmap, err := GetUserHeatmapDataByUser(user, doer)
|
||||
var contributions int
|
||||
for _, hm := range heatmap {
|
||||
contributions += int(hm.Contributions)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, heatmap, len(actions), "invalid action count: did the test data became too old?")
|
||||
assert.Len(t, heatmap, tc.CountResult, fmt.Sprintf("testcase %d", i))
|
||||
assert.Len(t, actions, contributions, "invalid action count: did the test data became too old?")
|
||||
assert.Equal(t, tc.CountResult, contributions, fmt.Sprintf("testcase %d", i))
|
||||
|
||||
// Test JSON rendering
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue