72168aa8fa
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
|
auth_model "code.gitea.io/gitea/models/auth"
|
|
"code.gitea.io/gitea/models/db"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
"code.gitea.io/gitea/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestUserHeatmap(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
adminUsername := "user1"
|
|
normalUsername := "user2"
|
|
token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeReadUser)
|
|
|
|
fakeNow := time.Date(2011, 10, 21, 0, 0, 0, 0, time.Local)
|
|
timeutil.MockSet(fakeNow)
|
|
defer timeutil.MockUnset()
|
|
|
|
require.NoError(t, db.TruncateBeans(t.Context(), &activities_model.HeatmapContribution{}))
|
|
require.NoError(t, user_model.SetIncludePrivateContributions(t.Context(), 2, false))
|
|
testHeatmapSeedContribution(t, 2, 1, "api-user2-public-author-date", 1319068800)
|
|
testHeatmapSeedContribution(t, 2, 1, "api-user2-public-same-bucket", 1319068850)
|
|
testHeatmapSeedContribution(t, 2, 2, "api-user2-private-hidden", 1319070600)
|
|
|
|
req := NewRequestf(t, "GET", "/api/v1/users/%s/heatmap", normalUsername).
|
|
AddTokenAuth(token)
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
var heatmap []*activities_model.UserHeatmapData
|
|
DecodeJSON(t, resp, &heatmap)
|
|
|
|
assert.Equal(t, []*activities_model.UserHeatmapData{
|
|
{Timestamp: 1319068800, Contributions: 2},
|
|
}, heatmap)
|
|
}
|