]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/stats.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / stats.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { ServerStats } from '../../../../shared/models/server/server-stats.model'
6 import {
7 cleanupTests,
8 createUser,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 follow,
12 killallServers,
13 ServerInfo,
14 uploadVideo,
15 viewVideo,
16 wait
17 } from '../../../../shared/extra-utils'
18 import { flushTests, 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'
22
23 const expect = chai.expect
24
25 describe('Test stats (excluding redundancy)', function () {
26 let servers: ServerInfo[] = []
27
28 before(async function () {
29 this.timeout(60000)
30 servers = await flushAndRunMultipleServers(3)
31 await setAccessTokensToServers(servers)
32
33 await doubleFollow(servers[0], servers[1])
34
35 const user = {
36 username: 'user1',
37 password: 'super_password'
38 }
39 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
40
41 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
42 const videoUUID = resVideo.body.video.uuid
43
44 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment')
45
46 await viewVideo(servers[0].url, videoUUID)
47
48 // Wait the video views repeatable job
49 await wait(8000)
50
51 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken)
52 await waitJobs(servers)
53 })
54
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
58
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)
68 })
69
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
73
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)
83 })
84
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
88
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)
97 })
98
99 after(async function () {
100 await cleanupTests(servers)
101 })
102 })