aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2021-04-12 11:19:07 +0200
committerGitHub <noreply@github.com>2021-04-12 11:19:07 +0200
commitfe19f600dab0f6b00a7aa146ba4bd4bb96536155 (patch)
treebe388f89a41cbc257fc9a642a9205b4910b7a6b7 /server/tests
parenta472cf033003cf96b69a80808b2dce1fe382e09b (diff)
downloadPeerTube-fe19f600dab0f6b00a7aa146ba4bd4bb96536155.tar.gz
PeerTube-fe19f600dab0f6b00a7aa146ba4bd4bb96536155.tar.zst
PeerTube-fe19f600dab0f6b00a7aa146ba4bd4bb96536155.zip
add channel and playlist stats to server stats endpoint (#3747)
* add channel and playlist stats to nodeinfo * add tests for active video channels stats * fix tests for active channel stats
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/server/stats.ts76
1 files changed, 73 insertions, 3 deletions
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index eb474c1f5..304181a6d 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -3,8 +3,10 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 addVideoChannel,
6 cleanupTests, 7 cleanupTests,
7 createUser, 8 createUser,
9 createVideoPlaylist,
8 doubleFollow, 10 doubleFollow,
9 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
10 follow, 12 follow,
@@ -21,12 +23,14 @@ import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21import { getStats } from '../../../../shared/extra-utils/server/stats' 23import { getStats } from '../../../../shared/extra-utils/server/stats'
22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' 24import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
23import { ServerStats } from '../../../../shared/models/server/server-stats.model' 25import { ServerStats } from '../../../../shared/models/server/server-stats.model'
26import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
24import { ActivityType } from '@shared/models' 27import { ActivityType } from '@shared/models'
25 28
26const expect = chai.expect 29const expect = chai.expect
27 30
28describe('Test stats (excluding redundancy)', function () { 31describe('Test stats (excluding redundancy)', function () {
29 let servers: ServerInfo[] = [] 32 let servers: ServerInfo[] = []
33 let channelId
30 const user = { 34 const user = {
31 username: 'user1', 35 username: 'user1',
32 password: 'super_password' 36 password: 'super_password'
@@ -70,6 +74,7 @@ describe('Test stats (excluding redundancy)', function () {
70 expect(data.totalVideos).to.equal(1) 74 expect(data.totalVideos).to.equal(1)
71 expect(data.totalInstanceFollowers).to.equal(2) 75 expect(data.totalInstanceFollowers).to.equal(2)
72 expect(data.totalInstanceFollowing).to.equal(1) 76 expect(data.totalInstanceFollowing).to.equal(1)
77 expect(data.totalLocalPlaylists).to.equal(0)
73 }) 78 })
74 79
75 it('Should have the correct stats on instance 2', async function () { 80 it('Should have the correct stats on instance 2', async function () {
@@ -85,6 +90,7 @@ describe('Test stats (excluding redundancy)', function () {
85 expect(data.totalVideos).to.equal(1) 90 expect(data.totalVideos).to.equal(1)
86 expect(data.totalInstanceFollowers).to.equal(1) 91 expect(data.totalInstanceFollowers).to.equal(1)
87 expect(data.totalInstanceFollowing).to.equal(1) 92 expect(data.totalInstanceFollowing).to.equal(1)
93 expect(data.totalLocalPlaylists).to.equal(0)
88 }) 94 })
89 95
90 it('Should have the correct stats on instance 3', async function () { 96 it('Should have the correct stats on instance 3', async function () {
@@ -99,6 +105,7 @@ describe('Test stats (excluding redundancy)', function () {
99 expect(data.totalVideos).to.equal(1) 105 expect(data.totalVideos).to.equal(1)
100 expect(data.totalInstanceFollowing).to.equal(1) 106 expect(data.totalInstanceFollowing).to.equal(1)
101 expect(data.totalInstanceFollowers).to.equal(0) 107 expect(data.totalInstanceFollowers).to.equal(0)
108 expect(data.totalLocalPlaylists).to.equal(0)
102 }) 109 })
103 110
104 it('Should have the correct total videos stats after an unfollow', async function () { 111 it('Should have the correct total videos stats after an unfollow', async function () {
@@ -113,7 +120,7 @@ describe('Test stats (excluding redundancy)', function () {
113 expect(data.totalVideos).to.equal(0) 120 expect(data.totalVideos).to.equal(0)
114 }) 121 })
115 122
116 it('Should have the correct active users stats', async function () { 123 it('Should have the correct active user stats', async function () {
117 const server = servers[0] 124 const server = servers[0]
118 125
119 { 126 {
@@ -135,6 +142,69 @@ describe('Test stats (excluding redundancy)', function () {
135 } 142 }
136 }) 143 })
137 144
145 it('Should have the correct active channel stats', async function () {
146 const server = servers[0]
147
148 {
149 const res = await getStats(server.url)
150 const data: ServerStats = res.body
151 expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
152 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
153 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1)
154 }
155
156 {
157 const channelAttributes = {
158 name: 'stats_channel',
159 displayName: 'My stats channel'
160 }
161 const resChannel = await addVideoChannel(server.url, server.accessToken, channelAttributes)
162 channelId = resChannel.body.videoChannel.id
163
164 const res = await getStats(server.url)
165 const data: ServerStats = res.body
166 expect(data.totalLocalDailyActiveVideoChannels).to.equal(1)
167 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(1)
168 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(1)
169 }
170
171 {
172 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.webm', channelId })
173
174 const res = await getStats(server.url)
175 const data: ServerStats = res.body
176 expect(data.totalLocalDailyActiveVideoChannels).to.equal(2)
177 expect(data.totalLocalWeeklyActiveVideoChannels).to.equal(2)
178 expect(data.totalLocalMonthlyActiveVideoChannels).to.equal(2)
179 }
180 })
181
182 it('Should have the correct playlist stats', async function () {
183 const server = servers[0]
184
185 {
186 const resStats = await getStats(server.url)
187 const dataStats: ServerStats = resStats.body
188 expect(dataStats.totalLocalPlaylists).to.equal(0)
189 }
190
191 {
192 await createVideoPlaylist({
193 url: server.url,
194 token: server.accessToken,
195 playlistAttrs: {
196 displayName: 'playlist for count',
197 privacy: VideoPlaylistPrivacy.PUBLIC,
198 videoChannelId: channelId
199 }
200 })
201
202 const resStats = await getStats(server.url)
203 const dataStats: ServerStats = resStats.body
204 expect(dataStats.totalLocalPlaylists).to.equal(1)
205 }
206 })
207
138 it('Should correctly count video file sizes if transcoding is enabled', async function () { 208 it('Should correctly count video file sizes if transcoding is enabled', async function () {
139 this.timeout(60000) 209 this.timeout(60000)
140 210
@@ -173,8 +243,8 @@ describe('Test stats (excluding redundancy)', function () {
173 { 243 {
174 const res = await getStats(servers[0].url) 244 const res = await getStats(servers[0].url)
175 const data: ServerStats = res.body 245 const data: ServerStats = res.body
176 expect(data.totalLocalVideoFilesSize).to.be.greaterThan(300000) 246 expect(data.totalLocalVideoFilesSize).to.be.greaterThan(500000)
177 expect(data.totalLocalVideoFilesSize).to.be.lessThan(400000) 247 expect(data.totalLocalVideoFilesSize).to.be.lessThan(600000)
178 } 248 }
179 }) 249 })
180 250