All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Signed-off-by: Asai Neko <sugar@sne.moe>
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package service_stats
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"nixcn-cms/testutil"
|
|
)
|
|
|
|
func TestGlobalStatsEmpty(t *testing.T) {
|
|
testutil.Setup(t)
|
|
|
|
svc := NewStatsService()
|
|
result := svc.Global(&GlobalStatsPayload{
|
|
Context: context.Background(),
|
|
})
|
|
|
|
assert.Equal(t, 200, result.Common.HttpCode)
|
|
require.NotNil(t, result.Data)
|
|
assert.Equal(t, int64(0), result.Data.TotalUsers)
|
|
assert.NotNil(t, result.Data.UsersPerLevel)
|
|
assert.Empty(t, *result.Data.UsersPerLevel)
|
|
}
|
|
|
|
func TestGlobalStatsWithData(t *testing.T) {
|
|
testutil.Setup(t)
|
|
ctx := context.Background()
|
|
|
|
for _, lvl := range []uint{10, 10, 30} {
|
|
testutil.SeedUser(t, testutil.RandomEmail(), lvl)
|
|
}
|
|
|
|
svc := NewStatsService()
|
|
result := svc.Global(&GlobalStatsPayload{
|
|
Context: ctx,
|
|
})
|
|
|
|
assert.Equal(t, 200, result.Common.HttpCode)
|
|
require.NotNil(t, result.Data)
|
|
assert.Equal(t, int64(3), result.Data.TotalUsers)
|
|
require.NotNil(t, result.Data.UsersPerLevel)
|
|
|
|
countMap := make(map[uint]int64)
|
|
for _, r := range *result.Data.UsersPerLevel {
|
|
countMap[r.PermissionLevel] = r.Count
|
|
}
|
|
assert.Equal(t, int64(2), countMap[10])
|
|
assert.Equal(t, int64(1), countMap[30])
|
|
}
|
|
|
|
func TestGlobalStatsEventJoinCheckinField(t *testing.T) {
|
|
testutil.Setup(t)
|
|
ctx := context.Background()
|
|
|
|
svc := NewStatsService()
|
|
result := svc.Global(&GlobalStatsPayload{Context: ctx})
|
|
|
|
assert.Equal(t, 200, result.Common.HttpCode)
|
|
require.NotNil(t, result.Data)
|
|
require.NotNil(t, result.Data.EventJoinCheckin, "EventJoinCheckin field must not be nil")
|
|
assert.Empty(t, *result.Data.EventJoinCheckin)
|
|
}
|