1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 import { ServerStats } from '../../../../shared/models/server/server-stats.model'
10 flushAndRunMultipleServers,
17 } from '../../../../shared/extra-utils'
18 import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
19 import { getStats } from '../../../../shared/extra-utils/server/stats'
20 import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
21 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23 const expect = chai.expect
25 describe('Test stats (excluding redundancy)', function () {
26 let servers: ServerInfo[] = []
29 password: 'super_password'
32 before(async function () {
34 servers = await flushAndRunMultipleServers(3)
35 await setAccessTokensToServers(servers)
37 await doubleFollow(servers[0], servers[1])
39 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
41 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
42 const videoUUID = resVideo.body.video.uuid
44 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
46 await viewVideo(servers[0].url, videoUUID)
48 // Wait the video views repeatable job
51 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
52 await waitJobs(servers)
55 it('Should have the correct stats on instance 1', async function () {
56 const res = await getStats(servers[0].url)
57 const data: ServerStats = res.body
59 expect(data.totalLocalVideoComments).to.equal(1)
60 expect(data.totalLocalVideos).to.equal(1)
61 expect(data.totalLocalVideoViews).to.equal(1)
62 expect(data.totalLocalVideoFilesSize).to.equal(218910)
63 expect(data.totalUsers).to.equal(2)
64 expect(data.totalVideoComments).to.equal(1)
65 expect(data.totalVideos).to.equal(1)
66 expect(data.totalInstanceFollowers).to.equal(2)
67 expect(data.totalInstanceFollowing).to.equal(1)
70 it('Should have the correct stats on instance 2', async function () {
71 const res = await getStats(servers[1].url)
72 const data: ServerStats = res.body
74 expect(data.totalLocalVideoComments).to.equal(0)
75 expect(data.totalLocalVideos).to.equal(0)
76 expect(data.totalLocalVideoViews).to.equal(0)
77 expect(data.totalLocalVideoFilesSize).to.equal(0)
78 expect(data.totalUsers).to.equal(1)
79 expect(data.totalVideoComments).to.equal(1)
80 expect(data.totalVideos).to.equal(1)
81 expect(data.totalInstanceFollowers).to.equal(1)
82 expect(data.totalInstanceFollowing).to.equal(1)
85 it('Should have the correct stats on instance 3', async function () {
86 const res = await getStats(servers[2].url)
87 const data: ServerStats = res.body
89 expect(data.totalLocalVideoComments).to.equal(0)
90 expect(data.totalLocalVideos).to.equal(0)
91 expect(data.totalLocalVideoViews).to.equal(0)
92 expect(data.totalUsers).to.equal(1)
93 expect(data.totalVideoComments).to.equal(1)
94 expect(data.totalVideos).to.equal(1)
95 expect(data.totalInstanceFollowing).to.equal(1)
96 expect(data.totalInstanceFollowers).to.equal(0)
99 it('Should have the correct total videos stats after an unfollow', async function () {
102 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
103 await waitJobs(servers)
105 const res = await getStats(servers[2].url)
106 const data: ServerStats = res.body
108 expect(data.totalVideos).to.equal(0)
111 it('Should have the correct active users stats', async function () {
112 const server = servers[0]
115 const res = await getStats(server.url)
116 const data: ServerStats = res.body
117 expect(data.totalDailyActiveUsers).to.equal(1)
118 expect(data.totalWeeklyActiveUsers).to.equal(1)
119 expect(data.totalMonthlyActiveUsers).to.equal(1)
123 await userLogin(server, user)
125 const res = await getStats(server.url)
126 const data: ServerStats = res.body
127 expect(data.totalDailyActiveUsers).to.equal(2)
128 expect(data.totalWeeklyActiveUsers).to.equal(2)
129 expect(data.totalMonthlyActiveUsers).to.equal(2)
133 after(async function () {
134 await cleanupTests(servers)