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,
16 } from '../../../../shared/extra-utils'
17 import { setAccessTokensToServers } from '../../../../shared/extra-utils/index'
18 import { getStats } from '../../../../shared/extra-utils/server/stats'
19 import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
20 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22 const expect = chai.expect
24 describe('Test stats (excluding redundancy)', function () {
25 let servers: ServerInfo[] = []
27 before(async function () {
29 servers = await flushAndRunMultipleServers(3)
30 await setAccessTokensToServers(servers)
32 await doubleFollow(servers[0], servers[1])
36 password: 'super_password'
38 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
40 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
41 const videoUUID = resVideo.body.video.uuid
43 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
45 await viewVideo(servers[0].url, videoUUID)
47 // Wait the video views repeatable job
50 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
51 await waitJobs(servers)
54 it('Should have the correct stats on instance 1', async function () {
55 const res = await getStats(servers[0].url)
56 const data: ServerStats = res.body
58 expect(data.totalLocalVideoComments).to.equal(1)
59 expect(data.totalLocalVideos).to.equal(1)
60 expect(data.totalLocalVideoViews).to.equal(1)
61 expect(data.totalLocalVideoFilesSize).to.equal(218910)
62 expect(data.totalUsers).to.equal(2)
63 expect(data.totalVideoComments).to.equal(1)
64 expect(data.totalVideos).to.equal(1)
65 expect(data.totalInstanceFollowers).to.equal(2)
66 expect(data.totalInstanceFollowing).to.equal(1)
69 it('Should have the correct stats on instance 2', async function () {
70 const res = await getStats(servers[1].url)
71 const data: ServerStats = res.body
73 expect(data.totalLocalVideoComments).to.equal(0)
74 expect(data.totalLocalVideos).to.equal(0)
75 expect(data.totalLocalVideoViews).to.equal(0)
76 expect(data.totalLocalVideoFilesSize).to.equal(0)
77 expect(data.totalUsers).to.equal(1)
78 expect(data.totalVideoComments).to.equal(1)
79 expect(data.totalVideos).to.equal(1)
80 expect(data.totalInstanceFollowers).to.equal(1)
81 expect(data.totalInstanceFollowing).to.equal(1)
84 it('Should have the correct stats on instance 3', async function () {
85 const res = await getStats(servers[2].url)
86 const data: ServerStats = res.body
88 expect(data.totalLocalVideoComments).to.equal(0)
89 expect(data.totalLocalVideos).to.equal(0)
90 expect(data.totalLocalVideoViews).to.equal(0)
91 expect(data.totalUsers).to.equal(1)
92 expect(data.totalVideoComments).to.equal(1)
93 expect(data.totalVideos).to.equal(1)
94 expect(data.totalInstanceFollowing).to.equal(1)
95 expect(data.totalInstanceFollowers).to.equal(0)
98 it('Should have the correct total videos stats after an unfollow', async function () {
99 await unfollow(servers[2].url, servers[2].accessToken, servers[0])
100 await waitJobs(servers)
102 const res = await getStats(servers[2].url)
103 const data: ServerStats = res.body
105 expect(data.totalVideos).to.equal(0)
108 after(async function () {
109 await cleanupTests(servers)