1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { ServerStats } from '../../../../shared/models/server/server-stats.model'
9 flushAndRunMultipleServers,
16 } from '../../../../shared/utils'
17 import { flushTests, setAccessTokensToServers } from '../../../../shared/utils/index'
18 import { getStats } from '../../../../shared/utils/server/stats'
19 import { addVideoCommentThread } from '../../../../shared/utils/videos/video-comments'
20 import { waitJobs } from '../../../../shared/utils/server/jobs'
22 const expect = chai.expect
24 describe('Test stats (excluding redundancy)', function () {
25 let servers: ServerInfo[] = []
27 before(async function () {
31 servers = await flushAndRunMultipleServers(3)
32 await setAccessTokensToServers(servers)
34 await doubleFollow(servers[0], servers[1])
38 password: 'super_password'
40 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
42 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, {})
43 const videoUUID = resVideo.body.video.uuid
45 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
47 await viewVideo(servers[0].url, videoUUID)
49 // Wait the video views repeatable job
52 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
53 await waitJobs(servers)
56 it('Should have the correct stats on instance 1', async function () {
57 const res = await getStats(servers[0].url)
58 const data: ServerStats = res.body
60 expect(data.totalLocalVideoComments).to.equal(1)
61 expect(data.totalLocalVideos).to.equal(1)
62 expect(data.totalLocalVideoViews).to.equal(1)
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.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 after(async function () {
99 killallServers(servers)