code.gitea.io/gitea@v1.21.7/tests/integration/api_user_heatmap_test.go (about) 1 // Copyright 2018 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package integration 5 6 import ( 7 "fmt" 8 "net/http" 9 "testing" 10 "time" 11 12 activities_model "code.gitea.io/gitea/models/activities" 13 auth_model "code.gitea.io/gitea/models/auth" 14 "code.gitea.io/gitea/modules/timeutil" 15 "code.gitea.io/gitea/tests" 16 17 "github.com/stretchr/testify/assert" 18 ) 19 20 func TestUserHeatmap(t *testing.T) { 21 defer tests.PrepareTestEnv(t)() 22 adminUsername := "user1" 23 normalUsername := "user2" 24 token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeReadUser) 25 26 fakeNow := time.Date(2011, 10, 20, 0, 0, 0, 0, time.Local) 27 timeutil.Set(fakeNow) 28 defer timeutil.Unset() 29 30 urlStr := fmt.Sprintf("/api/v1/users/%s/heatmap?token=%s", normalUsername, token) 31 req := NewRequest(t, "GET", urlStr) 32 resp := MakeRequest(t, req, http.StatusOK) 33 var heatmap []*activities_model.UserHeatmapData 34 DecodeJSON(t, resp, &heatmap) 35 var dummyheatmap []*activities_model.UserHeatmapData 36 dummyheatmap = append(dummyheatmap, &activities_model.UserHeatmapData{Timestamp: 1603227600, Contributions: 1}) 37 38 assert.Equal(t, dummyheatmap, heatmap) 39 }