1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { ServerStats } from '../../../../shared/models/server/server-stats.model'
9 flushAndRunMultipleServers,
17 import { flushTests, setAccessTokensToServers } from '../../utils/index'
18 import { getStats } from '../../utils/server/stats'
19 import { addVideoCommentThread } from '../../utils/videos/video-comments'
21 const expect = chai.expect
23 describe('Test stats', function () {
24 let servers: ServerInfo[] = []
26 before(async function () {
30 servers = await flushAndRunMultipleServers(3)
31 await setAccessTokensToServers(servers)
33 await doubleFollow(servers[0], servers[1])
37 password: 'super_password'
39 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
41 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, {})
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 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
52 it('Should have the correct stats on instance 1', async function () {
53 const res = await getStats(servers[0].url)
54 const data: ServerStats = res.body
56 expect(data.totalLocalVideoComments).to.equal(1)
57 expect(data.totalLocalVideos).to.equal(1)
58 expect(data.totalLocalVideoViews).to.equal(1)
59 expect(data.totalUsers).to.equal(2)
60 expect(data.totalVideoComments).to.equal(1)
61 expect(data.totalVideos).to.equal(1)
62 expect(data.totalInstanceFollowers).to.equal(2)
63 expect(data.totalInstanceFollowing).to.equal(1)
66 it('Should have the correct stats on instance 2', async function () {
67 const res = await getStats(servers[1].url)
68 const data: ServerStats = res.body
70 expect(data.totalLocalVideoComments).to.equal(0)
71 expect(data.totalLocalVideos).to.equal(0)
72 expect(data.totalLocalVideoViews).to.equal(0)
73 expect(data.totalUsers).to.equal(1)
74 expect(data.totalVideoComments).to.equal(1)
75 expect(data.totalVideos).to.equal(1)
76 expect(data.totalInstanceFollowers).to.equal(1)
77 expect(data.totalInstanceFollowing).to.equal(1)
80 it('Should have the correct stats on instance 3', async function () {
81 const res = await getStats(servers[2].url)
82 const data: ServerStats = res.body
84 expect(data.totalLocalVideoComments).to.equal(0)
85 expect(data.totalLocalVideos).to.equal(0)
86 expect(data.totalLocalVideoViews).to.equal(0)
87 expect(data.totalUsers).to.equal(1)
88 expect(data.totalVideoComments).to.equal(1)
89 expect(data.totalVideos).to.equal(1)
90 expect(data.totalInstanceFollowing).to.equal(1)
91 expect(data.totalInstanceFollowers).to.equal(0)
94 after(async function () {
95 killallServers(servers)
97 // Keep the logs if the test failed